mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-21 21:52:10 +02:00
Bug 562292 - Fix method definition position for override method
The position of namespaces didn't take into account because the
declaration doesn't exist yet when we use this kind of refactoring,
so the find method of MethodDefinitionInsertLocationFinder didn't
look for namespaces.
Change-Id: I839194879c41f86653c837ca83a306ea1840c1d0
(cherry picked from commit d36ed7cfd5
)
This commit is contained in:
parent
21d68daf5d
commit
df7c89b876
3 changed files with 80 additions and 4 deletions
|
@ -672,4 +672,66 @@ public class OverrideMethodsRefactoringTest extends RefactoringTestBase {
|
|||
selectedMethods = new String[] { "baseFunc()const" };
|
||||
assertRefactoringSuccess();
|
||||
}
|
||||
|
||||
//A.h
|
||||
//namespace Bar {
|
||||
//namespace Foo {
|
||||
//namespace Baz {
|
||||
//class Base {
|
||||
//public:
|
||||
// virtual ~Base();
|
||||
// virtual void baseFunc() const = 0;
|
||||
//};
|
||||
//class X: public Base {
|
||||
//public:
|
||||
// X();
|
||||
// /*$*//*$$*/
|
||||
//};
|
||||
//}
|
||||
//}
|
||||
//}
|
||||
//====================
|
||||
//namespace Bar {
|
||||
//namespace Foo {
|
||||
//namespace Baz {
|
||||
//class Base {
|
||||
//public:
|
||||
// virtual ~Base();
|
||||
// virtual void baseFunc() const = 0;
|
||||
//};
|
||||
//class X: public Base {
|
||||
//public:
|
||||
// X();
|
||||
// virtual void baseFunc() const;
|
||||
//};
|
||||
//}
|
||||
//}
|
||||
//}
|
||||
|
||||
//A.cpp
|
||||
//#include "A.h"
|
||||
//
|
||||
//namespace Bar {
|
||||
//namespace Foo {
|
||||
//namespace Baz {
|
||||
//}
|
||||
//}
|
||||
//}
|
||||
//====================
|
||||
//#include "A.h"
|
||||
//
|
||||
//namespace Bar {
|
||||
//namespace Foo {
|
||||
//namespace Baz {
|
||||
//
|
||||
//void X::baseFunc() const {
|
||||
//}
|
||||
//
|
||||
//}
|
||||
//}
|
||||
//}
|
||||
public void testWithHeaderAndSource_Bug562292() throws Exception {
|
||||
selectedMethods = new String[] { "baseFunc()const" };
|
||||
assertRefactoringSuccess();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -229,7 +229,7 @@ public class ImplementMethodRefactoring extends CRefactoring {
|
|||
throw new OperationCanceledException();
|
||||
}
|
||||
IASTSimpleDeclaration decl = config.getDeclaration();
|
||||
InsertLocation insertLocation = findInsertLocation(decl, subMonitor);
|
||||
InsertLocation insertLocation = findInsertLocation(decl, subMonitor, functionOffset);
|
||||
if (subMonitor.isCanceled()) {
|
||||
throw new OperationCanceledException();
|
||||
}
|
||||
|
@ -277,11 +277,17 @@ public class ImplementMethodRefactoring extends CRefactoring {
|
|||
|
||||
private InsertLocation findInsertLocation(IASTSimpleDeclaration methodDeclaration, IProgressMonitor subMonitor)
|
||||
throws CoreException {
|
||||
return findInsertLocation(methodDeclaration, subMonitor, -1);
|
||||
}
|
||||
|
||||
private InsertLocation findInsertLocation(IASTSimpleDeclaration methodDeclaration, IProgressMonitor subMonitor,
|
||||
int functionOffset) throws CoreException {
|
||||
if (insertLocations.containsKey(methodDeclaration)) {
|
||||
return insertLocations.get(methodDeclaration);
|
||||
}
|
||||
InsertLocation insertLocation = methodDefinitionInsertLocationFinder.find(tu,
|
||||
methodDeclaration.getFileLocation(), methodDeclaration.getParent(), refactoringContext, subMonitor);
|
||||
methodDeclaration.getFileLocation(), methodDeclaration.getParent(), refactoringContext, subMonitor,
|
||||
functionOffset);
|
||||
|
||||
if (insertLocation.getTranslationUnit() == null
|
||||
|| NodeHelper.isContainedInTemplateDeclaration(methodDeclaration)) {
|
||||
|
|
|
@ -63,6 +63,12 @@ public class MethodDefinitionInsertLocationFinder {
|
|||
|
||||
public InsertLocation find(ITranslationUnit declarationTu, IASTFileLocation methodDeclarationLocation,
|
||||
IASTNode parent, CRefactoringContext refactoringContext, IProgressMonitor pm) throws CoreException {
|
||||
return find(declarationTu, methodDeclarationLocation, parent, refactoringContext, pm, -1);
|
||||
}
|
||||
|
||||
public InsertLocation find(ITranslationUnit declarationTu, IASTFileLocation methodDeclarationLocation,
|
||||
IASTNode parent, CRefactoringContext refactoringContext, IProgressMonitor pm, int functionOffset)
|
||||
throws CoreException {
|
||||
IASTDeclaration[] declarations = NodeHelper.getDeclarations(parent);
|
||||
InsertLocation insertLocation = new InsertLocation();
|
||||
|
||||
|
@ -120,12 +126,14 @@ public class MethodDefinitionInsertLocationFinder {
|
|||
ITranslationUnit partner = SourceHeaderPartnerFinder.getPartnerTranslationUnit(declarationTu,
|
||||
refactoringContext);
|
||||
if (partner != null) {
|
||||
if (methodDeclarationLocation == null) {
|
||||
if (methodDeclarationLocation == null && functionOffset < 0) {
|
||||
insertLocation.setParentNode(refactoringContext.getAST(partner, null), partner);
|
||||
return insertLocation;
|
||||
}
|
||||
final ICPPASTName[] names = NamespaceHelper.getSurroundingNamespace(declarationTu,
|
||||
methodDeclarationLocation.getNodeOffset(), refactoringContext);
|
||||
methodDeclarationLocation != null ? methodDeclarationLocation.getNodeOffset()
|
||||
: functionOffset,
|
||||
refactoringContext);
|
||||
IASTTranslationUnit ast = refactoringContext.getAST(partner, null);
|
||||
IASTNode[] target = new IASTNode[1];
|
||||
if (ast != null) {
|
||||
|
|
Loading…
Add table
Reference in a new issue