mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 09:25:31 +02:00
Bug 303870 - Fix for base template classes
Methods weren't added if the virtual methods were in a base template class. Change-Id: I34b05eeb1e7dc5ce83944a642461eca521764967 Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
This commit is contained in:
parent
188d84eea5
commit
353315f84a
2 changed files with 56 additions and 4 deletions
|
@ -270,6 +270,43 @@ public class OverrideMethodsRefactoringTest extends RefactoringTestBase {
|
|||
assertRefactoringSuccess();
|
||||
}
|
||||
|
||||
//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:
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue