1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Bug 324905 - [Search] Show different colors to mark read and write accesses in Mark Occurrences

Patch from Patrick Hofer
This commit is contained in:
Anton Leherbauer 2010-09-17 08:38:51 +00:00
parent c5b4c65418
commit ca68f6bb04
9 changed files with 118 additions and 47 deletions

View file

@ -17,7 +17,7 @@ static void globalStaticFunc() {
EMPTY_MACRO(n);
globalVariable = 1;
EMPTY_MACRO(1);
return 0;
return;
}
class Base1 {

View file

@ -69,12 +69,16 @@ public class MarkOccurrenceTest extends BaseUITestCase {
private static final String PROJECT = "MarkOccurrenceTest";
private static final String OCCURRENCE_ANNOTATION= "org.eclipse.cdt.ui.occurrences";
private static final String WRITE_OCCURRENCE_ANNOTATION= "org.eclipse.cdt.ui.occurrences.write";
private static final RGB fgHighlightRGB= getHighlightRGB();
private static final RGB fgWriteHighlightRGB= getWriteHighlightRGB();
private CEditor fEditor;
private IDocument fDocument;
private FindReplaceDocumentAdapter fFindReplaceDocumentAdapter;
private int fOccurrences;
private int fWriteOccurrences;
private IAnnotationModel fAnnotationModel;
private ISelectionListenerWithAST fSelWASTListener;
private IRegion fMatch;
@ -117,6 +121,7 @@ public class MarkOccurrenceTest extends BaseUITestCase {
fProjectSetup.setUp();
}
assertNotNull(fgHighlightRGB);
assertNotNull(fgWriteHighlightRGB);
final IPreferenceStore store = CUIPlugin.getDefault().getPreferenceStore();
store.setValue(PreferenceConstants.EDITOR_MARK_OCCURRENCES, true);
// TLETODO temporary fix for bug 314635
@ -143,11 +148,14 @@ public class MarkOccurrenceTest extends BaseUITestCase {
private synchronized void countOccurrences() {
fOccurrences= 0;
fWriteOccurrences= 0;
Iterator<Annotation> iter= fAnnotationModel.getAnnotationIterator();
while (iter.hasNext()) {
Annotation annotation= iter.next();
if (OCCURRENCE_ANNOTATION.equals(annotation.getType()))
if (annotation.getType().startsWith(OCCURRENCE_ANNOTATION))
fOccurrences++;
if (annotation.getType().equals(WRITE_OCCURRENCE_ANNOTATION))
fWriteOccurrences++;
}
}
};
@ -193,7 +201,7 @@ public class MarkOccurrenceTest extends BaseUITestCase {
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(3);
assertOccurrences(3, 0);
assertOccurrencesInWidget();
}
@ -207,7 +215,7 @@ public class MarkOccurrenceTest extends BaseUITestCase {
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(5);
assertOccurrences(5, 0);
assertOccurrencesInWidget();
}
@ -221,7 +229,7 @@ public class MarkOccurrenceTest extends BaseUITestCase {
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(3);
assertOccurrences(3, 0);
assertOccurrencesInWidget();
}
@ -235,7 +243,7 @@ public class MarkOccurrenceTest extends BaseUITestCase {
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(4);
assertOccurrences(4, 0);
assertOccurrencesInWidget();
}
@ -249,7 +257,7 @@ public class MarkOccurrenceTest extends BaseUITestCase {
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(3);
assertOccurrences(3, 0);
assertOccurrencesInWidget();
}
@ -263,7 +271,7 @@ public class MarkOccurrenceTest extends BaseUITestCase {
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(3);
assertOccurrences(3, 0);
assertOccurrencesInWidget();
}
@ -277,7 +285,7 @@ public class MarkOccurrenceTest extends BaseUITestCase {
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(4);
assertOccurrences(4, 0);
assertOccurrencesInWidget();
}
@ -306,7 +314,7 @@ public class MarkOccurrenceTest extends BaseUITestCase {
fMatch= new Region(fMatch.getOffset(), 4);
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(1);
assertOccurrences(1, 0);
assertOccurrencesInWidget();
store.setValue("REUSE_OPEN_EDITORS_BOOLEAN", false);
@ -323,7 +331,7 @@ public class MarkOccurrenceTest extends BaseUITestCase {
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(2);
assertOccurrences(2, 0);
assertOccurrencesInWidget();
}
@ -337,7 +345,7 @@ public class MarkOccurrenceTest extends BaseUITestCase {
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(2);
assertOccurrences(2, 0);
assertOccurrencesInWidget();
}
@ -351,7 +359,7 @@ public class MarkOccurrenceTest extends BaseUITestCase {
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(2);
assertOccurrences(2, 1);
assertOccurrencesInWidget();
}
@ -365,7 +373,7 @@ public class MarkOccurrenceTest extends BaseUITestCase {
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(2);
assertOccurrences(2, 2);
assertOccurrencesInWidget();
}
@ -380,7 +388,7 @@ public class MarkOccurrenceTest extends BaseUITestCase {
fMatch= new Region(fMatch.getOffset(), fMatch.getLength() - 1);
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(2);
assertOccurrences(2, 0);
assertOccurrencesInWidget();
}
@ -395,7 +403,7 @@ public class MarkOccurrenceTest extends BaseUITestCase {
fMatch= new Region(fMatch.getOffset() + 1, fMatch.getLength() - 1);
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(2);
assertOccurrences(2, 0);
assertOccurrencesInWidget();
}
@ -409,7 +417,7 @@ public class MarkOccurrenceTest extends BaseUITestCase {
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(2);
assertOccurrences(2, 1);
assertOccurrencesInWidget();
}
@ -423,7 +431,7 @@ public class MarkOccurrenceTest extends BaseUITestCase {
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(5);
assertOccurrences(5, 0);
assertOccurrencesInWidget();
}
@ -437,7 +445,7 @@ public class MarkOccurrenceTest extends BaseUITestCase {
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(3);
assertOccurrences(3, 0);
assertOccurrencesInWidget();
}
@ -451,7 +459,7 @@ public class MarkOccurrenceTest extends BaseUITestCase {
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(2);
assertOccurrences(2, 0);
assertOccurrencesInWidget();
}
@ -465,7 +473,7 @@ public class MarkOccurrenceTest extends BaseUITestCase {
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(3);
assertOccurrences(3, 0);
assertOccurrencesInWidget();
}
@ -479,7 +487,7 @@ public class MarkOccurrenceTest extends BaseUITestCase {
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(4);
assertOccurrences(4, 2);
assertOccurrencesInWidget();
}
@ -493,7 +501,7 @@ public class MarkOccurrenceTest extends BaseUITestCase {
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(2);
assertOccurrences(2, 0);
assertOccurrencesInWidget();
}
@ -507,7 +515,7 @@ public class MarkOccurrenceTest extends BaseUITestCase {
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(2);
assertOccurrences(2, 0);
assertOccurrencesInWidget();
}
@ -524,17 +532,17 @@ public class MarkOccurrenceTest extends BaseUITestCase {
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(0);
assertOccurrences(0, 0);
assertOccurrencesInWidget();
}
private void assertOccurrencesInWidget() {
EditorTestHelper.runEventQueue(500);
EditorTestHelper.runEventQueue(100);
Iterator<Annotation> iter= fAnnotationModel.getAnnotationIterator();
while (iter.hasNext()) {
Annotation annotation= iter.next();
if (OCCURRENCE_ANNOTATION.equals(annotation.getType()))
if (annotation.getType().startsWith(OCCURRENCE_ANNOTATION))
assertOccurrenceInWidget(fAnnotationModel.getPosition(annotation));
}
}
@ -544,7 +552,7 @@ public class MarkOccurrenceTest extends BaseUITestCase {
for (int i= 0; i < styleRanges.length; i++) {
if (styleRanges[i].background != null) {
RGB rgb= styleRanges[i].background.getRGB();
if (fgHighlightRGB.equals(rgb))
if ((fgHighlightRGB.equals(rgb)) || (fgWriteHighlightRGB.equals(rgb)))
return;
}
}
@ -565,15 +573,30 @@ public class MarkOccurrenceTest extends BaseUITestCase {
return null;
}
private void assertOccurrences(final int expected) {
/**
* Returns the write occurrence annotation color.
*
* @return the write occurrence annotation color
*/
private static RGB getWriteHighlightRGB() {
AnnotationPreference annotationPref= EditorsPlugin.getDefault().getAnnotationPreferenceLookup().getAnnotationPreference(WRITE_OCCURRENCE_ANNOTATION);
IPreferenceStore store= EditorsUI.getPreferenceStore();
if (store != null)
return PreferenceConverter.getColor(store, annotationPref.getColorPreferenceKey());
return null;
}
private void assertOccurrences(final int expected, final int expectedWrite) {
DisplayHelper helper= new DisplayHelper() {
@Override
protected boolean condition() {
return fOccurrences == expected;
return ((fOccurrences == expected) && (fWriteOccurrences == expectedWrite));
}
};
if (!helper.waitForCondition(EditorTestHelper.getActiveDisplay(), 10000)) {
assertEquals(expected, fOccurrences);
assertEquals(expectedWrite, fWriteOccurrences);
}
}
}

View file

@ -514,6 +514,7 @@ toggleMarkOccurrences.tooltip= Toggle Mark Occurrences
toggleMarkOccurrences.description= Toggles mark occurrences in C/C++ editors
OccurrenceAnnotation.label= C/C++ Occurrences
WriteOccurrenceAnnotation.label= C/C++ Write Occurrences
DocCommentOwner.name = DocCommentOwner
Doxygen.name = Doxygen

View file

@ -2601,25 +2601,42 @@
annotationType="org.eclipse.cdt.ui.occurrences"
label="%OccurrenceAnnotation.label"
icon="$nl$/icons/obj16/searchm_obj.gif"
textPreferenceKey="org.eclipse.cdt.ui.occurrenceIndication"
textPreferenceKey="occurrenceIndication"
textPreferenceValue="false"
highlightPreferenceKey="org.eclipse.cdt.ui.occurrenceHighlighting"
highlightPreferenceKey="occurrenceHighlighting"
highlightPreferenceValue="true"
contributesToHeader="false"
overviewRulerPreferenceKey="org.eclipse.cdt.ui.occurrenceIndicationInOverviewRuler"
overviewRulerPreferenceKey="occurrenceIndicationInOverviewRuler"
overviewRulerPreferenceValue="true"
verticalRulerPreferenceKey="org.eclipse.cdt.ui.occurrenceIndicationInVerticalRuler"
verticalRulerPreferenceKey="occurrenceIndicationInVerticalRuler"
verticalRulerPreferenceValue="false"
colorPreferenceKey="org.eclipse.cdt.ui.occurrenceIndicationColor"
colorPreferenceKey="occurrenceIndicationColor"
colorPreferenceValue="212,212,212"
presentationLayer="4"
showInNextPrevDropdownToolbarActionKey="org.eclipse.cdt.ui.showOccurrenceInNextPrevDropdownToolbarAction"
showInNextPrevDropdownToolbarActionKey="showOccurrenceInNextPrevDropdownToolbarAction"
showInNextPrevDropdownToolbarAction="true"
isGoToNextNavigationTargetKey="org.eclipse.cdt.ui.isOccurrenceGoToNextNavigationTarget"
isGoToNextNavigationTargetKey="isOccurrenceGoToNextNavigationTarget"
isGoToNextNavigationTarget="false"
isGoToPreviousNavigationTargetKey="org.eclipse.cdt.ui.isOccurrenceGoToPreviousNavigationTarget"
isGoToPreviousNavigationTargetKey="isOccurrenceGoToPreviousNavigationTarget"
isGoToPreviousNavigationTarget="false"
textStylePreferenceKey="org.eclipse.cdt.ui.occurrenceTextStyle"
textStylePreferenceKey="occurrenceTextStyle"
textStylePreferenceValue="NONE">
</specification>
<specification
annotationType="org.eclipse.cdt.ui.occurrences.write"
label="%WriteOccurrenceAnnotation.label"
textPreferenceKey="occurrenceIndication"
textPreferenceValue="false"
highlightPreferenceKey="writeOccurrenceHighlighting"
highlightPreferenceValue="true"
overviewRulerPreferenceKey="writeOccurrenceIndicationInOverviewRuler"
overviewRulerPreferenceValue="true"
verticalRulerPreferenceKey="writeOccurrenceIndicationInVerticalRuler"
verticalRulerPreferenceValue="false"
colorPreferenceKey="writeOccurrenceIndicationColor"
colorPreferenceValue="240, 216, 168"
presentationLayer="4"
textStylePreferenceKey="writeOccurrenceTextStyle"
textStylePreferenceValue="NONE">
</specification>
<specification
@ -2798,6 +2815,10 @@
<type
name="org.eclipse.cdt.ui.occurrences">
</type>
<type
name="org.eclipse.cdt.ui.occurrences.write"
super="org.eclipse.cdt.ui.occurrences">
</type>
<type name="org.eclipse.cdt.ui.overrideIndicator"/>
</extension>
<extension point="org.eclipse.ui.workbench.texteditor.spellingEngine">

View file

@ -210,6 +210,7 @@ import org.eclipse.cdt.internal.ui.actions.RemoveBlockCommentAction;
import org.eclipse.cdt.internal.ui.actions.StructureSelectionAction;
import org.eclipse.cdt.internal.ui.actions.SurroundWithActionGroup;
import org.eclipse.cdt.internal.ui.search.IOccurrencesFinder.OccurrenceLocation;
import org.eclipse.cdt.internal.ui.search.IOccurrencesFinder;
import org.eclipse.cdt.internal.ui.search.OccurrencesFinder;
import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup;
import org.eclipse.cdt.internal.ui.text.CHeuristicScanner;
@ -3189,7 +3190,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
Position position= new Position(location.getOffset(), location.getLength());
String description= location.getDescription();
String annotationType= "org.eclipse.cdt.ui.occurrences"; //$NON-NLS-1$
String annotationType= (location.getFlags() == IOccurrencesFinder.F_WRITE_OCCURRENCE) ? "org.eclipse.cdt.ui.occurrences.write" : "org.eclipse.cdt.ui.occurrences"; //$NON-NLS-1$ //$NON-NLS-2$
annotationMap.put(new Annotation(annotationType, false, description), position);
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2003, 2009 IBM Corporation and others.
* Copyright (c) 2003, 2010 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
@ -84,6 +84,7 @@ public final class CSearchMessages extends NLS {
public static String OccurrencesFinder_label_singular;
public static String OccurrencesFinder_label_plural;
public static String OccurrencesFinder_occurrence_description;
public static String OccurrencesFinder_occurrence_write_description;
public static String PDOMSearchListContentProvider_IndexerNotEnabledMessageFormat;
public static String PDOMSearchListContentProvider_ProjectClosedMessageFormat;

View file

@ -107,3 +107,4 @@ OccurrencesFinder_label_singular=''{0}'' - 1 occurrence in ''{1}''
# The first argument will be replaced by the element name, the second by the count and the last by the file name
OccurrencesFinder_label_plural=''{0}'' - {1} occurrences in ''{2}''
OccurrencesFinder_occurrence_description=Occurrence of ''{0}''
OccurrencesFinder_occurrence_write_description=Write Occurrence of ''{0}''

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2008 IBM Corporation and others.
* Copyright (c) 2000, 2010 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
@ -18,6 +18,9 @@ public interface IOccurrencesFinder {
public static final int K_OCCURRENCE= 5;
public static final int F_WRITE_OCCURRENCE= 1;
public static final int F_READ_OCCURRENCE= 2;
/**
* Element representing an occurrence
*/

View file

@ -19,12 +19,17 @@ 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.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;
@ -42,7 +47,9 @@ public class OccurrencesFinder implements IOccurrencesFinder {
private IBinding fTarget;
private List<OccurrenceLocation> fResult;
private String fDescription;
private String fReadDescription;
private String fWriteDescription;
private int fOptions;
@ -59,7 +66,8 @@ public class OccurrencesFinder implements IOccurrencesFinder {
if (fTarget == null)
return CSearchMessages.OccurrencesFinder_no_binding;
fDescription= Messages.format(CSearchMessages.OccurrencesFinder_occurrence_description, fTarget.getName());
fReadDescription= Messages.format(CSearchMessages.OccurrencesFinder_occurrence_description, fTarget.getName());
fWriteDescription= Messages.format(CSearchMessages.OccurrencesFinder_occurrence_write_description, fTarget.getName());
return null;
}
@ -154,8 +162,6 @@ public class OccurrencesFinder implements IOccurrencesFinder {
private boolean addUsage(IASTName node, IBinding binding) {
if (binding != null /* && Bindings.equals(binding, fTarget) */) {
int flag= 0;
String description= fDescription;
if (node instanceof ICPPASTTemplateId) {
node= ((ICPPASTTemplateId) node).getTemplateName();
}
@ -167,7 +173,21 @@ public class OccurrencesFinder implements IOccurrencesFinder {
final int offset= fileLocation.getNodeOffset();
final int length= fileLocation.getNodeLength();
if (offset >= 0 && length > 0) {
fResult.add(new OccurrenceLocation(offset, length, flag, description));
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;
fResult.add(new OccurrenceLocation(offset, length, flag, description));
}
else {
fResult.add(new OccurrenceLocation(offset, length, F_READ_OCCURRENCE, fWriteDescription));
}
}
}
return true;