mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-08 19:13:27 +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();
|
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
|
//A.h
|
||||||
//class Base {
|
//class Base {
|
||||||
//public:
|
//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.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
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.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.IIndex;
|
||||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||||
import org.eclipse.cdt.core.index.IIndexFile;
|
import org.eclipse.cdt.core.index.IIndexFile;
|
||||||
|
@ -254,9 +256,22 @@ public class DefinitionFinder {
|
||||||
*/
|
*/
|
||||||
public static IASTName getMemberDeclaration(ICPPMember member, IASTTranslationUnit contextTu,
|
public static IASTName getMemberDeclaration(ICPPMember member, IASTTranslationUnit contextTu,
|
||||||
CRefactoringContext context, IProgressMonitor pm) throws CoreException, OperationCanceledException {
|
CRefactoringContext context, IProgressMonitor pm) throws CoreException, OperationCanceledException {
|
||||||
IASTName classDefintionName = getDefinition(member.getClassOwner(), contextTu, context, pm);
|
IBinding classBinding = member.getClassOwner();
|
||||||
if (classDefintionName == null)
|
IBinding memberBinding = member;
|
||||||
return null;
|
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 compositeTypeSpecifier = ASTQueries.findAncestorWithType(classDefintionName,
|
||||||
IASTCompositeTypeSpecifier.class);
|
IASTCompositeTypeSpecifier.class);
|
||||||
IASTTranslationUnit ast = classDefintionName.getTranslationUnit();
|
IASTTranslationUnit ast = classDefintionName.getTranslationUnit();
|
||||||
|
@ -264,7 +279,7 @@ public class DefinitionFinder {
|
||||||
if (index == null) {
|
if (index == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
IASTName[] memberDeclarationNames = ast.getDeclarationsInAST(index.adaptBinding(member));
|
IASTName[] memberDeclarationNames = ast.getDeclarationsInAST(index.adaptBinding(memberBinding));
|
||||||
for (IASTName name : memberDeclarationNames) {
|
for (IASTName name : memberDeclarationNames) {
|
||||||
if (name.getPropertyInParent() == IASTDeclarator.DECLARATOR_NAME) {
|
if (name.getPropertyInParent() == IASTDeclarator.DECLARATOR_NAME) {
|
||||||
IASTDeclaration declaration = ASTQueries.findAncestorWithType(name, IASTDeclaration.class);
|
IASTDeclaration declaration = ASTQueries.findAncestorWithType(name, IASTDeclaration.class);
|
||||||
|
|
Loading…
Add table
Reference in a new issue