From 952046381e98720cfb40bbd0542cfbfee025dee2 Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Thu, 31 Jan 2008 14:50:16 +0000 Subject: [PATCH] Fix mark occurrences for template specializations --- .../core/dom/parser/cpp/CPPVisitor.java | 9 ++--- .../resources/ceditor/occurrences.cpp | 4 +- .../cdt/ui/tests/text/MarkOccurrenceTest.java | 40 +++++++++++++++++++ 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java index 736bcde0c9d..be4f31704a4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java @@ -119,7 +119,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPDeferredTemplateInstance; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionScope; @@ -1296,8 +1295,8 @@ public class CPPVisitor { public CollectReferencesAction( IBinding binding ){ - if (binding instanceof ICPPDeferredTemplateInstance) { - binding= ((ICPPDeferredTemplateInstance) binding).getSpecializedBinding(); + if (binding instanceof ICPPSpecialization) { + binding= ((ICPPSpecialization) binding).getSpecializedBinding(); } this.binding = binding; this.refs = new IASTName[ DEFAULT_LIST_SIZE ]; @@ -1398,8 +1397,8 @@ public class CPPVisitor { candidate = null; else candidate = bs[ ++n ]; - } else if (potential instanceof ICPPDeferredTemplateInstance) { - candidate= ((ICPPDeferredTemplateInstance) potential).getSpecializedBinding(); + } else if (potential instanceof ICPPSpecialization) { + candidate= ((ICPPSpecialization) potential).getSpecializedBinding(); } else { candidate = potential; } diff --git a/core/org.eclipse.cdt.ui.tests/resources/ceditor/occurrences.cpp b/core/org.eclipse.cdt.ui.tests/resources/ceditor/occurrences.cpp index f7f808153ca..c3f7834b32d 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/ceditor/occurrences.cpp +++ b/core/org.eclipse.cdt.ui.tests/resources/ceditor/occurrences.cpp @@ -115,7 +115,7 @@ label: template class ConstantTemplate { public: - size_t foo(size_t y) { + size_t getNumber(size_t y) { return X; } }; @@ -123,3 +123,5 @@ public: ConstantTemplate<5> c5; ConstantTemplate<5> c52; ConstantTemplate<4> c4; + +const int c= c5.getNumber(0); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/MarkOccurrenceTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/MarkOccurrenceTest.java index 61f4892fb0b..516cc7e2d32 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/MarkOccurrenceTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/MarkOccurrenceTest.java @@ -308,6 +308,19 @@ public class MarkOccurrenceTest extends BaseUITestCase { assertOccurrences(2); assertOccurrencesInWidget(); } + public void testMarkMethodOccurrences2() { + try { + fMatch= fFindReplaceDocumentAdapter.find(0, "getNumber", true, true, true, false); + } catch (BadLocationException e) { + fail(); + } + assertNotNull(fMatch); + + fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength()); + + assertOccurrences(2); + assertOccurrencesInWidget(); + } public void testMarkFieldOccurrences() { try { fMatch= fFindReplaceDocumentAdapter.find(0, "pubField", true, true, true, false); @@ -321,6 +334,19 @@ public class MarkOccurrenceTest extends BaseUITestCase { assertOccurrences(2); assertOccurrencesInWidget(); } + public void testMarkFieldOccurrences2() { + try { + fMatch= fFindReplaceDocumentAdapter.find(0, "tArg1", true, true, true, false); + } catch (BadLocationException e) { + fail(); + } + assertNotNull(fMatch); + + fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength()); + + assertOccurrences(2); + assertOccurrencesInWidget(); + } public void testMarkConstructorOccurrences() { try { @@ -436,6 +462,20 @@ public class MarkOccurrenceTest extends BaseUITestCase { assertOccurrencesInWidget(); } + public void testMarkLabelOccurrences() { + try { + fMatch= fFindReplaceDocumentAdapter.find(0, "label", true, true, true, false); + } catch (BadLocationException e) { + fail(); + } + assertNotNull(fMatch); + + fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength()); + + assertOccurrences(2); + assertOccurrencesInWidget(); + } + public void testNoOccurrencesIfDisabled() { CUIPlugin.getDefault().getPreferenceStore().setValue(PreferenceConstants.EDITOR_MARK_OCCURRENCES, false); fOccurrences= Integer.MAX_VALUE;