1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 09:25:31 +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:
Marc-Andre Laperle 2018-09-21 23:44:23 -04:00 committed by Marc-André Laperle
parent c6abbfb6d3
commit 70a03a862e
4 changed files with 92 additions and 7 deletions

View file

@ -212,6 +212,12 @@ public interface ICPPASTFunctionDeclarator extends IASTStandardFunctionDeclarato
*/
public void addVirtSpecifier(ICPPASTVirtSpecifier virtSpecifier);
/**
* Set virt-specifiers of this function.
* @since 6.6
*/
public void setVirtSpecifiers(ICPPASTVirtSpecifier[] newVirtSpecifiers);
/**
* @deprecated Not used.
* @noreference This field is not intended to be referenced by clients.

View file

@ -362,12 +362,26 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS
@Override
public void addVirtSpecifier(ICPPASTVirtSpecifier virtSpecifier) {
assertNotFrozen();
if (virtSpecifier != null) {
assert virtSpecifiers != null;
virtSpecifiers = ArrayUtil.append(virtSpecifiers, virtSpecifier);
virtSpecifier.setParent(this);
virtSpecifier.setPropertyInParent(EXCEPTION_TYPEID);
}
assertNotFrozen();
if (virtSpecifier != null) {
assert virtSpecifiers != null;
virtSpecifiers = ArrayUtil.append(virtSpecifiers, virtSpecifier);
virtSpecifier.setParent(this);
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);
}
}
}
}

View file

@ -3568,4 +3568,63 @@ public class ToggleRefactoringTest extends RefactoringTestBase {
public void testFreeFunctionFromHeaderToImplInC_531701() 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;
//};
//
//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();
}
}

View file

@ -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.ICPPASTDeclSpecifier;
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.ICPPASTFunctionWithTryBlock;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTName;
@ -144,6 +145,11 @@ public class ToggleNodeHelper extends NodeHelper {
ICPPASTFunctionDefinition newFunction =
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;
}