summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Lindo2012-02-16 14:20:58 (EST)
committerVivian Kong2012-02-16 14:20:58 (EST)
commita059aeb2bd8baa2882ee9d4fe2c370704555a369 (patch)
tree9214bb7ab23e257d8356b041dd2263bea178f410
parent83615d9d18ac6045d8e0a9bc913aa8965a39e1a5 (diff)
downloadorg.eclipse.ptp-a059aeb2bd8baa2882ee9d4fe2c370704555a369.zip
org.eclipse.ptp-a059aeb2bd8baa2882ee9d4fe2c370704555a369.tar.gz
org.eclipse.ptp-a059aeb2bd8baa2882ee9d4fe2c370704555a369.tar.bz2
Bug 370763 - Remote Semantic Highlighting in the Remote C/C++ Editor and
some minor fixes
-rw-r--r--rdt/org.eclipse.ptp.rdt.core/META-INF/MANIFEST.MF2
-rw-r--r--rdt/org.eclipse.ptp.rdt.core/miners/org/eclipse/ptp/internal/rdt/core/miners/CDTMiner.java72
-rw-r--r--rdt/org.eclipse.ptp.rdt.core/miners/org/eclipse/ptp/internal/rdt/core/miners/PositionCollector.java314
-rw-r--r--rdt/org.eclipse.ptp.rdt.core/miners/org/eclipse/ptp/internal/rdt/core/miners/SemanticHighlighting.java36
-rw-r--r--rdt/org.eclipse.ptp.rdt.core/miners/org/eclipse/ptp/internal/rdt/core/miners/SemanticHighlightings.java765
-rw-r--r--rdt/org.eclipse.ptp.rdt.core/pom.xml2
-rwxr-xr-xrdt/org.eclipse.ptp.rdt.core/src/org/eclipse/ptp/internal/rdt/core/subsystems/ICIndexSubsystem.java4
-rw-r--r--rdt/org.eclipse.ptp.rdt.editor/src/org/eclipse/ptp/internal/rdt/editor/RemoteCEditor.java9
-rw-r--r--rdt/org.eclipse.ptp.rdt.editor/src/org/eclipse/ptp/rdt/editor/info/IRemoteCEditorInfoProvider.java6
-rw-r--r--rdt/org.eclipse.ptp.rdt.server.dstore/.project68
-rw-r--r--rdt/org.eclipse.ptp.rdt.server.dstore/META-INF/MANIFEST.MF2
-rw-r--r--rdt/org.eclipse.ptp.rdt.server.dstore/pom.xml2
-rw-r--r--rdt/org.eclipse.ptp.rdt.server.dstore/src/org/eclipse/ptp/rdt/server/dstore/core/RemoteToolsCIndexServiceProvider.java20
-rw-r--r--rdt/org.eclipse.ptp.rdt.server.dstore/src/org/eclipse/ptp/rdt/server/dstore/core/RemoteToolsCIndexSubsystem.java53
-rw-r--r--rdt/org.eclipse.ptp.rdt.ui/META-INF/MANIFEST.MF2
-rw-r--r--rdt/org.eclipse.ptp.rdt.ui/pom.xml2
-rw-r--r--rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/internal/rdt/ui/editor/IRemoteSemanticHighlightingService.java28
-rw-r--r--rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/internal/rdt/ui/editor/RemoteCEditorInfoProvider.java39
-rw-r--r--rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/internal/rdt/ui/editor/RemoteSemanticHighlightingManager.java162
-rw-r--r--rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/internal/rdt/ui/editor/RemoteSemanticHighlightingReconciler.java345
-rw-r--r--rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/internal/rdt/ui/editor/RemoteSemanticHighlightingService.java81
-rw-r--r--rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/preferences/Messages.java2
-rw-r--r--rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/preferences/PreferenceConstants.java2
-rw-r--r--rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/preferences/PreferenceInitializer.java2
-rw-r--r--rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/preferences/RemoteDevelopmentPreferencePage.java2
-rwxr-xr-xrdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/serviceproviders/IIndexServiceProvider2.java8
-rw-r--r--rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/serviceproviders/LocalCIndexServiceProvider.java17
-rw-r--r--rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/serviceproviders/NullCIndexServiceProvider.java14
-rwxr-xr-xrdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/serviceproviders/RSECIndexServiceProvider.java18
-rwxr-xr-xrdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/subsystems/RSECIndexSubsystem.java51
30 files changed, 2054 insertions, 76 deletions
diff --git a/rdt/org.eclipse.ptp.rdt.core/META-INF/MANIFEST.MF b/rdt/org.eclipse.ptp.rdt.core/META-INF/MANIFEST.MF
index 91b2e4e..afce27a 100644
--- a/rdt/org.eclipse.ptp.rdt.core/META-INF/MANIFEST.MF
+++ b/rdt/org.eclipse.ptp.rdt.core/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name.0
Bundle-SymbolicName: org.eclipse.ptp.rdt.core;singleton:=true
-Bundle-Version: 4.0.1.qualifier
+Bundle-Version: 4.1.0.qualifier
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Require-Bundle: org.eclipse.cdt.core;bundle-version="5.0.2",
org.eclipse.core.runtime,
diff --git a/rdt/org.eclipse.ptp.rdt.core/miners/org/eclipse/ptp/internal/rdt/core/miners/CDTMiner.java b/rdt/org.eclipse.ptp.rdt.core/miners/org/eclipse/ptp/internal/rdt/core/miners/CDTMiner.java
index cf1defc..56d65da 100644
--- a/rdt/org.eclipse.ptp.rdt.core/miners/org/eclipse/ptp/internal/rdt/core/miners/CDTMiner.java
+++ b/rdt/org.eclipse.ptp.rdt.core/miners/org/eclipse/ptp/internal/rdt/core/miners/CDTMiner.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 IBM Corporation and others.
+ * Copyright (c) 2008, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -144,13 +144,17 @@ public class CDTMiner extends Miner {
// includes
public static final String C_INCLUDES_FIND_INCLUDES_TO = "C_INCLUDES_FIND_INCLUDES_TO"; //$NON-NLS-1$
- public static final String C_INCLUDES_FIND_INCLUDES_TO_RESULT = "C_INCLUDES_FIND_INCLUDES_TO_RESULT"; //$NON-NLS-1$
+ public static final String T_INCLUDES_FIND_INCLUDES_TO_RESULT = "Type.Includes.Find.Includes.To.Result"; //$NON-NLS-1$
public static final String C_INCLUDES_FIND_INCLUDED_BY = "C_INCLUDES_FIND_INCLUDED_BY"; //$NON-NLS-1$
- public static final String C_INCLUDES_FIND_INCLUDED_BY_RESULT = "C_INCLUDES_FIND_INCLUDED_BY_RESULT"; //$NON-NLS-1$
+ public static final String T_INCLUDES_FIND_INCLUDED_BY_RESULT = "Type.Includes.Find.Included.By.Result"; //$NON-NLS-1$
public static final String C_INCLUDES_IS_INDEXED = "C_INCLUDES_IS_INDEXED"; //$NON-NLS-1$
- public static final String C_INCLUDES_IS_INDEXED_RESULT = "C_INCLUDES_IS_INDEXED_RESULT"; //$NON-NLS-1$
+ public static final String T_INCLUDES_IS_INDEXED_RESULT = "Type.Includes.Is.Indexed.Result"; //$NON-NLS-1$
public static final String C_INCLUDES_FIND_INCLUDE = "C_INCLUDES_FIND_INCLUDE"; //$NON-NLS-1$
- public static final String C_INCLUDES_FIND_INCLUDE_RESULT = "C_INCLUDES_FIND_INCLUDE_RESULT"; //$NON-NLS-1$
+ public static final String T_INCLUDES_FIND_INCLUDE_RESULT = "Type.Includes.Find.Include.Result"; //$NON-NLS-1$
+
+ //semantic highlighting
+ public static final String C_SEMANTIC_HIGHTLIGHTING_COMPUTE_POSITIONS = "C_SEMANTIC_HIGHTLIGHTING_COMPUTE_POSITIONS"; //$NON-NLS-1$
+ public static final String T_HIGHTLIGHTING_POSITIONS_RESULT = "Highlighting.Positions.Result"; //$NON-NLS-1$
public static String LINE_SEPARATOR;
@@ -158,7 +162,7 @@ public class CDTMiner extends Miner {
//model builder
public static final String C_MODEL_BUILDER = "C_MODEL_BUILDER"; //$NON-NLS-1$;
- public static final String C_MODEL_RESULT= "C_MODEL_RESULT"; //$NON-NLS-1$;
+ public static final String T_MODEL_RESULT= "Type.Model.Result"; //$NON-NLS-1$;
public static final String LOG_TAG = "CDTMiner"; //$NON-NLS-1$
@@ -676,10 +680,53 @@ public class CDTMiner extends Miner {
UniversalServerUtilities.logError(LOG_TAG, e.toString(), e, _dataStore);
}
}
+ else if (name.equals(C_SEMANTIC_HIGHTLIGHTING_COMPUTE_POSITIONS)) {
+ try {
+ String scopeName = getString(theCommand, 1);
+ ITranslationUnit tu = (ITranslationUnit) Serializer.deserialize(getString(theCommand, 2));
+
+ hanleComputeSemanticHightlightingPositions(scopeName, tu, status);
+ } catch (IOException e) {
+ UniversalServerUtilities.logError(LOG_TAG, e.toString(), e, _dataStore);
+ } catch (ClassNotFoundException e) {
+ UniversalServerUtilities.logError(LOG_TAG, e.toString(), e, _dataStore);
+ }
+ }
return status;
}
+ protected void hanleComputeSemanticHightlightingPositions(String scopeName, ITranslationUnit tu, DataElement status) {
+ try {
+ IIndex index = RemoteIndexManager.getInstance().getIndexForScope(scopeName, _dataStore);
+ index.acquireReadLock();
+ try {
+ IASTTranslationUnit ast = tu.getAST(index, ITranslationUnit.AST_SKIP_ALL_HEADERS);
+ PositionCollector collector = new PositionCollector(true);
+ ast.accept(collector);
+ ArrayList<ArrayList<Integer>> positionList = collector.getPositions();
+ String clumpedPositions = new String();
+ for (ArrayList<Integer> position : positionList) {
+ clumpedPositions += position.get(0) + "," + position.get(1) + "," + position.get(2) + ","; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ String resultString = Serializer.serialize(clumpedPositions);
+ status.getDataStore().createObject(status, T_HIGHTLIGHTING_POSITIONS_RESULT, resultString);
+ }
+ finally {
+ index.releaseReadLock();
+ }
+ } catch (IOException e) {
+ UniversalServerUtilities.logError(LOG_TAG, e.toString(), e, _dataStore);
+ } catch (CoreException e) {
+ UniversalServerUtilities.logError(LOG_TAG, e.toString(), e, _dataStore);
+ } catch (InterruptedException e) {
+ UniversalServerUtilities.logError(LOG_TAG, e.toString(), e, _dataStore);
+ }
+ finally {
+ statusDone(status);
+ }
+ }
+
protected void handleIndexFileMove(String scopeName, String newIndexLocation, DataElement status) throws IOException {
String actualLocation = RemoteIndexManager.getInstance().moveIndexFile(scopeName, newIndexLocation, _dataStore);
status.getDataStore().createObject(status, T_MOVE_INDEX_FILE_RESULT, actualLocation);
@@ -734,7 +781,7 @@ public class CDTMiner extends Miner {
// create the result object
String resultString = Serializer.serialize(workingCopy);
- status.getDataStore().createObject(status, C_MODEL_RESULT, resultString);
+ status.getDataStore().createObject(status, T_MODEL_RESULT, resultString);
}
} catch (IOException e) {
UniversalServerUtilities.logError(LOG_TAG, e.toString(), e, _dataStore);
@@ -822,7 +869,7 @@ public class CDTMiner extends Miner {
// create the result object
String resultString = Serializer.serialize(includesToReturn);
- status.getDataStore().createObject(status, C_INCLUDES_FIND_INCLUDES_TO_RESULT, resultString);
+ status.getDataStore().createObject(status, T_INCLUDES_FIND_INCLUDES_TO_RESULT, resultString);
}
finally
{
@@ -899,7 +946,7 @@ public class CDTMiner extends Miner {
// create the result object
String resultString = Serializer.serialize(includeToReturn);
- status.getDataStore().createObject(status, C_INCLUDES_FIND_INCLUDE_RESULT, resultString);
+ status.getDataStore().createObject(status, T_INCLUDES_FIND_INCLUDE_RESULT, resultString);
}
finally
{
@@ -996,7 +1043,7 @@ public class CDTMiner extends Miner {
// create the result object
String resultString = Serializer.serialize(includesToReturn);
- status.getDataStore().createObject(status, C_INCLUDES_FIND_INCLUDED_BY_RESULT, resultString);
+ status.getDataStore().createObject(status, T_INCLUDES_FIND_INCLUDED_BY_RESULT, resultString);
}
finally
{
@@ -1034,7 +1081,7 @@ public class CDTMiner extends Miner {
// create the result object
String resultString = Serializer.serialize(new Boolean(files.length > 0));
- status.getDataStore().createObject(status, C_INCLUDES_IS_INDEXED_RESULT, resultString);
+ status.getDataStore().createObject(status, T_INCLUDES_IS_INDEXED_RESULT, resultString);
}
finally
{
@@ -1381,6 +1428,9 @@ public class CDTMiner extends Miner {
createCommandDescriptor(schemaRoot, "Find input from element", C_TYPE_HIERARCHY_FIND_INPUT1, false); //$NON-NLS-1$
createCommandDescriptor(schemaRoot, "Find input from text selection", C_TYPE_HIERARCHY_FIND_INPUT2, false); //$NON-NLS-1$
+ // semantic highlighting
+ createCommandDescriptor(schemaRoot, "Compute added & removed positions for semantic highlighting", C_SEMANTIC_HIGHTLIGHTING_COMPUTE_POSITIONS, false); //$NON-NLS-1$
+
// navigation
createCommandDescriptor(schemaRoot, "Open declaration", C_NAVIGATION_OPEN_DECLARATION, false); //$NON-NLS-1$
diff --git a/rdt/org.eclipse.ptp.rdt.core/miners/org/eclipse/ptp/internal/rdt/core/miners/PositionCollector.java b/rdt/org.eclipse.ptp.rdt.core/miners/org/eclipse/ptp/internal/rdt/core/miners/PositionCollector.java
new file mode 100644
index 0000000..86b1af6
--- /dev/null
+++ b/rdt/org.eclipse.ptp.rdt.core/miners/org/eclipse/ptp/internal/rdt/core/miners/PositionCollector.java
@@ -0,0 +1,314 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.ptp.internal.rdt.core.miners;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTImageLocation;
+import org.eclipse.cdt.core.dom.ast.IASTMacroExpansionLocation;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
+import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
+import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroExpansion;
+import org.eclipse.cdt.core.dom.ast.IASTStatement;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
+
+import org.eclipse.ptp.internal.rdt.core.miners.SemanticHighlighting;
+import org.eclipse.ptp.internal.rdt.core.miners.SemanticHighlightings;
+
+
+/* Pulled from SemanticHighlightingReconciler with SemanticToken added as a nested class.*/
+public class PositionCollector extends CPPASTVisitor {
+
+ public final class SemanticToken {
+
+ /** AST node */
+ private IASTNode fNode;
+
+ /** Binding */
+ private IBinding fBinding;
+ /** Is the binding resolved? */
+ private boolean fIsBindingResolved= false;
+
+ /** AST root */
+ private IASTTranslationUnit fRoot;
+ private boolean fIsRootResolved= false;
+
+ /**
+ * @return Returns the binding, can be <code>null</code>.
+ */
+ public IBinding getBinding() {
+ if (!fIsBindingResolved) {
+ fIsBindingResolved= true;
+ if (fNode instanceof IASTName)
+ fBinding= ((IASTName)fNode).resolveBinding();
+ }
+
+ return fBinding;
+ }
+
+ /**
+ * @return the AST node
+ */
+ public IASTNode getNode() {
+ return fNode;
+ }
+
+ /**
+ * @return the AST root
+ */
+ public IASTTranslationUnit getRoot() {
+ if (!fIsRootResolved) {
+ fIsRootResolved= true;
+ if (fNode != null) {
+ fRoot= fNode.getTranslationUnit();
+ }
+ }
+ return fRoot;
+ }
+
+ /**
+ * Update this token with the given AST node.
+ * <p>
+ * NOTE: Allowed to be used by {@link SemanticHighlightingReconciler} only.
+ * </p>
+ *
+ * @param node the AST node
+ */
+ public void update(IASTNode node) {
+ clear();
+ fNode= node;
+ }
+
+ /**
+ * Clears this token.
+ * <p>
+ * NOTE: Allowed to be used by {@link SemanticHighlightingReconciler} only.
+ * </p>
+ */
+ public void clear() {
+ fNode= null;
+ fBinding= null;
+ fIsBindingResolved= false;
+ fRoot= null;
+ fIsRootResolved= false;
+ }
+ }
+
+ protected SemanticHighlighting[] fJobSemanticHighlightings;
+
+ ArrayList<ArrayList<Integer>> positionList = new ArrayList<ArrayList<Integer>>();
+
+ /** The semantic token */
+ private SemanticToken fToken= new SemanticToken();
+ private int fMinLocation;
+
+ public PositionCollector(boolean visitImplicitNames) {
+
+ fJobSemanticHighlightings = SemanticHighlightings.getSemanticHighlightings();
+
+ fMinLocation= -1;
+ shouldVisitTranslationUnit= true;
+ shouldVisitNames= true;
+ shouldVisitDeclarations= true;
+ shouldVisitExpressions= true;
+ shouldVisitStatements= true;
+ shouldVisitDeclarators= true;
+ shouldVisitNamespaces= true;
+ shouldVisitImplicitNames = visitImplicitNames;
+ shouldVisitImplicitNameAlternates = visitImplicitNames;
+ }
+
+ /*
+ * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#leave(org.eclipse.cdt.core.dom.ast.IASTDeclaration)
+ */
+ @Override
+ public int leave(IASTDeclaration declaration) {
+ return PROCESS_CONTINUE;
+ }
+
+
+ /*
+ * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit)
+ */
+ @Override
+ public int visit(IASTTranslationUnit tu) {
+
+ // visit macro definitions
+ IASTPreprocessorMacroDefinition[] macroDefs= tu.getMacroDefinitions();
+ for (IASTPreprocessorMacroDefinition macroDef : macroDefs) {
+ if (macroDef.isPartOfTranslationUnitFile()) {
+ visitNode(macroDef.getName());
+ }
+ }
+ fMinLocation= -1;
+
+ // visit macro expansions
+ IASTPreprocessorMacroExpansion[] macroExps= tu.getMacroExpansions();
+ for (IASTPreprocessorMacroExpansion macroExp : macroExps) {
+ if (macroExp.isPartOfTranslationUnitFile()) {
+ IASTName macroRef= macroExp.getMacroReference();
+ visitNode(macroRef);
+ IASTName[] nestedMacroRefs= macroExp.getNestedMacroReferences();
+ for (IASTName nestedMacroRef : nestedMacroRefs) {
+ visitNode(nestedMacroRef);
+ }
+ }
+ }
+ fMinLocation= -1;
+
+ // visit ordinary code
+ return super.visit(tu);
+ }
+
+ /*
+ * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTDeclaration)
+ */
+ @Override
+ public int visit(IASTDeclaration declaration) {
+ if (!declaration.isPartOfTranslationUnitFile()) {
+ return PROCESS_SKIP;
+ }
+ return PROCESS_CONTINUE;
+ }
+
+ /*
+ * @see org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor#visit(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition)
+ */
+ @Override
+ public int visit(ICPPASTNamespaceDefinition namespace) {
+ if (!namespace.isPartOfTranslationUnitFile()) {
+ return PROCESS_SKIP;
+ }
+ return PROCESS_CONTINUE;
+ }
+
+ /*
+ * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTDeclarator)
+ */
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ return PROCESS_CONTINUE;
+ }
+
+ /*
+ * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTStatement)
+ */
+ @Override
+ public int visit(IASTStatement statement) {
+ return PROCESS_CONTINUE;
+ }
+
+ /*
+ * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTName)
+ */
+ @Override
+ public int visit(IASTName name) {
+ if (visitNode(name)) {
+ return PROCESS_SKIP;
+ }
+ return PROCESS_CONTINUE;
+ }
+
+ private boolean visitNode(IASTNode node) {
+ boolean consumed= false;
+ fToken.update(node);
+ for (int i= 0, n= fJobSemanticHighlightings.length; i < n; ++i) {
+ SemanticHighlighting semanticHighlighting= fJobSemanticHighlightings[i];
+ if (semanticHighlighting.consumes(fToken)) {
+ if (node instanceof IASTName) {
+ addNameLocation((IASTName)node, i);
+ } else {
+ addNodeLocation(node.getFileLocation(), i);
+ }
+ consumed= true;
+ break;
+ }
+ }
+ fToken.clear();
+ return consumed;
+ }
+
+ /**
+ * Add the a location range for the given name.
+ *
+ * @param name The name
+ * @param highlighting The highlighting
+ */
+ private void addNameLocation(IASTName name, int highlightingStyleIndex) {
+ IASTImageLocation imageLocation= name.getImageLocation();
+ if (imageLocation != null) {
+ if (imageLocation.getLocationKind() != IASTImageLocation.MACRO_DEFINITION) {
+ int offset= imageLocation.getNodeOffset();
+ if (offset >= fMinLocation) {
+ int length= imageLocation.getNodeLength();
+ if (offset > -1 && length > 0) {
+ fMinLocation= offset + length;
+ addPosition(offset, length, highlightingStyleIndex);
+ }
+ }
+ }
+ } else {
+ // fallback in case no image location available
+ IASTNodeLocation[] nodeLocations= name.getNodeLocations();
+ if (nodeLocations.length == 1 && !(nodeLocations[0] instanceof IASTMacroExpansionLocation)) {
+ addNodeLocation(nodeLocations[0], highlightingStyleIndex);
+ }
+ }
+ }
+
+ /**
+ * Add the a location range for the given highlighting.
+ *
+ * @param nodeLocation The node location
+ * @param highlighting The highlighting
+ */
+ private void addNodeLocation(IASTNodeLocation nodeLocation, int highlightingStyleIndex) {
+ if (nodeLocation == null) {
+ return;
+ }
+ int offset= nodeLocation.getNodeOffset();
+ if (offset >= fMinLocation) {
+ int length= nodeLocation.getNodeLength();
+ if (offset > -1 && length > 0) {
+ fMinLocation= offset + length;
+ addPosition(offset, length, highlightingStyleIndex);
+ }
+ }
+ }
+
+ /**
+ * Add a position with the given range.
+ *
+ * @param offset The range offset
+ * @param length The range length
+ * @param highlighting The highlighting
+ */
+ private void addPosition(int offset, int length, int highlightingStyleIndex) {
+ ArrayList<Integer> u = new ArrayList<Integer>();
+ u.addAll(Arrays.asList(new Integer[]{offset,length,highlightingStyleIndex}));
+ positionList.add(u);
+ }
+
+
+ public ArrayList<ArrayList<Integer>> getPositions(){
+ return positionList;
+ }
+
+} \ No newline at end of file
diff --git a/rdt/org.eclipse.ptp.rdt.core/miners/org/eclipse/ptp/internal/rdt/core/miners/SemanticHighlighting.java b/rdt/org.eclipse.ptp.rdt.core/miners/org/eclipse/ptp/internal/rdt/core/miners/SemanticHighlighting.java
new file mode 100644
index 0000000..65e816a
--- /dev/null
+++ b/rdt/org.eclipse.ptp.rdt.core/miners/org/eclipse/ptp/internal/rdt/core/miners/SemanticHighlighting.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Anton Leherbauer (Wind River Systems) - Adapted for CDT
+ * Markus Schorn (Wind River Systems)
+ *******************************************************************************/
+
+package org.eclipse.ptp.internal.rdt.core.miners;
+
+
+/**
+ * Semantic highlighting.
+ * Cloned from JDT.
+ *
+ * @since 4.0
+ */
+public abstract class SemanticHighlighting {
+
+ /**
+ * Returns <code>true</code> iff the semantic highlighting consumes the semantic token.
+ * <p>
+ * NOTE: Implementors are not allowed to keep a reference on the token or on any object
+ * retrieved from the token.
+ * </p>
+ *
+ * @param fToken the semantic token for a {@link org.eclipse.cdt.core.dom.ast.IASTName}
+ * @return <code>true</code> iff the semantic highlighting consumes the semantic token
+ */
+ public abstract boolean consumes(org.eclipse.ptp.internal.rdt.core.miners.PositionCollector.SemanticToken fToken);
+}
diff --git a/rdt/org.eclipse.ptp.rdt.core/miners/org/eclipse/ptp/internal/rdt/core/miners/SemanticHighlightings.java b/rdt/org.eclipse.ptp.rdt.core/miners/org/eclipse/ptp/internal/rdt/core/miners/SemanticHighlightings.java
new file mode 100644
index 0000000..5c22b75
--- /dev/null
+++ b/rdt/org.eclipse.ptp.rdt.core/miners/org/eclipse/ptp/internal/rdt/core/miners/SemanticHighlightings.java
@@ -0,0 +1,765 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Anton Leherbauer (Wind River Systems) - Adapted for CDT
+ *******************************************************************************/
+
+package org.eclipse.ptp.internal.rdt.core.miners;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.cdt.core.dom.ast.DOMException;
+import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTImplicitName;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTProblem;
+import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.IEnumeration;
+import org.eclipse.cdt.core.dom.ast.IEnumerator;
+import org.eclipse.cdt.core.dom.ast.IField;
+import org.eclipse.cdt.core.dom.ast.IFunction;
+import org.eclipse.cdt.core.dom.ast.ILabel;
+import org.eclipse.cdt.core.dom.ast.IMacroBinding;
+import org.eclipse.cdt.core.dom.ast.IParameter;
+import org.eclipse.cdt.core.dom.ast.IProblemBinding;
+import org.eclipse.cdt.core.dom.ast.IScope;
+import org.eclipse.cdt.core.dom.ast.ITypedef;
+import org.eclipse.cdt.core.dom.ast.IVariable;
+import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding;
+import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionScope;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
+import org.eclipse.cdt.core.index.IIndex;
+import org.eclipse.cdt.core.index.IIndexBinding;
+import org.eclipse.cdt.core.index.IIndexFile;
+import org.eclipse.cdt.core.index.IIndexName;
+
+import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator;
+import org.eclipse.ptp.internal.rdt.core.miners.PositionCollector.SemanticToken;
+
+
+/**
+ * Semantic highlightings.
+ * Derived from JDT.
+ *
+ * @since 4.0
+ */
+public class SemanticHighlightings {
+ /**
+ * Semantic highlightings
+ */
+ private static SemanticHighlighting[] fgSemanticHighlightings;
+
+ /**
+ * Semantic highlighting for static fields.
+ */
+ private static final class StaticFieldHighlighting extends SemanticHighlighting {
+ /*
+ * @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#consumes(org.eclipse.cdt.internal.ui.editor.SemanticToken)
+ */
+ @Override
+ public boolean consumes(SemanticToken token) {
+ IASTNode node= token.getNode();
+ if (node instanceof IASTName) {
+ IASTName name= (IASTName)node;
+ if (name instanceof ICPPASTQualifiedName && name.isReference()) {
+ return false;
+ }
+ IBinding binding= token.getBinding();
+ if (binding instanceof IField && !(binding instanceof IProblemBinding)) {
+ try {
+ return ((IField)binding).isStatic();
+ } catch (DOMException exc) {
+ } catch (Error e) /* PDOMNotImplementedError */ {
+ // ignore
+ }
+ }
+ }
+ return false;
+ }
+ }
+
+ /**
+ * Semantic highlighting for fields.
+ */
+ private static final class FieldHighlighting extends SemanticHighlighting {
+ /*
+ * @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#consumes(org.eclipse.cdt.internal.ui.editor.SemanticToken)
+ */
+ @Override
+ public boolean consumes(SemanticToken token) {
+ IASTNode node= token.getNode();
+ if (node instanceof IASTName) {
+ IASTName name= (IASTName)node;
+ if (name instanceof ICPPASTQualifiedName && name.isReference()) {
+ return false;
+ }
+ IBinding binding= token.getBinding();
+ if (binding instanceof IField) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+
+ /**
+ * Semantic highlighting for method declarations.
+ */
+ private static final class MethodDeclarationHighlighting extends SemanticHighlighting {
+ /*
+ * @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#consumes(org.eclipse.cdt.internal.ui.editor.SemanticToken)
+ */
+ @Override
+ public boolean consumes(SemanticToken token) {
+ IASTNode node= token.getNode();
+ if (node instanceof IASTName) {
+ IASTName name= (IASTName)node;
+ if (!name.isReference()) {
+ IBinding binding= token.getBinding();
+ if (binding instanceof ICPPMethod) {
+ return true;
+ } else if (binding instanceof IProblemBinding) {
+ // try to be derive from AST
+ node= name.getParent();
+ while (node instanceof IASTName) {
+ node= node.getParent();
+ }
+ if (node instanceof ICPPASTFunctionDeclarator) {
+ if (name instanceof ICPPASTQualifiedName) {
+ ICPPASTQualifiedName qName= (ICPPASTQualifiedName)name;
+ IASTName[] names= qName.getNames();
+ if (names.length > 1) {
+ if (names[names.length - 2].getBinding() instanceof ICPPClassType) {
+ return true;
+ }
+ }
+ } else {
+ while (node != token.getRoot() && !(node.getParent() instanceof IASTDeclSpecifier)) {
+ node= node.getParent();
+ }
+ if (node instanceof ICPPASTCompositeTypeSpecifier) {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+ }
+
+ /**
+ * Semantic highlighting for static method invocations.
+ */
+ private static final class StaticMethodInvocationHighlighting extends SemanticHighlighting {
+ /*
+ * @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#consumes(org.eclipse.cdt.internal.ui.editor.SemanticToken)
+ */
+ @Override
+ public boolean consumes(SemanticToken token) {
+ IASTNode node= token.getNode();
+ if (node instanceof IASTName) {
+ IASTName name= (IASTName)node;
+ if (name instanceof ICPPASTQualifiedName) {
+ return false;
+ }
+ if (!name.isReference()) {
+ return false;
+ }
+ IBinding binding= token.getBinding();
+ if (binding instanceof ICPPMethod && !(binding instanceof IProblemBinding)) {
+ try {
+ return ((ICPPMethod)binding).isStatic();
+ } catch (DOMException exc) {
+ } catch (Error e) /* PDOMNotImplementedError */ {
+ // ignore
+ }
+ }
+ }
+ return false;
+ }
+ }
+
+ /**
+ * Semantic highlighting for methods.
+ */
+ private static final class MethodHighlighting extends SemanticHighlighting {
+ /*
+ * @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#consumes(org.eclipse.cdt.internal.ui.editor.SemanticToken)
+ */
+ @Override
+ public boolean consumes(SemanticToken token) {
+ IASTNode node= token.getNode();
+ if (node instanceof IASTImplicitName)
+ return false;
+ if (node instanceof IASTName) {
+ IASTName name= (IASTName)node;
+ if (name instanceof ICPPASTQualifiedName && name.isReference()) {
+ return false;
+ }
+ IBinding binding= token.getBinding();
+ if (binding instanceof ICPPMethod) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ }
+
+ /**
+ * Semantic highlighting for function declarations.
+ */
+ private static final class FunctionDeclarationHighlighting extends SemanticHighlighting {
+ /*
+ * @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#consumes(org.eclipse.cdt.internal.ui.editor.SemanticToken)
+ */
+ @Override
+ public boolean consumes(SemanticToken token) {
+ IASTNode node= token.getNode();
+ if (node instanceof IASTName) {
+ IASTName name= (IASTName)node;
+ if (name.isDeclaration()) {
+ IBinding binding= token.getBinding();
+ if (binding instanceof IFunction
+ && !(binding instanceof ICPPMethod)) {
+ return true;
+ } else if (binding instanceof IProblemBinding) {
+ // try to derive from AST
+ if (name instanceof ICPPASTQualifiedName) {
+ return false;
+ }
+ node= name.getParent();
+ while (node instanceof IASTName) {
+ node= node.getParent();
+ }
+ if (node instanceof IASTFunctionDeclarator) {
+ while (node != token.getRoot() && !(node.getParent() instanceof IASTDeclSpecifier)) {
+ node= node.getParent();
+ }
+ if (node instanceof ICPPASTCompositeTypeSpecifier) {
+ return false;
+ }
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+ }
+
+ /**
+ * Semantic highlighting for functions.
+ */
+ private static final class FunctionHighlighting extends SemanticHighlighting {
+ /*
+ * @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#consumes(org.eclipse.cdt.internal.ui.editor.SemanticToken)
+ */
+ @Override
+ public boolean consumes(SemanticToken token) {
+ IASTNode node= token.getNode();
+ if (node instanceof IASTImplicitName)
+ return false;
+ if (node instanceof IASTName) {
+ IASTName name= (IASTName)node;
+ if (name instanceof ICPPASTQualifiedName && name.isReference()) {
+ return false;
+ }
+ IBinding binding= token.getBinding();
+ if (binding instanceof IFunction && !(binding instanceof ICPPMethod)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+
+ /**
+ * Semantic highlighting for local variable declarations.
+ */
+ private static final class LocalVariableDeclarationHighlighting extends SemanticHighlighting {
+ /*
+ * @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#consumes(org.eclipse.cdt.internal.ui.editor.SemanticToken)
+ */
+ @Override
+ public boolean consumes(SemanticToken token) {
+ IASTNode node= token.getNode();
+ if (node instanceof IASTName) {
+ IASTName name= (IASTName)node;
+ if (name.isDeclaration()) {
+ IBinding binding= token.getBinding();
+ if (binding instanceof IVariable
+ && !(binding instanceof IField)
+ && !(binding instanceof IParameter)
+ && !(binding instanceof IProblemBinding)) {
+ try {
+ IScope scope= binding.getScope();
+ if (LocalVariableHighlighting.isLocalScope(scope)) {
+ return true;
+ }
+ } catch (DOMException exc) {
+ } catch (Error e) /* PDOMNotImplementedError */ {
+ // ignore
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+}
+
+ /**
+ * Semantic highlighting for local variables.
+ */
+ private static final class LocalVariableHighlighting extends SemanticHighlighting {
+ /*
+ * @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#consumes(org.eclipse.cdt.internal.ui.editor.SemanticToken)
+ */
+ @Override
+ public boolean consumes(SemanticToken token) {
+ IASTNode node= token.getNode();
+ if (node instanceof IASTName) {
+ IASTName name= (IASTName)node;
+ if (name.isReference()) {
+ IBinding binding= token.getBinding();
+ if (binding instanceof IVariable
+ && !(binding instanceof IField)
+ && !(binding instanceof IParameter)
+ && !(binding instanceof IProblemBinding)) {
+ try {
+ IScope scope= binding.getScope();
+ if (isLocalScope(scope)) {
+ return true;
+ }
+ } catch (DOMException exc) {
+ } catch (Error e) /* PDOMNotImplementedError */ {
+ // ignore
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ public static boolean isLocalScope(IScope scope) {
+ while (scope != null) {
+ if (scope instanceof ICPPFunctionScope ||
+ scope instanceof ICPPBlockScope ||
+ scope instanceof ICFunctionScope) {
+ return true;
+ }
+ try {
+ scope= scope.getParent();
+ } catch (DOMException e) {
+ scope= null;
+ }
+ }
+ return false;
+ }
+}
+
+ /**
+ * Semantic highlighting for global variables.
+ */
+ private static final class GlobalVariableHighlighting extends SemanticHighlighting {
+ /*
+ * @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#consumes(org.eclipse.cdt.internal.ui.editor.SemanticToken)
+ */
+ @Override
+ public boolean consumes(SemanticToken token) {
+ IASTNode node= token.getNode();
+ if (node instanceof IASTName) {
+ IASTName name= (IASTName)node;
+ if (name instanceof ICPPASTQualifiedName) {
+ return false;
+ }
+ IBinding binding= token.getBinding();
+ if (binding instanceof IVariable
+ && !(binding instanceof IField)
+ && !(binding instanceof IParameter)
+ && !(binding instanceof ICPPTemplateNonTypeParameter)
+ && !(binding instanceof IProblemBinding)) {
+ try {
+ IScope scope= binding.getScope();
+ if (!LocalVariableHighlighting.isLocalScope(scope)) {
+ return true;
+ }
+ } catch (DOMException exc) {
+
+ } catch (Error e) /* PDOMNotImplementedError */ {
+ // ignore
+ }
+ }
+ }
+ return false;
+ }
+
+ }
+
+ /**
+ * Semantic highlighting for parameter variables.
+ */
+ private static final class ParameterVariableHighlighting extends SemanticHighlighting {
+ /*
+ * @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#consumes(org.eclipse.cdt.internal.ui.editor.SemanticToken)
+ */
+ @Override
+ public boolean consumes(SemanticToken token) {
+ IBinding binding= token.getBinding();
+ if (binding instanceof IParameter) {
+ return true;
+ }
+ return false;
+ }
+ }
+
+ /**
+ * Semantic highlighting for template parameters.
+ */
+ private static final class TemplateParameterHighlighting extends SemanticHighlighting {
+ /*
+ * @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#consumes(org.eclipse.cdt.internal.ui.editor.SemanticToken)
+ */
+ @Override
+ public boolean consumes(SemanticToken token) {
+ IASTNode node= token.getNode();
+ if (node instanceof IASTName) {
+ IBinding binding= token.getBinding();
+ if (binding instanceof ICPPTemplateParameter) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+
+ /**
+ * Semantic highlighting for classes.
+ */
+ private static final class ClassHighlighting extends SemanticHighlighting {
+ /*
+ * @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#consumes(org.eclipse.cdt.internal.ui.editor.SemanticToken)
+ */
+ @Override
+ public boolean consumes(SemanticToken token) {
+ IASTNode node= token.getNode();
+ if (node instanceof ICPPASTQualifiedName || node instanceof ICPPASTTemplateId) {
+ return false;
+ }
+ if (node instanceof IASTName) {
+ IBinding binding= token.getBinding();
+ if (binding instanceof ICPPClassType) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+
+ /**
+ * Semantic highlighting for enums.
+ */
+ private static final class EnumHighlighting extends SemanticHighlighting {
+ /*
+ * @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#consumes(org.eclipse.cdt.internal.ui.editor.SemanticToken)
+ */
+ @Override
+ public boolean consumes(SemanticToken token) {
+ IASTNode node= token.getNode();
+ if (node instanceof IASTName) {
+ IBinding binding= token.getBinding();
+ if (binding instanceof IEnumeration) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+
+ /**
+ * Semantic highlighting for macro references.
+ */
+ private static final class MacroReferenceHighlighting extends SemanticHighlighting {
+ /*
+ * @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#consumes(org.eclipse.cdt.internal.ui.editor.SemanticToken)
+ */
+ @Override
+ public boolean consumes(SemanticToken token) {
+ IBinding binding= token.getBinding();
+ if (binding instanceof IMacroBinding) {
+ IASTName name= (IASTName)token.getNode();
+ if (name.isReference()) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+
+ /**
+ * Semantic highlighting for macro definitions.
+ */
+ private static final class MacroDefinitionHighlighting extends SemanticHighlighting {
+ /*
+ * @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#consumes(org.eclipse.cdt.internal.ui.editor.SemanticToken)
+ */
+ @Override
+ public boolean consumes(SemanticToken token) {
+ IBinding binding= token.getBinding();
+ if (binding instanceof IMacroBinding) {
+ IASTName name= (IASTName)token.getNode();
+ if (!name.isReference()) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+
+ /**
+ * Semantic highlighting for typedefs.
+ */
+ private static final class TypedefHighlighting extends SemanticHighlighting {
+ /*
+ * @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#consumes(org.eclipse.cdt.internal.ui.editor.SemanticToken)
+ */
+ @Override
+ public boolean consumes(SemanticToken token) {
+ IASTNode node= token.getNode();
+ if (node instanceof IASTName) {
+ IASTName name= (IASTName)node;
+ if (name instanceof ICPPASTQualifiedName) {
+ return false;
+ }
+ IBinding binding= token.getBinding();
+ if (binding instanceof ITypedef) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+
+ /**
+ * Semantic highlighting for namespaces.
+ */
+ private static final class NamespaceHighlighting extends SemanticHighlighting {
+ /*
+ * @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#consumes(org.eclipse.cdt.internal.ui.editor.SemanticToken)
+ */
+ @Override
+ public boolean consumes(SemanticToken token) {
+ IBinding binding= token.getBinding();
+ if (binding instanceof ICPPNamespace) {
+ return true;
+ }
+ return false;
+ }
+ }
+
+ /**
+ * Semantic highlighting for labels.
+ */
+ private static final class LabelHighlighting extends SemanticHighlighting {
+ /*
+ * @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#consumes(org.eclipse.cdt.internal.ui.editor.SemanticToken)
+ */
+ @Override
+ public boolean consumes(SemanticToken token) {
+ IBinding binding= token.getBinding();
+ if (binding instanceof ILabel) {
+ return true;
+ }
+ return false;
+ }
+ }
+
+ /**
+ * Semantic highlighting for enumerators.
+ */
+ private static final class EnumeratorHighlighting extends SemanticHighlighting {
+ /*
+ * @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#consumes(org.eclipse.cdt.internal.ui.editor.SemanticToken)
+ */
+ @Override
+ public boolean consumes(SemanticToken token) {
+ IASTNode node= token.getNode();
+ if (node instanceof IASTName) {
+ IASTName name= (IASTName)node;
+ if (name instanceof ICPPASTQualifiedName) {
+ return false;
+ }
+ IBinding binding= token.getBinding();
+ if (binding instanceof IEnumerator) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+
+ /**
+ * Semantic highlighting for problems.
+ */
+ private static final class ProblemHighlighting extends SemanticHighlighting {
+ /*
+ * @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#consumes(org.eclipse.cdt.internal.ui.editor.SemanticToken)
+ */
+ @Override
+ public boolean consumes(SemanticToken token) {
+ IASTNode node= token.getNode();
+ if (node instanceof IASTProblem) {
+ return true;
+ }
+ IBinding binding= token.getBinding();
+ if (binding instanceof IProblemBinding) {
+ return true;
+ }
+ return false;
+ }
+ }
+
+ /**
+ * Semantic highlighting for external SDK references.
+ */
+ private static final class ExternalSDKHighlighting extends SemanticHighlighting {
+ /*
+ * @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#consumes(org.eclipse.cdt.internal.ui.editor.SemanticToken)
+ */
+ @Override
+ public boolean consumes(SemanticToken token) {
+ IASTNode node= token.getNode();
+ if (node instanceof IASTName) {
+ IASTName name= (IASTName)node;
+ if (name instanceof ICPPASTQualifiedName) {
+ return false;
+ }
+ if (name instanceof IASTImplicitName) {
+ return false;
+ }
+ if (name.isReference()) {
+ IBinding binding= token.getBinding();
+ IIndex index= token.getRoot().getIndex();
+ return isExternalSDKReference(binding, index);
+ }
+ }
+ return false;
+ }
+
+ private boolean isExternalSDKReference(IBinding binding, IIndex index) {
+ if (binding instanceof IFunction) {
+ try {
+ if (binding instanceof IIndexBinding) {
+ if (((IIndexBinding) binding).isFileLocal()) {
+ return false;
+ }
+ }
+ else if (!(binding instanceof ICExternalBinding)) {
+ return false;
+ }
+ IIndexName[] decls= index.findNames(binding, IIndex.FIND_DECLARATIONS | IIndex.SEARCH_ACROSS_LANGUAGE_BOUNDARIES);
+ for (IIndexName decl : decls) {
+ IIndexFile indexFile= decl.getFile();
+ if (indexFile != null && indexFile.getLocation().getFullPath() != null) {
+ return false;
+ }
+ }
+ if (decls.length != 0) {
+ return true;
+ }
+ } catch (CoreException exc) {
+ return false;
+ }
+ }
+ return false;
+ }
+ }
+
+ /**
+ * Semantic highlighting for functions.
+ */
+ private static final class OverloadedOperatorHighlighting extends SemanticHighlighting {
+ /*
+ * @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#consumes(org.eclipse.cdt.internal.ui.editor.SemanticToken)
+ */
+ @Override
+ public boolean consumes(SemanticToken token) {
+ IASTNode node = token.getNode();
+ // so far we only have implicit names for overloaded operators and destructors, so this works
+ if(node instanceof IASTImplicitName) {
+ IASTImplicitName name = (IASTImplicitName) node;
+ IBinding binding = name.resolveBinding();
+ if(binding instanceof ICPPMethod && !(binding instanceof IProblemBinding) && ((ICPPMethod)binding).isImplicit()) {
+ return false;
+ }
+ char[] chars = name.toCharArray();
+ if(chars[0] == '~' || OverloadableOperator.isNew(chars) || OverloadableOperator.isDelete(chars)) {
+ return false;
+ }
+ return true;
+ }
+ return false;
+ }
+ }
+
+
+ /**
+ * @return The semantic highlightings, the order defines the precedence of matches, the first match wins.
+ */
+ public static SemanticHighlighting[] getSemanticHighlightings() {
+ if (fgSemanticHighlightings == null)
+ fgSemanticHighlightings= new SemanticHighlighting[] {
+ new MacroReferenceHighlighting(), // before all others!
+ new ProblemHighlighting(),
+ new ExternalSDKHighlighting(),
+ new ClassHighlighting(),
+ new StaticFieldHighlighting(),
+ new FieldHighlighting(), // after all other fields
+ new MethodDeclarationHighlighting(),
+ new StaticMethodInvocationHighlighting(),
+ new ParameterVariableHighlighting(), // before local variables
+ new LocalVariableDeclarationHighlighting(),
+ new LocalVariableHighlighting(),
+ new GlobalVariableHighlighting(),
+ new TemplateParameterHighlighting(), // before template arguments!
+ new OverloadedOperatorHighlighting(), // before both method and function
+ new MethodHighlighting(), // before types to get ctors
+ new EnumHighlighting(),
+ new MacroDefinitionHighlighting(),
+ new FunctionDeclarationHighlighting(),
+ new FunctionHighlighting(),
+ new TypedefHighlighting(),
+ new NamespaceHighlighting(),
+ new LabelHighlighting(),
+ new EnumeratorHighlighting(),
+ };
+ return fgSemanticHighlightings;
+ }
+
+
+ /**
+ * Do not instantiate
+ */
+ private SemanticHighlightings() {
+ }
+}
diff --git a/rdt/org.eclipse.ptp.rdt.core/pom.xml b/rdt/org.eclipse.ptp.rdt.core/pom.xml
index a1c4389..60fb94f 100644
--- a/rdt/org.eclipse.ptp.rdt.core/pom.xml
+++ b/rdt/org.eclipse.ptp.rdt.core/pom.xml
@@ -11,6 +11,6 @@
</parent>
<artifactId>org.eclipse.ptp.rdt.core</artifactId>
- <version>4.0.1-SNAPSHOT</version>
+ <version>4.1.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/rdt/org.eclipse.ptp.rdt.core/src/org/eclipse/ptp/internal/rdt/core/subsystems/ICIndexSubsystem.java b/rdt/org.eclipse.ptp.rdt.core/src/org/eclipse/ptp/internal/rdt/core/subsystems/ICIndexSubsystem.java
index 2395a69..0c84f25 100755
--- a/rdt/org.eclipse.ptp.rdt.core/src/org/eclipse/ptp/internal/rdt/core/subsystems/ICIndexSubsystem.java
+++ b/rdt/org.eclipse.ptp.rdt.core/src/org/eclipse/ptp/internal/rdt/core/subsystems/ICIndexSubsystem.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 IBM Corporation and others.
+ * Copyright (c) 2008, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -268,4 +268,6 @@ public interface ICIndexSubsystem {
*/
public EventType getReIndexEventType();
+ public String computeHighlightPositions(ITranslationUnit targetUnit);
+
}
diff --git a/rdt/org.eclipse.ptp.rdt.editor/src/org/eclipse/ptp/internal/rdt/editor/RemoteCEditor.java b/rdt/org.eclipse.ptp.rdt.editor/src/org/eclipse/ptp/internal/rdt/editor/RemoteCEditor.java
index 4cc2f38..a03a771 100644
--- a/rdt/org.eclipse.ptp.rdt.editor/src/org/eclipse/ptp/internal/rdt/editor/RemoteCEditor.java
+++ b/rdt/org.eclipse.ptp.rdt.editor/src/org/eclipse/ptp/internal/rdt/editor/RemoteCEditor.java
@@ -89,8 +89,11 @@ public class RemoteCEditor extends CEditor implements HelpListener {
public void createPartControl(Composite parent) {
super.createPartControl(parent);
- if (provider != null)
+ if (provider != null){
+ if (isSemanticHighlightingEnabled())
+ provider.installSemanticHighlighting(getSourceViewer(), getPreferenceStore());
provider.doPostCreatePartControl(parent);
+ }
}
@SuppressWarnings("rawtypes")
@@ -223,9 +226,7 @@ public class RemoteCEditor extends CEditor implements HelpListener {
@Override
protected boolean isSemanticHighlightingEnabled() {
if (provider != null) {
- Boolean enabled = provider.isSemanticHighlightingEnabled();
- if (enabled != null)
- return enabled.booleanValue();
+ return provider.isSemanticHighlightingEnabled(getPreferenceStore());
}
return super.isSemanticHighlightingEnabled();
}
diff --git a/rdt/org.eclipse.ptp.rdt.editor/src/org/eclipse/ptp/rdt/editor/info/IRemoteCEditorInfoProvider.java b/rdt/org.eclipse.ptp.rdt.editor/src/org/eclipse/ptp/rdt/editor/info/IRemoteCEditorInfoProvider.java
index 5a61458..bc21d9f 100644
--- a/rdt/org.eclipse.ptp.rdt.editor/src/org/eclipse/ptp/rdt/editor/info/IRemoteCEditorInfoProvider.java
+++ b/rdt/org.eclipse.ptp.rdt.editor/src/org/eclipse/ptp/rdt/editor/info/IRemoteCEditorInfoProvider.java
@@ -17,6 +17,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.IVerticalRuler;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.ptp.internal.rdt.editor.RemoteCEditor;
@@ -125,6 +126,7 @@ public interface IRemoteCEditorInfoProvider {
public boolean shouldProcessLocalParsingCompletions();
- public Boolean isSemanticHighlightingEnabled();
-
+ public boolean isSemanticHighlightingEnabled(IPreferenceStore store);
+
+ public void installSemanticHighlighting(ISourceViewer sourceViewer, IPreferenceStore prefStore);
}
diff --git a/rdt/org.eclipse.ptp.rdt.server.dstore/.project b/rdt/org.eclipse.ptp.rdt.server.dstore/.project
index 718dedc..059e5bc 100644
--- a/rdt/org.eclipse.ptp.rdt.server.dstore/.project
+++ b/rdt/org.eclipse.ptp.rdt.server.dstore/.project
@@ -1,34 +1,34 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.eclipse.ptp.rdt.server.dstore.dstore</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.ManifestBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.SchemaBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.pde.PluginNature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
- </natures>
-</projectDescription>
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.ptp.rdt.server.dstore</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
+ </natures>
+</projectDescription>
diff --git a/rdt/org.eclipse.ptp.rdt.server.dstore/META-INF/MANIFEST.MF b/rdt/org.eclipse.ptp.rdt.server.dstore/META-INF/MANIFEST.MF
index 934b6af..fda38e0 100644
--- a/rdt/org.eclipse.ptp.rdt.server.dstore/META-INF/MANIFEST.MF
+++ b/rdt/org.eclipse.ptp.rdt.server.dstore/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-Localization: plugin
Bundle-SymbolicName: org.eclipse.ptp.rdt.server.dstore;singleton:=true
-Bundle-Version: 2.0.0.qualifier
+Bundle-Version: 2.1.0.qualifier
Bundle-Activator: org.eclipse.ptp.rdt.server.dstore.Activator
Bundle-Vendor: %pluginProvider
Require-Bundle: org.eclipse.core.runtime,
diff --git a/rdt/org.eclipse.ptp.rdt.server.dstore/pom.xml b/rdt/org.eclipse.ptp.rdt.server.dstore/pom.xml
index 115a9cc..5ea0fbb 100644
--- a/rdt/org.eclipse.ptp.rdt.server.dstore/pom.xml
+++ b/rdt/org.eclipse.ptp.rdt.server.dstore/pom.xml
@@ -11,6 +11,6 @@
</parent>
<artifactId>org.eclipse.ptp.rdt.server.dstore</artifactId>
- <version>2.0.0-SNAPSHOT</version>
+ <version>2.1.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/rdt/org.eclipse.ptp.rdt.server.dstore/src/org/eclipse/ptp/rdt/server/dstore/core/RemoteToolsCIndexServiceProvider.java b/rdt/org.eclipse.ptp.rdt.server.dstore/src/org/eclipse/ptp/rdt/server/dstore/core/RemoteToolsCIndexServiceProvider.java
index e7581ee..a1a3baf 100644
--- a/rdt/org.eclipse.ptp.rdt.server.dstore/src/org/eclipse/ptp/rdt/server/dstore/core/RemoteToolsCIndexServiceProvider.java
+++ b/rdt/org.eclipse.ptp.rdt.server.dstore/src/org/eclipse/ptp/rdt/server/dstore/core/RemoteToolsCIndexServiceProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 IBM Corporation and others.
+ * Copyright (c) 2008, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -24,6 +24,8 @@ import org.eclipse.ptp.internal.rdt.core.typehierarchy.ITypeHierarchyService;
import org.eclipse.ptp.internal.rdt.core.typehierarchy.RemoteTypeHierarchyService;
import org.eclipse.ptp.internal.rdt.ui.contentassist.IContentAssistService;
import org.eclipse.ptp.internal.rdt.ui.contentassist.RemoteContentAssistService;
+import org.eclipse.ptp.internal.rdt.ui.editor.IRemoteSemanticHighlightingService;
+import org.eclipse.ptp.internal.rdt.ui.editor.RemoteSemanticHighlightingService;
import org.eclipse.ptp.internal.rdt.ui.navigation.INavigationService;
import org.eclipse.ptp.internal.rdt.ui.navigation.RemoteNavigationService;
import org.eclipse.ptp.internal.rdt.ui.search.ISearchService;
@@ -48,6 +50,10 @@ public class RemoteToolsCIndexServiceProvider extends ServiceProvider implements
protected IModelBuilderService fModelBuilderService = null;
protected RemoteSearchService fSearchService = null;
protected IContentAssistService fContentAssistService = null;
+ /**
+ * @since 2.1
+ */
+ protected RemoteSemanticHighlightingService fRemoteSemanticHighlightingService = null;
protected RemoteToolsCIndexSubsystem fSubsystem = null;
protected boolean fIsDirty = false;
protected RemoteToolsCIndexServiceProvider fProvider = null;
@@ -409,5 +415,17 @@ public class RemoteToolsCIndexServiceProvider extends ServiceProvider implements
fSubsystem = new RemoteToolsCIndexSubsystem(this);
setConfigured(true);
}
+
+ /**
+ * @since 2.1
+ */
+ public IRemoteSemanticHighlightingService getRemoteSemanticHighlightingService() {
+ if(!isConfigured())
+ return null;
+ if(fRemoteSemanticHighlightingService== null)
+ fRemoteSemanticHighlightingService = new RemoteSemanticHighlightingService(fSubsystem);
+
+ return fRemoteSemanticHighlightingService;
+ }
}
diff --git a/rdt/org.eclipse.ptp.rdt.server.dstore/src/org/eclipse/ptp/rdt/server/dstore/core/RemoteToolsCIndexSubsystem.java b/rdt/org.eclipse.ptp.rdt.server.dstore/src/org/eclipse/ptp/rdt/server/dstore/core/RemoteToolsCIndexSubsystem.java
index 02c416b..659e215 100644
--- a/rdt/org.eclipse.ptp.rdt.server.dstore/src/org/eclipse/ptp/rdt/server/dstore/core/RemoteToolsCIndexSubsystem.java
+++ b/rdt/org.eclipse.ptp.rdt.server.dstore/src/org/eclipse/ptp/rdt/server/dstore/core/RemoteToolsCIndexSubsystem.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 IBM Corporation and others.
+ * Copyright (c) 2008, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -81,6 +81,7 @@ import org.eclipse.ptp.services.core.IService;
import org.eclipse.ptp.services.core.IServiceConfiguration;
import org.eclipse.ptp.services.core.IServiceProvider;
import org.eclipse.ptp.services.core.ServiceModelManager;
+import org.eclipse.rse.connectorservice.dstore.util.StatusMonitorFactory;
/**
@@ -1203,4 +1204,54 @@ public class RemoteToolsCIndexSubsystem implements ICIndexSubsystem {
return IRemoteFastIndexerUpdateEvent.EventType.EVENT_REINDEX;
}
+ /**
+ * @since 2.1
+ */
+ public String computeHighlightPositions(ITranslationUnit targetUnit) {
+ // If something goes wrong, return an empty string.
+
+ checkAllProjects(new NullProgressMonitor());
+ DataStore dataStore = getDataStore(null);
+ if (dataStore == null) {
+ return ""; //$NON-NLS-1$
+ }
+ DataElement queryCmd = dataStore.localDescriptorQuery(dataStore.getDescriptorRoot(), CDTMiner.C_SEMANTIC_HIGHTLIGHTING_COMPUTE_POSITIONS);
+ if (queryCmd == null) {
+ return ""; //$NON-NLS-1$
+ }
+ NullProgressMonitor monitor = new NullProgressMonitor();
+ StatusMonitor smonitor = StatusMonitor.getStatusMonitorFor(fProvider.getConnection(), dataStore);
+ ArrayList<Object> args = new ArrayList<Object>();
+ Scope scope = new Scope(targetUnit.getCProject().getProject());
+ DataElement dataElement = dataStore.createObject(null, CDTMiner.T_SCOPE_SCOPENAME_DESCRIPTOR, scope.getName());
+
+ args.add(dataElement);
+ args.add(createSerializableElement(dataStore, targetUnit));
+
+ // execute the command
+ DataElement status = dataStore.command(queryCmd, args, dataStore.getDescriptorRoot());
+
+ try {
+ smonitor.waitForUpdate(status, monitor);
+ }
+ catch (Exception e) {
+ RDTLog.logError(e);
+ }
+
+ DataElement element = status.get(0);
+ String data = element.getName();
+ try {
+ Object result = Serializer.deserialize(data);
+ if (result == null || !(result instanceof String)) {
+ return ""; //$NON-NLS-1$;
+ }
+ return (String) result;
+ } catch (IOException e) {
+ RDTLog.logError(e);
+ } catch (ClassNotFoundException e) {
+ RDTLog.logError(e);
+ }
+ return ""; //$NON-NLS-1$
+ }
+
}
diff --git a/rdt/org.eclipse.ptp.rdt.ui/META-INF/MANIFEST.MF b/rdt/org.eclipse.ptp.rdt.ui/META-INF/MANIFEST.MF
index 30e8d24..6ea20ed 100644
--- a/rdt/org.eclipse.ptp.rdt.ui/META-INF/MANIFEST.MF
+++ b/rdt/org.eclipse.ptp.rdt.ui/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.ptp.rdt.ui;singleton:=true
-Bundle-Version: 4.0.1.qualifier
+Bundle-Version: 4.1.0.qualifier
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Require-Bundle: org.eclipse.cdt.core;bundle-version="5.0.2",
org.eclipse.cdt.ui;bundle-version="5.0.2",
diff --git a/rdt/org.eclipse.ptp.rdt.ui/pom.xml b/rdt/org.eclipse.ptp.rdt.ui/pom.xml
index 59fa5c1..5796ab0 100644
--- a/rdt/org.eclipse.ptp.rdt.ui/pom.xml
+++ b/rdt/org.eclipse.ptp.rdt.ui/pom.xml
@@ -11,6 +11,6 @@
</parent>
<artifactId>org.eclipse.ptp.rdt.ui</artifactId>
- <version>4.0.1-SNAPSHOT</version>
+ <version>4.1.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/internal/rdt/ui/editor/IRemoteSemanticHighlightingService.java b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/internal/rdt/ui/editor/IRemoteSemanticHighlightingService.java
new file mode 100644
index 0000000..96e82f3
--- /dev/null
+++ b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/internal/rdt/ui/editor/IRemoteSemanticHighlightingService.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.ptp.internal.rdt.ui.editor;
+
+import org.eclipse.cdt.core.model.IWorkingCopy;
+
+/**
+ * Provides Semantic Highlighting added and removed positions from the remote host.
+ */
+public interface IRemoteSemanticHighlightingService {
+ /**
+ * Returns a list of added and removed positions needed by the Presenter.
+ *
+ * @param working copy of the file
+ * @return A comma separated list of highlighting positions where Element x = the offset,
+ * x+1 = the length, x+2 is the Highlightings index.
+ */
+ String computeSemanticHighlightingPositions(IWorkingCopy workingCopy);
+}
diff --git a/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/internal/rdt/ui/editor/RemoteCEditorInfoProvider.java b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/internal/rdt/ui/editor/RemoteCEditorInfoProvider.java
index 4a9c236..6e87fa0 100644
--- a/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/internal/rdt/ui/editor/RemoteCEditorInfoProvider.java
+++ b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/internal/rdt/ui/editor/RemoteCEditorInfoProvider.java
@@ -14,9 +14,11 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.ui.editor.CContentOutlinePage;
+import org.eclipse.cdt.internal.ui.editor.SemanticHighlightings;
import org.eclipse.cdt.internal.ui.text.CTextTools;
import org.eclipse.cdt.internal.ui.util.EditorUtility;
import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.actions.CdtActionConstants;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.core.resources.IProject;
@@ -25,8 +27,10 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.help.IContextProvider;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.IVerticalRuler;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.jface.text.source.projection.ProjectionViewer;
import org.eclipse.ptp.internal.rdt.editor.RemoteCEditor;
import org.eclipse.ptp.internal.rdt.ui.RDTHelpContextIds;
import org.eclipse.ptp.internal.rdt.ui.actions.OpenViewActionGroup;
@@ -48,6 +52,7 @@ import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionGroup;
import org.eclipse.ui.texteditor.IDocumentProvider;
+import org.eclipse.cdt.internal.ui.editor.CSourceViewer;
/**
* Remote enabled version of the CEditor. If this editor is opened on a file from a remote project then it will use
@@ -58,6 +63,11 @@ public class RemoteCEditorInfoProvider implements IRemoteCEditorInfoProvider {
private RemoteCEditor editor;
private IEditorInput input;
+
+ /**
+ * Remote Semantic highlighting manager
+ */
+ private RemoteSemanticHighlightingManager fRemoteSemanticManager;
/* (non-Javadoc)
* @see org.eclipse.ptp.rdt.editor.info.IRemoteCEditorInfoProvider#initializeEditor(org.eclipse.ptp.internal.rdt.editor.RemoteCEditor)
@@ -146,7 +156,9 @@ public class RemoteCEditorInfoProvider implements IRemoteCEditorInfoProvider {
* @see org.eclipse.ptp.rdt.editor.info.IRemoteCEditorInfoProvider#doPostCreatePartControl(org.eclipse.swt.widgets.Composite)
*/
public void doPostCreatePartControl(Composite parent) {
- PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, RDTHelpContextIds.REMOTE_C_CPP_EDITOR);
+ if (isRemote()) {
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, RDTHelpContextIds.REMOTE_C_CPP_EDITOR);
+ }
}
/* (non-Javadoc)
@@ -187,10 +199,12 @@ public class RemoteCEditorInfoProvider implements IRemoteCEditorInfoProvider {
* @see org.eclipse.ptp.rdt.editor.info.IRemoteCEditorInfoProvider#editorContextMenuAboutToShow(org.eclipse.jface.action.IMenuManager)
*/
public void editorContextMenuAboutToShow(IMenuManager menu) {
- // remove text search
- menu.remove("org.eclipse.search.text.ctxmenu"); //$NON-NLS-1$
- // remove refactoring for now
- menu.remove("org.eclipse.cdt.ui.refactoring.menu"); //$NON-NLS-1$
+ if (isRemote()) {
+ // remove text search
+ menu.remove("org.eclipse.search.text.ctxmenu"); //$NON-NLS-1$
+ // remove refactoring for now
+ menu.remove("org.eclipse.cdt.ui.refactoring.menu"); //$NON-NLS-1$
+ }
}
/* (non-Javadoc)
@@ -392,8 +406,17 @@ public class RemoteCEditorInfoProvider implements IRemoteCEditorInfoProvider {
return isLocalServiceProvider();
}
- public Boolean isSemanticHighlightingEnabled() {
- return isRemote() ? new Boolean(false) : null;
+ /**
+ * Install Semantic Highlighting.
+ */
+ public void installSemanticHighlighting(ISourceViewer sourceViewer, IPreferenceStore prefStore) {
+ if (isRemote() && fRemoteSemanticManager == null && isSemanticHighlightingEnabled(prefStore)) {
+ fRemoteSemanticManager= new RemoteSemanticHighlightingManager();
+ fRemoteSemanticManager.install(editor, (CSourceViewer) sourceViewer, CUIPlugin.getDefault().getTextTools().getColorManager(), prefStore);
+ }
+ }
+
+ public boolean isSemanticHighlightingEnabled(IPreferenceStore prefStore) {
+ return SemanticHighlightings.isEnabled(prefStore) && !(editor.isEnableScalablilityMode() && prefStore.getBoolean(PreferenceConstants.SCALABILITY_SEMANTIC_HIGHLIGHT));
}
-
}
diff --git a/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/internal/rdt/ui/editor/RemoteSemanticHighlightingManager.java b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/internal/rdt/ui/editor/RemoteSemanticHighlightingManager.java
new file mode 100644
index 0000000..bb82262
--- /dev/null
+++ b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/internal/rdt/ui/editor/RemoteSemanticHighlightingManager.java
@@ -0,0 +1,162 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Anton Leherbauer (Wind River Systems) - Adapted for CDT
+ *******************************************************************************/
+
+package org.eclipse.ptp.internal.rdt.ui.editor;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.ptp.internal.rdt.editor.RemoteCEditor;
+import org.eclipse.cdt.ui.text.ICPartitions;
+import org.eclipse.cdt.ui.text.IColorManager;
+import org.eclipse.cdt.internal.ui.editor.CSourceViewer;
+import org.eclipse.cdt.internal.ui.editor.SemanticHighlightingManager;
+import org.eclipse.cdt.internal.ui.editor.SemanticHighlightingPresenter;
+import org.eclipse.cdt.internal.ui.text.CPresentationReconciler;
+import org.eclipse.cdt.internal.ui.text.CSourceViewerScalableConfiguration;
+
+/**
+ * Semantic highlighting manager.
+ * Cloned from JDT.
+ *
+ * @since 4.0
+ */
+public class RemoteSemanticHighlightingManager extends SemanticHighlightingManager {
+
+ /** Remote Semantic highlighting reconciler */
+ private RemoteSemanticHighlightingReconciler fRemoteReconciler;
+ /** The editor */
+ private RemoteCEditor remoteCEditor;
+
+ /**
+ * Install the semantic highlighting on the given editor infrastructure
+ *
+ * @param editor The remote C editor
+ * @param sourceViewer The source viewer
+ * @param colorManager The color manager
+ * @param preferenceStore The preference store
+ */
+ public void install(RemoteCEditor editor, CSourceViewer sourceViewer, IColorManager colorManager, IPreferenceStore preferenceStore) {
+ remoteCEditor= editor;
+ fSourceViewer= sourceViewer;
+ fColorManager= colorManager;
+ fPreferenceStore= preferenceStore;
+ if (remoteCEditor != null) {
+ fConfiguration= new CSourceViewerScalableConfiguration(colorManager, preferenceStore, editor, ICPartitions.C_PARTITIONING);
+ fPresentationReconciler= (CPresentationReconciler) fConfiguration.getPresentationReconciler(sourceViewer);
+ } else {
+ fConfiguration= null;
+ fPresentationReconciler= null;
+ }
+
+ fPreferenceStore.addPropertyChangeListener(this);
+
+ if (isEnabled())
+ enable();
+ }
+
+ /**
+ * Install the semantic highlighting on the given source viewer infrastructure. No reconciliation will be performed.
+ *
+ * @param sourceViewer the source viewer
+ * @param colorManager the color manager
+ * @param preferenceStore the preference store
+ * @param hardcodedRanges the hard-coded ranges to be highlighted
+ */
+ public void install(CSourceViewer sourceViewer, IColorManager colorManager, IPreferenceStore preferenceStore, HighlightedRange[][] hardcodedRanges) {
+ fHardcodedRanges= hardcodedRanges;
+ install(null, sourceViewer, colorManager, preferenceStore);
+ }
+
+ /**
+ * Enable semantic highlighting.
+ */
+ protected void enable() {
+ initializeHighlightings();
+
+ fPresenter= new SemanticHighlightingPresenter();
+ fPresenter.install(fSourceViewer, fPresentationReconciler);
+
+ if (remoteCEditor != null) {
+ fRemoteReconciler= new RemoteSemanticHighlightingReconciler();
+ fRemoteReconciler.install(remoteCEditor, fSourceViewer, fPresenter, fSemanticHighlightings, fHighlightings);
+ } else {
+ fPresenter.updatePresentation(null, createHardcodedPositions(), new HighlightedPosition[0]);
+ }
+ }
+
+ /**
+ * Uninstall the semantic highlighting
+ */
+ public void uninstall() {
+ disable();
+
+ if (fPreferenceStore != null) {
+ fPreferenceStore.removePropertyChangeListener(this);
+ fPreferenceStore= null;
+ }
+
+ remoteCEditor= null;
+ fSourceViewer= null;
+ fColorManager= null;
+ fConfiguration= null;
+ fPresentationReconciler= null;
+ fHardcodedRanges= null;
+ }
+
+ /**
+ * Disable semantic highlighting.
+ */
+ protected void disable() {
+ if (fRemoteReconciler != null) {
+ fRemoteReconciler.uninstall();
+ fRemoteReconciler= null;
+ }
+
+ if (fPresenter != null) {
+ fPresenter.uninstall();
+ fPresenter= null;
+ }
+
+ if (fSemanticHighlightings != null)
+ disposeHighlightings();
+ }
+
+
+ /*
+ * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
+ */
+ public void propertyChange(PropertyChangeEvent event) {
+ handlePropertyChangeEvent(event);
+ }
+
+ /**
+ * Handle the given property change event
+ *
+ * @param event The event
+ */
+ protected boolean handlePropertyChangeEvent(PropertyChangeEvent event) {
+ if (super.handlePropertyChangeEvent(event) && fRemoteReconciler != null) {
+ fRemoteReconciler.refresh();
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Force refresh of highlighting.
+ */
+ public void refresh() {
+ if (fRemoteReconciler != null) {
+ fRemoteReconciler.refresh();
+ }
+ }
+} \ No newline at end of file
diff --git a/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/internal/rdt/ui/editor/RemoteSemanticHighlightingReconciler.java b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/internal/rdt/ui/editor/RemoteSemanticHighlightingReconciler.java
new file mode 100644
index 0000000..9ceba79
--- /dev/null
+++ b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/internal/rdt/ui/editor/RemoteSemanticHighlightingReconciler.java
@@ -0,0 +1,345 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ptp.internal.rdt.ui.editor;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.model.IWorkingCopy;
+import org.eclipse.cdt.internal.core.model.ASTCache;
+import org.eclipse.cdt.internal.ui.editor.ASTProvider;
+import org.eclipse.cdt.internal.ui.editor.CEditorMessages;
+import org.eclipse.cdt.internal.ui.editor.SemanticHighlighting;
+import org.eclipse.cdt.internal.ui.editor.SemanticHighlightingPresenter;
+import org.eclipse.cdt.internal.ui.editor.SemanticHighlightingReconciler;
+import org.eclipse.cdt.internal.ui.editor.SemanticHighlightingManager.HighlightedPosition;
+import org.eclipse.ptp.internal.rdt.editor.RemoteCEditor;
+import org.eclipse.ptp.internal.rdt.ui.editor.RemoteSemanticHighlightingManager;
+import org.eclipse.cdt.internal.ui.editor.SemanticHighlightingManager.HighlightingStyle;
+import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.cdt.ui.IWorkingCopyManager;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.TextPresentation;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.ptp.rdt.core.services.IRDTServiceConstants;
+import org.eclipse.ptp.rdt.ui.serviceproviders.IIndexServiceProvider2;
+import org.eclipse.ptp.services.core.IService;
+import org.eclipse.ptp.services.core.IServiceConfiguration;
+import org.eclipse.ptp.services.core.IServiceModelManager;
+import org.eclipse.ptp.services.core.IServiceProvider;
+import org.eclipse.ptp.services.core.ServiceModelManager;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchPartSite;
+
+
+/**
+ * Remote Semantic highlighting reconciler
+ */
+
+public class RemoteSemanticHighlightingReconciler extends SemanticHighlightingReconciler {
+
+ /** Reconcile operation lock. */
+ private final Object fReconcileLock= new Object();
+
+ private boolean fIsReconciling= false;
+
+ /** Highlightings */
+ protected RemoteSemanticHighlightingManager.HighlightingStyle[] fHighlightings;
+
+ /** Highlightings - cache for background thread, only valid during {@link #reconciled(IASTTranslationUnit, boolean, IProgressMonitor)} */
+ protected RemoteSemanticHighlightingManager.HighlightingStyle[] fJobHighlightings;
+
+ /** The Remote C editor this semantic highlighting reconciler is installed on */
+ private RemoteCEditor fRemoteEditor;
+
+ /** Background job */
+ private Job fJob;
+ /** Background job lock */
+ private final Object fJobLock= new Object();
+
+
+ /**
+ * @param positions are separated by commas. Element x = the offset,
+ * x+1 = the length, x+2 is the Highlightings index.
+ */
+ private void parsePositions(String positions) {
+ String [] positionList = positions.split(","); //$NON-NLS-1$
+
+ for(int i=0; i < positionList.length; i+=3) {
+ int lgtIndex = Integer.parseInt(positionList[i+2]);
+ if (fJobHighlightings[lgtIndex].isEnabled()){
+ int offset = Integer.parseInt(positionList[i]);
+ int length = Integer.parseInt(positionList[i+1]);
+ addPosition(offset, length, fJobHighlightings[lgtIndex]);
+ }
+ }
+ sortPositions();
+ }
+
+ /**
+ * Add a position with the given range and highlighting iff it does not exist already.
+ *
+ * @param offset The range offset
+ * @param length The range length
+ * @param highlighting The highlighting
+ */
+ private void addPosition(int offset, int length, HighlightingStyle highlighting) {
+ boolean isExisting= false;
+ // TODO: use binary search
+ for (int i= 0, n= fRemovedPositions.size(); i < n; i++) {
+ HighlightedPosition position= fRemovedPositions.get(i);
+ if (position == null)
+ continue;
+ if (position.isEqual(offset, length, highlighting)) {
+ isExisting= true;
+ fRemovedPositions.set(i, null);
+ fNOfRemovedPositions--;
+ break;
+ }
+ }
+
+ if (!isExisting) {
+ HighlightedPosition position= fJobPresenter.createHighlightedPosition(offset, length, highlighting);
+ fAddedPositions.add(position);
+ }
+ }
+
+ private IRemoteSemanticHighlightingService getSemanticHighlightingService(IProject project) {
+ IServiceModelManager smm = ServiceModelManager.getInstance();
+ IServiceConfiguration serviceConfig = smm.getActiveConfiguration(project);
+ IService indexingService = smm.getService(IRDTServiceConstants.SERVICE_C_INDEX);
+ IServiceProvider serviceProvider = serviceConfig.getServiceProvider(indexingService);
+ if (!(serviceProvider instanceof IIndexServiceProvider2)) {
+ return null;
+ }
+ IRemoteSemanticHighlightingService service = ((IIndexServiceProvider2) serviceProvider).getRemoteSemanticHighlightingService();
+ return service;
+ }
+
+
+ public void reconciled(IASTTranslationUnit ast, boolean force, IProgressMonitor progressMonitor) {
+ // ensure at most one thread can be reconciling at any time
+ synchronized (fReconcileLock) {
+ if (fIsReconciling)
+ return;
+ fIsReconciling= true;
+ }
+
+ TextPresentation textPresentation= null;
+ boolean updatePresentation = false;
+
+ fJobPresenter= fPresenter;
+ fJobSemanticHighlightings= fSemanticHighlightings;
+ fJobHighlightings= fHighlightings;
+
+ try {
+ if (fJobPresenter == null || fJobSemanticHighlightings == null || fJobHighlightings == null)
+ return;
+
+ IWorkingCopyManager fManager= CUIPlugin.getDefault().getWorkingCopyManager();
+ IWorkingCopy workingCopy= fManager.getWorkingCopy(fRemoteEditor.getEditorInput());
+
+ if (workingCopy == null) {
+ return;
+ }
+
+ fJobPresenter.setCanceled(progressMonitor != null && progressMonitor.isCanceled());
+
+ startReconcilingPositions();
+
+ if (!fJobPresenter.isCanceled()) {
+ IProject project = ((RemoteCEditor) fRemoteEditor).getInputCElement().getCProject().getProject();
+ IRemoteSemanticHighlightingService rsgs = getSemanticHighlightingService(project);
+
+ /*
+ * Send the working copy to the server. It will return the found positions in a comma
+ * separated list.
+ */
+ String foundPositions = rsgs.computeSemanticHighlightingPositions(workingCopy);
+ if (foundPositions != null && foundPositions.compareTo("") != 0) { //$NON-NLS-1$
+ parsePositions(foundPositions);
+ updatePresentation = true;
+ }
+ }
+
+ if (!fJobPresenter.isCanceled() && updatePresentation) {
+ //Update the presentation just as is done with the local C Editor
+ textPresentation= fJobPresenter.createPresentation(fAddedPositions, fRemovedPositions);
+ updatePresentation(textPresentation, fAddedPositions, fRemovedPositions);
+ }
+ stopReconcilingPositions();
+
+ } finally {
+ fJobPresenter= null;
+ fJobSemanticHighlightings= null;
+ fJobHighlightings= null;
+ synchronized (fReconcileLock) {
+ fIsReconciling= false;
+ }
+ }
+ }
+
+ private void sortPositions() {
+ List<HighlightedPosition> oldPositions= fRemovedPositions;
+ List<HighlightedPosition> newPositions= new ArrayList<HighlightedPosition>(fNOfRemovedPositions);
+ for (int i= 0, n= oldPositions.size(); i < n; i ++) {
+ HighlightedPosition current= oldPositions.get(i);
+ if (current != null)
+ newPositions.add(current);
+ }
+ fRemovedPositions= newPositions;
+ // positions need to be sorted by ascending offset
+ Collections.sort(fAddedPositions, new Comparator<Position>() {
+ public int compare(final Position p1, final Position p2) {
+ return p1.getOffset() - p2.getOffset();
+ }});
+ }
+
+
+ /**
+ * Update the presentation.
+ *
+ * @param textPresentation the text presentation
+ * @param addedPositions the added positions
+ * @param removedPositions the removed positions
+ */
+ protected void updatePresentation(TextPresentation textPresentation, List<HighlightedPosition> addedPositions, List<HighlightedPosition> removedPositions) {
+ Runnable runnable= fJobPresenter.createUpdateRunnable(textPresentation, addedPositions, removedPositions);
+ if (runnable == null)
+ return;
+
+ RemoteCEditor editor= fRemoteEditor;
+
+ if (editor == null)
+ return;
+
+ IWorkbenchPartSite site= editor.getSite();
+ if (site == null)
+ return;
+
+ Shell shell= site.getShell();
+ if (shell == null || shell.isDisposed())
+ return;
+
+ Display display= shell.getDisplay();
+ if (display == null || display.isDisposed())
+ return;
+
+ display.asyncExec(runnable);
+ }
+
+ /**
+ * Install this reconciler on the given editor, presenter and highlightings.
+ * @param editor the editor
+ * @param sourceViewer the source viewer
+ * @param fPresenter2 the semantic highlighting presenter
+ * @param semanticHighlightings the semantic highlightings
+ * @param highlightings the highlightings
+ */
+ public void install(RemoteCEditor editor, ISourceViewer sourceViewer, SemanticHighlightingPresenter fPresenter2, SemanticHighlighting[] semanticHighlightings, RemoteSemanticHighlightingManager.HighlightingStyle[] highlightings) {
+ fPresenter= fPresenter2;
+ fSemanticHighlightings= semanticHighlightings;
+ fHighlightings= highlightings;
+
+ fRemoteEditor= editor;
+
+ if (fRemoteEditor != null) {
+ fRemoteEditor.addReconcileListener(this);
+ }
+ }
+
+ /**
+ * Uninstall this reconciler from the editor
+ */
+ public void uninstall() {
+ if (fPresenter != null)
+ fPresenter.setCanceled(true);
+
+ if (fRemoteEditor != null) {
+ fRemoteEditor.removeReconcileListener(this);
+ fRemoteEditor= null;
+ }
+
+ fSemanticHighlightings= null;
+ fHighlightings= null;
+ fPresenter= null;
+ }
+
+ /**
+ * Schedule a background job used for preference changes.
+ * This is a copy of super.scheduleJob. The The local ast is NOT used here.
+ */
+ private void scheduleJob() {
+ final ICElement element= fRemoteEditor.getInputCElement();
+
+ synchronized (fJobLock) {
+ final Job oldJob= fJob;
+ if (fJob != null) {
+ fJob.cancel();
+ fJob= null;
+ }
+
+ if (element != null) {
+ fJob= new Job(CEditorMessages.SemanticHighlighting_job) {
+ @Override
+ protected IStatus run(final IProgressMonitor monitor) {
+ if (oldJob != null) {
+ try {
+ oldJob.join();
+ } catch (InterruptedException e) {
+ CUIPlugin.log(e);
+ return Status.CANCEL_STATUS;
+ }
+ }
+ if (monitor.isCanceled())
+ return Status.CANCEL_STATUS;
+
+ final Job me= this;
+ ASTProvider astProvider= CUIPlugin.getDefault().getASTProvider();
+ IStatus status= astProvider.runOnAST(element, ASTProvider.WAIT_IF_OPEN, monitor, new ASTCache.ASTRunnable() {
+ public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
+ reconciled(ast, true, monitor);
+ synchronized (fJobLock) {
+ // allow the job to be gc'ed
+ if (fJob == me)
+ fJob= null;
+ }
+ return Status.OK_STATUS;
+ }
+ });
+ return status;
+ }
+ };
+ fJob.setPriority(Job.SHORT);
+ fJob.schedule();
+ }
+ }
+ }
+
+ /**
+ * Refreshes the highlighting.
+ */
+ public void refresh() {
+ scheduleJob();
+ }
+
+}
diff --git a/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/internal/rdt/ui/editor/RemoteSemanticHighlightingService.java b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/internal/rdt/ui/editor/RemoteSemanticHighlightingService.java
new file mode 100644
index 0000000..beafcef
--- /dev/null
+++ b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/internal/rdt/ui/editor/RemoteSemanticHighlightingService.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.ptp.internal.rdt.ui.editor;
+
+import java.util.Map;
+
+import org.eclipse.cdt.core.model.CModelException;
+import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.cdt.core.model.IWorkingCopy;
+import org.eclipse.cdt.core.parser.IScannerInfo;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.ptp.internal.rdt.core.RemoteIndexerInfoProviderFactory;
+import org.eclipse.ptp.internal.rdt.core.model.ModelAdapter;
+import org.eclipse.ptp.internal.rdt.core.model.TranslationUnit;
+import org.eclipse.ptp.internal.rdt.core.serviceproviders.AbstractRemoteService;
+import org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem;
+import org.eclipse.ptp.rdt.core.RDTLog;
+import org.eclipse.ptp.rdt.ui.subsystems.RSECIndexSubsystem;
+import org.eclipse.rse.core.subsystems.IConnectorService;
+
+/**
+ * A service for computing semantic highlighting on a remote host.
+ */
+public class RemoteSemanticHighlightingService extends AbstractRemoteService implements IRemoteSemanticHighlightingService {
+
+ public RemoteSemanticHighlightingService(IConnectorService connectorService) {
+ super(connectorService);
+ }
+
+ public RemoteSemanticHighlightingService(ICIndexSubsystem subsystem) {
+ super(subsystem);
+ }
+
+ public String computeSemanticHighlightingPositions(IWorkingCopy workingCopy) {
+ ICIndexSubsystem subsystem = getSubSystem();
+ ITranslationUnit unit = workingCopy.getTranslationUnit();
+
+ ITranslationUnit targetUnit;
+ try {
+ targetUnit = ModelAdapter.adaptElement(null, unit, 0, true);
+ } catch (CModelException e1) {
+ RDTLog.logError(e1);
+ return null;
+ } catch (Exception e) {
+ RDTLog.logError(e);
+ return null;
+ }
+
+ // TODO: This can potentially take a while. But we need
+ // to trigger scope initialization in case it hasn't
+ // been done for the project.
+ IProject project = unit.getCProject().getProject();
+ IProgressMonitor monitor = new NullProgressMonitor();
+ subsystem.checkProject(project, monitor);
+
+ if(targetUnit instanceof TranslationUnit) {
+ IScannerInfo scannerInfo = RemoteIndexerInfoProviderFactory.getScannerInfo(unit.getResource());
+ Map<String,String> langaugeProperties = null;
+ try {
+ String languageId = unit.getLanguage().getId();
+ langaugeProperties = RemoteIndexerInfoProviderFactory.getLanguageProperties(languageId, project);
+ } catch(Exception e) {
+ RDTLog.logError(e);
+ }
+ ((TranslationUnit)targetUnit).setASTContext(scannerInfo, langaugeProperties);
+ }
+
+ return subsystem.computeHighlightPositions(targetUnit);
+ }
+} \ No newline at end of file
diff --git a/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/preferences/Messages.java b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/preferences/Messages.java
index 8f59800..98f6e05 100644
--- a/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/preferences/Messages.java
+++ b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/preferences/Messages.java
@@ -13,7 +13,7 @@ package org.eclipse.ptp.rdt.ui.preferences;
import org.eclipse.osgi.util.NLS;
/**
- * @since 4.0
+ * @since 4.1
*/
public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.ptp.rdt.ui.preferences.messages"; //$NON-NLS-1$
diff --git a/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/preferences/PreferenceConstants.java b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/preferences/PreferenceConstants.java
index 03f0602..5fba5d2 100644
--- a/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/preferences/PreferenceConstants.java
+++ b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/preferences/PreferenceConstants.java
@@ -13,7 +13,7 @@
package org.eclipse.ptp.rdt.ui.preferences;
/**
- * @since 4.0
+ * @since 4.1
*/
public final class PreferenceConstants {
diff --git a/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/preferences/PreferenceInitializer.java b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/preferences/PreferenceInitializer.java
index ac0930c..fc5a2f2 100644
--- a/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/preferences/PreferenceInitializer.java
+++ b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/preferences/PreferenceInitializer.java
@@ -17,7 +17,7 @@ import org.eclipse.ptp.rdt.ui.UIPlugin;
/**
* Class used to initialize default preference values.
- * @since 4.0
+ * @since 4.1
*/
public class PreferenceInitializer extends AbstractPreferenceInitializer {
diff --git a/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/preferences/RemoteDevelopmentPreferencePage.java b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/preferences/RemoteDevelopmentPreferencePage.java
index 7294642..f5b616e 100644
--- a/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/preferences/RemoteDevelopmentPreferencePage.java
+++ b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/preferences/RemoteDevelopmentPreferencePage.java
@@ -28,7 +28,7 @@ import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
/**
- * @since 4.0
+ * @since 4.1
*
*/
public class RemoteDevelopmentPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
diff --git a/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/serviceproviders/IIndexServiceProvider2.java b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/serviceproviders/IIndexServiceProvider2.java
index 87cd758..4b8f176 100755
--- a/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/serviceproviders/IIndexServiceProvider2.java
+++ b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/serviceproviders/IIndexServiceProvider2.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 IBM Corporation and others.
+ * Copyright (c) 2008, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,6 +11,7 @@
package org.eclipse.ptp.rdt.ui.serviceproviders;
import org.eclipse.ptp.internal.rdt.ui.contentassist.IContentAssistService;
+import org.eclipse.ptp.internal.rdt.ui.editor.IRemoteSemanticHighlightingService;
import org.eclipse.ptp.internal.rdt.ui.navigation.INavigationService;
import org.eclipse.ptp.internal.rdt.ui.search.ISearchService;
import org.eclipse.ptp.rdt.core.serviceproviders.IIndexServiceProvider;
@@ -32,4 +33,9 @@ public interface IIndexServiceProvider2 extends IIndexServiceProvider {
* @since 4.0
*/
public INavigationService getNavigationService();
+
+ /**
+ * @since 4.1
+ */
+ public IRemoteSemanticHighlightingService getRemoteSemanticHighlightingService();
}
diff --git a/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/serviceproviders/LocalCIndexServiceProvider.java b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/serviceproviders/LocalCIndexServiceProvider.java
index 93ec194..2a07428 100644
--- a/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/serviceproviders/LocalCIndexServiceProvider.java
+++ b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/serviceproviders/LocalCIndexServiceProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation and others.
+ * Copyright (c) 2011, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -13,6 +13,8 @@ package org.eclipse.ptp.rdt.ui.serviceproviders;
import org.eclipse.ptp.internal.rdt.core.serviceproviders.AbstractLocalCIndexServiceProvider;
import org.eclipse.ptp.internal.rdt.ui.contentassist.IContentAssistService;
import org.eclipse.ptp.internal.rdt.ui.contentassist.LocalContentAssistService;
+import org.eclipse.ptp.internal.rdt.ui.editor.IRemoteSemanticHighlightingService;
+import org.eclipse.ptp.internal.rdt.ui.editor.RemoteSemanticHighlightingService;
import org.eclipse.ptp.internal.rdt.ui.navigation.INavigationService;
import org.eclipse.ptp.internal.rdt.ui.navigation.LocalNavigationService;
import org.eclipse.ptp.internal.rdt.ui.search.ISearchService;
@@ -29,6 +31,7 @@ public class LocalCIndexServiceProvider extends AbstractLocalCIndexServiceProvid
private ISearchService fSearchService;
private IContentAssistService fContentAssistService;
private INavigationService fNavigationService;
+ private IRemoteSemanticHighlightingService fRemoteSemanticHighlightingService;
public boolean isRemote() {
return false;
@@ -52,4 +55,16 @@ public class LocalCIndexServiceProvider extends AbstractLocalCIndexServiceProvid
return fContentAssistService;
}
+ /**
+ * @since 4.1
+ */
+ public IRemoteSemanticHighlightingService getRemoteSemanticHighlightingService() {
+ if(!isConfigured())
+ return null;
+
+ if(fRemoteSemanticHighlightingService== null)
+ fRemoteSemanticHighlightingService = new RemoteSemanticHighlightingService(fConnectorService);
+
+ return fRemoteSemanticHighlightingService;
+ }
}
diff --git a/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/serviceproviders/NullCIndexServiceProvider.java b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/serviceproviders/NullCIndexServiceProvider.java
index 8f1372d..030710c 100644
--- a/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/serviceproviders/NullCIndexServiceProvider.java
+++ b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/serviceproviders/NullCIndexServiceProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 IBM Corporation and others.
+ * Copyright (c) 2008, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -40,6 +40,7 @@ import org.eclipse.ptp.internal.rdt.core.serviceproviders.AbstractRemoteCIndexSe
import org.eclipse.ptp.internal.rdt.core.typehierarchy.ITypeHierarchyService;
import org.eclipse.ptp.internal.rdt.core.typehierarchy.THGraph;
import org.eclipse.ptp.internal.rdt.ui.contentassist.IContentAssistService;
+import org.eclipse.ptp.internal.rdt.ui.editor.IRemoteSemanticHighlightingService;
import org.eclipse.ptp.internal.rdt.ui.navigation.INavigationService;
import org.eclipse.ptp.internal.rdt.ui.search.ISearchService;
import org.eclipse.ptp.rdt.ui.messages.Messages;
@@ -307,4 +308,15 @@ public class NullCIndexServiceProvider extends
return Messages.getString("NullServiceProvider.config"); //$NON-NLS-1$
}
+ /**
+ * @since 4.1
+ */
+ public IRemoteSemanticHighlightingService getRemoteSemanticHighlightingService() {
+ return new IRemoteSemanticHighlightingService() {
+ public String computeSemanticHighlightingPositions(
+ IWorkingCopy workingCopy) {
+ return null;
+ }
+ };
+ }
}
diff --git a/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/serviceproviders/RSECIndexServiceProvider.java b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/serviceproviders/RSECIndexServiceProvider.java
index 86bf22d..39af844 100755
--- a/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/serviceproviders/RSECIndexServiceProvider.java
+++ b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/serviceproviders/RSECIndexServiceProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 IBM Corporation and others.
+ * Copyright (c) 2008, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -13,6 +13,8 @@ package org.eclipse.ptp.rdt.ui.serviceproviders;
import org.eclipse.ptp.internal.rdt.core.serviceproviders.AbstractRemoteCIndexServiceProvider;
import org.eclipse.ptp.internal.rdt.ui.contentassist.IContentAssistService;
import org.eclipse.ptp.internal.rdt.ui.contentassist.RemoteContentAssistService;
+import org.eclipse.ptp.internal.rdt.ui.editor.IRemoteSemanticHighlightingService;
+import org.eclipse.ptp.internal.rdt.ui.editor.RemoteSemanticHighlightingService;
import org.eclipse.ptp.internal.rdt.ui.navigation.INavigationService;
import org.eclipse.ptp.internal.rdt.ui.navigation.RemoteNavigationService;
import org.eclipse.ptp.internal.rdt.ui.search.ISearchService;
@@ -42,6 +44,7 @@ public class RSECIndexServiceProvider extends AbstractRemoteCIndexServiceProvide
private RemoteSearchService fSearchService;
private IContentAssistService fContentAssistService;
private INavigationService fNavigationService;
+ private IRemoteSemanticHighlightingService fRemoteSemanticHighlightingService;
/**
* @since 4.0
@@ -135,4 +138,17 @@ public class RSECIndexServiceProvider extends AbstractRemoteCIndexServiceProvide
public String toString() {
return "RSECIndexServiceProvider(" + getHostName() + "," + getIndexLocation() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
+
+ /**
+ * @since 4.1
+ */
+ public synchronized IRemoteSemanticHighlightingService getRemoteSemanticHighlightingService() {
+ if(!isConfigured())
+ return null;
+
+ if(fRemoteSemanticHighlightingService== null)
+ fRemoteSemanticHighlightingService = new RemoteSemanticHighlightingService(fConnectorService);
+
+ return fRemoteSemanticHighlightingService;
+ }
}
diff --git a/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/subsystems/RSECIndexSubsystem.java b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/subsystems/RSECIndexSubsystem.java
index 5329492..449debd 100755
--- a/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/subsystems/RSECIndexSubsystem.java
+++ b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/rdt/ui/subsystems/RSECIndexSubsystem.java
@@ -822,6 +822,57 @@ public class RSECIndexSubsystem extends SubSystem implements ICIndexSubsystem {
return (List<RemoteSearchMatch>) result;
}
+ /**
+ * @since 4.1
+ */
+ @SuppressWarnings("unchecked")
+ public String computeHighlightPositions(ITranslationUnit targetUnit) {
+ // If something goes wrong, return an empty string.
+
+ checkAllProjects(new NullProgressMonitor());
+ DataStore dataStore = getDataStore(null);
+ if (dataStore == null) {
+ return ""; //$NON-NLS-1$
+ }
+ DataElement queryCmd = dataStore.localDescriptorQuery(dataStore.getDescriptorRoot(), CDTMiner.C_SEMANTIC_HIGHTLIGHTING_COMPUTE_POSITIONS);
+ if (queryCmd == null) {
+ return ""; //$NON-NLS-1$
+ }
+ NullProgressMonitor monitor = new NullProgressMonitor();
+ StatusMonitor smonitor = StatusMonitorFactory.getInstance().getStatusMonitorFor(getConnectorService(), dataStore);
+ ArrayList<Object> args = new ArrayList<Object>();
+ Scope scope = new Scope(targetUnit.getCProject().getProject());
+ DataElement dataElement = dataStore.createObject(null, CDTMiner.T_SCOPE_SCOPENAME_DESCRIPTOR, scope.getName());
+
+ args.add(dataElement);
+ args.add(createSerializableElement(dataStore, targetUnit));
+
+ // execute the command
+ DataElement status = dataStore.command(queryCmd, args, dataStore.getDescriptorRoot());
+
+ try {
+ smonitor.waitForUpdate(status, monitor);
+ }
+ catch (Exception e) {
+ RDTLog.logError(e);
+ }
+
+ DataElement element = status.get(0);
+ String data = element.getName();
+ try {
+ Object result = Serializer.deserialize(data);
+ if (result == null || !(result instanceof String)) {
+ return ""; //$NON-NLS-1$;
+ }
+ return (String) result;
+ } catch (IOException e) {
+ RDTLog.logError(e);
+ } catch (ClassNotFoundException e) {
+ RDTLog.logError(e);
+ }
+ return ""; //$NON-NLS-1$
+ }
+
@SuppressWarnings("unchecked")
public List<Proposal> computeCompletionProposals(Scope scope, RemoteContentAssistInvocationContext context, ITranslationUnit unit) {
checkAllProjects(new NullProgressMonitor());