mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-08 19:13:27 +02:00
Bug 518273 - Toggle function should remove the override keyword when moving out of class
Change-Id: I7ad80262c7f9b98d3ae9b23ae2b45bf0c94ccf99 Signed-off-by: Marc-Andre Laperle <malaperle@gmail.com>
This commit is contained in:
parent
c6abbfb6d3
commit
70a03a862e
4 changed files with 92 additions and 7 deletions
|
@ -212,6 +212,12 @@ public interface ICPPASTFunctionDeclarator extends IASTStandardFunctionDeclarato
|
||||||
*/
|
*/
|
||||||
public void addVirtSpecifier(ICPPASTVirtSpecifier virtSpecifier);
|
public void addVirtSpecifier(ICPPASTVirtSpecifier virtSpecifier);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set virt-specifiers of this function.
|
||||||
|
* @since 6.6
|
||||||
|
*/
|
||||||
|
public void setVirtSpecifiers(ICPPASTVirtSpecifier[] newVirtSpecifiers);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Not used.
|
* @deprecated Not used.
|
||||||
* @noreference This field is not intended to be referenced by clients.
|
* @noreference This field is not intended to be referenced by clients.
|
||||||
|
|
|
@ -367,7 +367,21 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS
|
||||||
assert virtSpecifiers != null;
|
assert virtSpecifiers != null;
|
||||||
virtSpecifiers = ArrayUtil.append(virtSpecifiers, virtSpecifier);
|
virtSpecifiers = ArrayUtil.append(virtSpecifiers, virtSpecifier);
|
||||||
virtSpecifier.setParent(this);
|
virtSpecifier.setParent(this);
|
||||||
virtSpecifier.setPropertyInParent(EXCEPTION_TYPEID);
|
virtSpecifier.setPropertyInParent(VIRT_SPECIFIER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setVirtSpecifiers(ICPPASTVirtSpecifier[] newVirtSpecifiers) {
|
||||||
|
assertNotFrozen();
|
||||||
|
if (newVirtSpecifiers == null) {
|
||||||
|
virtSpecifiers = NO_VIRT_SPECIFIERS;
|
||||||
|
} else {
|
||||||
|
virtSpecifiers = newVirtSpecifiers;
|
||||||
|
for (ICPPASTVirtSpecifier virtSpecifier : newVirtSpecifiers) {
|
||||||
|
virtSpecifier.setParent(this);
|
||||||
|
virtSpecifier.setPropertyInParent(VIRT_SPECIFIER);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3568,4 +3568,63 @@ public class ToggleRefactoringTest extends RefactoringTestBase {
|
||||||
public void testFreeFunctionFromHeaderToImplInC_531701() throws Exception {
|
public void testFreeFunctionFromHeaderToImplInC_531701() throws Exception {
|
||||||
assertRefactoringSuccess();
|
assertRefactoringSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Test.h
|
||||||
|
//class Base {
|
||||||
|
// virtual void foo() {
|
||||||
|
// }
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//class Foo : public Base {
|
||||||
|
// void /*$*/foo/*$$*/() override final
|
||||||
|
// {
|
||||||
|
// }
|
||||||
|
//};
|
||||||
|
//====================
|
||||||
|
//class Base {
|
||||||
|
// virtual void foo() {
|
||||||
|
// }
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//class Foo : public Base {
|
||||||
|
// void foo() override final;
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//inline void Foo::foo() {
|
||||||
|
//}
|
||||||
|
public void testToggleWithVirtSpecifiers_518273() throws Exception {
|
||||||
|
assertRefactoringSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Test.h
|
||||||
|
//class Base {
|
||||||
|
// virtual void foo() {
|
||||||
|
// }
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//class Foo : public Base {
|
||||||
|
// void foo() override final;
|
||||||
|
//};
|
||||||
|
//====================
|
||||||
|
//class Base {
|
||||||
|
// virtual void foo() {
|
||||||
|
// }
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//class Foo : public Base {
|
||||||
|
// void foo() override final
|
||||||
|
// {
|
||||||
|
// }
|
||||||
|
//};
|
||||||
|
|
||||||
|
//Test.cpp
|
||||||
|
//#include "Test.h"
|
||||||
|
//
|
||||||
|
//void Foo::/*$*/foo/*$$*/() {
|
||||||
|
//}
|
||||||
|
//====================
|
||||||
|
//#include "Test.h"
|
||||||
|
public void testToggleWithVirtSpecifiersImplementationToClass_518273() throws Exception {
|
||||||
|
assertRefactoringSuccess();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclarator;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclarator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionWithTryBlock;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionWithTryBlock;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTName;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTName;
|
||||||
|
@ -144,6 +145,11 @@ public class ToggleNodeHelper extends NodeHelper {
|
||||||
|
|
||||||
ICPPASTFunctionDefinition newFunction =
|
ICPPASTFunctionDefinition newFunction =
|
||||||
createFunctionSignatureWithEmptyBody(newDeclSpecifier, newDeclarator, oldDefinition);
|
createFunctionSignatureWithEmptyBody(newDeclSpecifier, newDeclarator, oldDefinition);
|
||||||
|
// Virt-specifiers are only valid in the class declaration.
|
||||||
|
if (newFunction.getDeclarator() instanceof ICPPASTFunctionDeclarator) {
|
||||||
|
ICPPASTFunctionDeclarator functionDeclarator = (ICPPASTFunctionDeclarator) newFunction.getDeclarator();
|
||||||
|
functionDeclarator.setVirtSpecifiers(null);
|
||||||
|
}
|
||||||
|
|
||||||
return newFunction;
|
return newFunction;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue