diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml
index 58dbda15adf..119ca10540d 100644
--- a/core/org.eclipse.cdt.ui/plugin.xml
+++ b/core/org.eclipse.cdt.ui/plugin.xml
@@ -569,6 +569,12 @@
label="%Dummy.label"
value="206, 204, 247">
+
+
Preferences>Java>Code Generation>Code and Comments
- */
public class CSearchUtil {
public static int LRU_WORKINGSET_LIST_SIZE= 3;
@@ -32,7 +27,6 @@ public class CSearchUtil {
public CSearchUtil() {
super();
- // TODO Auto-generated constructor stub
}
public static void updateLRUWorkingSets(IWorkingSet[] workingSets) {
@@ -49,11 +43,6 @@ public class CSearchUtil {
return CSearchUtil.workingSetsCache;
}
- public static void warnIfBinaryConstant( ICElement element, Shell shell) {
- // TODO Auto-generated method stub
-
- }
-
public static String toString(IWorkingSet[] workingSets) {
if( workingSets != null && workingSets.length > 0 ){
String string = new String();
@@ -69,8 +58,14 @@ public class CSearchUtil {
return null;
}
- public static ICElement getCElement(IMarker marker) {
- // TODO Auto-generated method stub
- return null;
+ public static boolean isWriteOccurrence(IASTName node, IBinding binding) {
+ boolean isWrite;
+ if (binding instanceof ICPPVariable) {
+ isWrite = ((CPPVariableReadWriteFlags.getReadWriteFlags(node) & PDOMName.WRITE_ACCESS) != 0);
+ }
+ else {
+ isWrite = ((CVariableReadWriteFlags.getReadWriteFlags(node) & PDOMName.WRITE_ACCESS) != 0);
+ }
+ return isWrite;
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/LineSearchElement.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/LineSearchElement.java
index 098a3998c98..efef5016330 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/LineSearchElement.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/LineSearchElement.java
@@ -37,12 +37,14 @@ public class LineSearchElement extends PDOMSearchElement {
private final int fLength;
private final boolean fIsPolymorphicCall;
private final ICElement fEnclosingElement;
+ private final boolean fIsWriteAccess;
- public Match(int offset, int length, boolean isPolymorphicCall, ICElement enclosingElement) {
+ public Match(int offset, int length, boolean isPolymorphicCall, ICElement enclosingElement, boolean isWriteAccess) {
fOffset = offset;
fLength = length;
fIsPolymorphicCall = isPolymorphicCall;
fEnclosingElement = enclosingElement;
+ fIsWriteAccess = isWriteAccess;
}
public int getOffset() {
@@ -61,6 +63,10 @@ public class LineSearchElement extends PDOMSearchElement {
return fEnclosingElement;
}
+ public boolean isWriteAccess() {
+ return fIsWriteAccess;
+ }
+
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Match))
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/OccurrencesFinder.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/OccurrencesFinder.java
index 69cfa19835e..a93b70a0f32 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/OccurrencesFinder.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/OccurrencesFinder.java
@@ -22,14 +22,10 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
-import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.core.parser.Keywords;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
-import org.eclipse.cdt.internal.core.dom.parser.c.CVariableReadWriteFlags;
-import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVariableReadWriteFlags;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
-import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
import org.eclipse.cdt.internal.ui.util.Messages;
@@ -174,15 +170,9 @@ public class OccurrencesFinder implements IOccurrencesFinder {
final int length= fileLocation.getNodeLength();
if (offset >= 0 && length > 0) {
if (binding instanceof IVariable) {
- boolean isWrite;
- if (binding instanceof ICPPVariable) {
- isWrite = ((CPPVariableReadWriteFlags.getReadWriteFlags(node) & PDOMName.WRITE_ACCESS) != 0);
- }
- else {
- isWrite = ((CVariableReadWriteFlags.getReadWriteFlags(node) & PDOMName.WRITE_ACCESS) != 0);
- }
- int flag = isWrite ? F_WRITE_OCCURRENCE : F_READ_OCCURRENCE;
- String description = isWrite ? fWriteDescription : fReadDescription;
+ final boolean isWriteOccurrence = CSearchUtil.isWriteOccurrence(node, binding);
+ int flag = isWriteOccurrence ? F_WRITE_OCCURRENCE : F_READ_OCCURRENCE;
+ String description = isWriteOccurrence ? fWriteDescription : fReadDescription;
fResult.add(new OccurrenceLocation(offset, length, flag, description));
}
else {
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchLabelProvider.java
index 33c8c084062..6ce16e7978c 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchLabelProvider.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchLabelProvider.java
@@ -19,6 +19,7 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.StyledString;
+import org.eclipse.jface.viewers.StyledString.Styler;
import org.eclipse.search.ui.text.AbstractTextSearchResult;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.ISharedImages;
@@ -169,7 +170,8 @@ public class PDOMSearchLabelProvider extends LabelProvider implements IStyledLab
for (Match match : lineElement.getMatches()) {
int offset = Math.max(0, match.getOffset() - lineOffset);
int length = Math.min(match.getLength(), lineContent.length() - offset);
- styled.setStyle(offset, length, ColoringLabelProvider.HIGHLIGHT_STYLE);
+ Styler style = match.isWriteAccess() ? ColoringLabelProvider.HIGHLIGHT_WRITE_STYLE : ColoringLabelProvider.HIGHLIGHT_STYLE;
+ styled.setStyle(offset, length, style);
}
return styled;
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchQuery.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchQuery.java
index caffd9a8622..32c85795a4a 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchQuery.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchQuery.java
@@ -45,7 +45,9 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.IPositionConverter;
import org.eclipse.cdt.core.browser.ITypeReference;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
+import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
@@ -200,10 +202,7 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
if (names == null)
return;
- ICProject preferred= null;
- if (projects != null && projects.length == 1) {
- preferred= projects[0];
- }
+ ICProject preferred = getPreferredProject();
for (IIndexName name : names) {
if (!filterName(name)) {
if (!isPolymorphicOnly || name.couldBePolymorphicMethodCall()) {
@@ -221,7 +220,8 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
if (enclosingDefinition != null) {
enclosingElement = IndexUI.getCElementForName(preferred, index, enclosingDefinition);
}
- matches.add(new Match(nodeOffset, nodeLength, isPolymorphicOnly, enclosingElement));
+ boolean isWriteAccess = name.isWriteAccess();
+ matches.add(new Match(nodeOffset, nodeLength, isPolymorphicOnly, enclosingElement, isWriteAccess));
}
}
@@ -241,7 +241,8 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
int length = region.getLength();
boolean isPolymorphicCall = match.isPolymorphicCall();
ICElement enclosingElement = match.getEnclosingElement();
- convertedMatches.add(new Match(offset, length, isPolymorphicCall, enclosingElement));
+ boolean isWriteAccess = match.isWriteAccess();
+ convertedMatches.add(new Match(offset, length, isPolymorphicCall, enclosingElement, isWriteAccess));
}
matches = convertedMatches;
}
@@ -354,7 +355,7 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
names.addAll(Arrays.asList(bindingNames));
}
- protected void createLocalMatches(IASTTranslationUnit ast, IBinding binding) {
+ protected void createLocalMatches(IASTTranslationUnit ast, IBinding binding) throws CoreException {
if (binding != null) {
Set names= new HashSet();
names.addAll(Arrays.asList(ast.getDeclarationsInAST(binding)));
@@ -371,7 +372,17 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
if (typeInfo != null) {
ITypeReference ref= typeInfo.getResolvedReference();
if (ref != null) {
- localMatches.add(new Match(ref.getOffset(), ref.getLength(), false, null));
+ ICElement element = null;
+ IASTNode node = name;
+ while (node != null && !(node instanceof IASTFunctionDefinition)) {
+ node= node.getParent();
+ }
+ if (node != null) {
+ IASTFunctionDefinition definition = (IASTFunctionDefinition) node;
+ element = IndexUI.getCElementForName(getPreferredProject(), ast.getIndex(), definition.getDeclarator().getName());
+ }
+ boolean isWrite = CSearchUtil.isWriteOccurrence(name, binding);
+ localMatches.add(new Match(ref.getOffset(), ref.getLength(), false, element , isWrite));
fileLocation = typeInfo.getIFL();
}
}
@@ -418,6 +429,14 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
}
}
+ private ICProject getPreferredProject() {
+ ICProject preferred= null;
+ if (projects != null && projects.length == 1) {
+ preferred= projects[0];
+ }
+ return preferred;
+ }
+
public final IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
PDOMSearchResult result= (PDOMSearchResult) getSearchResult();
result.removeAll();