From 5b762b9f6be06cfdd58fb94bcd0d27dab3f846e2 Mon Sep 17 00:00:00 2001 From: Andrew Ferguson Date: Fri, 26 Oct 2007 10:41:25 +0000 Subject: [PATCH] 207320: apply fix and add regression tests --- .../tests/IndexCPPBindingResolutionBugs.java | 26 +++++++++++++ .../CPPSelectionTestsAnyIndexer.java | 37 ++++++++++++++++++- .../actions/OpenDeclarationsAction.java | 11 +++++- 3 files changed, 70 insertions(+), 4 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java index bab75a8dff4..d56d3d89b12 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java @@ -27,10 +27,12 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; 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.ICPPField; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; 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.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.index.IIndexBinding; @@ -63,6 +65,30 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas setStrategy(new SinglePDOMTestStrategy(true)); } + // template + // inline void testTemplate(T& aRef); + // + // class Temp { + // }; + + // #include + // #include + // #include "test.h" + // int main(void) { + // puts("Hello World!!!"); + // + // Temp testFile; + // testTemplate(testFile); + // + // return EXIT_SUCCESS; + // } + public void testBug207320() { + IBinding b0= getBindingFromASTName("testTemplate(", 12); + assertInstance(b0, ICPPFunction.class); + assertInstance(b0, ICPPTemplateInstance.class); + } + + // class testdef{ // // public: diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java index 0053447a138..7eebcafd318 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java @@ -132,6 +132,40 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde assertEquals(9, ((ASTNode)node).getLength()); } + // template + // inline void testTemplate(T& aRef); + // + // class Temp { + // }; + + // #include + // #include + // #include "test.h" + // int main(void) { + // puts("Hello World!!!"); + // + // Temp testFile; + // testTemplate(testFile); + // + // return EXIT_SUCCESS; + // } + public void testBug207320() throws Exception { + StringBuffer[] buffers= getContents(2); + String hcode= buffers[0].toString(); + String scode= buffers[1].toString(); + IFile hfile = importFile("test.h", hcode); + IFile file = importFile("test.cpp", scode); + TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + + int hoffset= hcode.indexOf("testTemplate"); + int soffset = scode.indexOf("testTemplate"); + IASTNode def = testF3(file, soffset+2); + assertTrue(def instanceof IASTName); + assertEquals(((IASTName)def).toString(), "testTemplate"); //$NON-NLS-1$ + assertEquals(((ASTNode)def).getOffset(), hoffset); + assertEquals(((ASTNode)def).getLength(), 12); + } + // // the header // extern int MyInt; // MyInt is in another file // extern const int MyConst; // MyConst is in another file @@ -227,7 +261,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde // #include "testBasicTemplateInstance.h" // N::AAA a; - public void _testBasicTemplateInstance() throws Exception{ + public void testBasicTemplateInstance_207320() throws Exception{ StringBuffer[] buffers= getContents(2); String hcode= buffers[0].toString(); String scode= buffers[1].toString(); @@ -235,7 +269,6 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde IFile file = importFile("testBasicTemplateInstance.cpp", scode); TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); - int hoffset= hcode.indexOf("AAA"); int soffset = scode.indexOf("AAA"); //$NON-NLS-1$ IASTNode decl1 = testF3(file, soffset, 3); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java index 18665de3981..13467b81460 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java @@ -39,6 +39,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndexManager; import org.eclipse.cdt.core.index.IIndexName; @@ -130,8 +131,14 @@ public class OpenDeclarationsAction extends SelectionParseAction { if (binding != null && !(binding instanceof IProblemBinding)) { IName[] declNames = findNames(fIndex, ast, isDefinition, binding); if (declNames.length == 0) { - // bug 86829, handle implicit methods. - if (binding instanceof ICPPMethod) { + if(binding instanceof ICPPTemplateInstance) { + // bug 207320, handle template instances + IBinding definition= ((ICPPTemplateInstance)binding).getTemplateDefinition(); + if(definition != null && !(definition instanceof IProblemBinding)) { + declNames = findNames(fIndex, ast, true, definition); + } + } else if (binding instanceof ICPPMethod) { + // bug 86829, handle implicit methods. ICPPMethod method= (ICPPMethod) binding; if (method.isImplicit()) { try {