Skip to main content
summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rwxr-xr-xcore/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/overridemethods/OverrideMethodsRefactoringTest.java37
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/DefinitionFinder.java23
2 files changed, 56 insertions, 4 deletions
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/overridemethods/OverrideMethodsRefactoringTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/overridemethods/OverrideMethodsRefactoringTest.java
index 87d564f125..7002675e29 100755
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/overridemethods/OverrideMethodsRefactoringTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/overridemethods/OverrideMethodsRefactoringTest.java
@@ -271,6 +271,43 @@ public class OverrideMethodsRefactoringTest extends RefactoringTestBase {
}
//A.h
+ //template<class T>
+ //class Base {
+ //public:
+ // virtual ~Base();
+ // virtual void baseFunc(T *t) const = 0;
+ //};
+ //class X: public Base<int> {
+ //public:
+ // X();
+ // /*$*//*$$*/
+ //};
+ //====================
+ //template<class T>
+ //class Base {
+ //public:
+ // virtual ~Base();
+ // virtual void baseFunc(T *t) const = 0;
+ //};
+ //class X: public Base<int> {
+ //public:
+ // X();
+ // virtual void baseFunc(int *t) const;
+ //};
+
+ //A.cpp
+ //#include "A.h"
+ //====================
+ //#include "A.h"
+ //
+ //void X::baseFunc(int *t) const {
+ //}
+ public void testWithTemplateBaseClass() throws Exception {
+ selectedMethods = new String[] { "baseFunc(int *) {#0,0: int}" };
+ assertRefactoringSuccess();
+ }
+
+ //A.h
//class Base {
//public:
// virtual ~Base();
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/DefinitionFinder.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/DefinitionFinder.java
index 00564d1090..05d27a5f5b 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/DefinitionFinder.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/DefinitionFinder.java
@@ -25,6 +25,8 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFile;
@@ -254,9 +256,22 @@ public class DefinitionFinder {
*/
public static IASTName getMemberDeclaration(ICPPMember member, IASTTranslationUnit contextTu,
CRefactoringContext context, IProgressMonitor pm) throws CoreException, OperationCanceledException {
- IASTName classDefintionName = getDefinition(member.getClassOwner(), contextTu, context, pm);
- if (classDefintionName == null)
- return null;
+ IBinding classBinding = member.getClassOwner();
+ IBinding memberBinding = member;
+ if (member instanceof ICPPSpecialization)
+ memberBinding = ((ICPPSpecialization) member).getSpecializedBinding();
+ IASTName classDefintionName = getDefinition(classBinding, contextTu, context, pm);
+ if (classDefintionName == null) {
+ /*
+ * We didn't find the class definition, check again the template definition then
+ * it was a template instance.
+ */
+ if (classBinding instanceof ICPPTemplateInstance)
+ classBinding = ((ICPPTemplateInstance) classBinding).getTemplateDefinition();
+ classDefintionName = getDefinition(classBinding, contextTu, context, pm);
+ if (classDefintionName == null)
+ return null;
+ }
IASTCompositeTypeSpecifier compositeTypeSpecifier = ASTQueries.findAncestorWithType(classDefintionName,
IASTCompositeTypeSpecifier.class);
IASTTranslationUnit ast = classDefintionName.getTranslationUnit();
@@ -264,7 +279,7 @@ public class DefinitionFinder {
if (index == null) {
return null;
}
- IASTName[] memberDeclarationNames = ast.getDeclarationsInAST(index.adaptBinding(member));
+ IASTName[] memberDeclarationNames = ast.getDeclarationsInAST(index.adaptBinding(memberBinding));
for (IASTName name : memberDeclarationNames) {
if (name.getPropertyInParent() == IASTDeclarator.DECLARATOR_NAME) {
IASTDeclaration declaration = ASTQueries.findAncestorWithType(name, IASTDeclaration.class);

Back to the top