Skip to main content
summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMarc-Andre Laperle2018-09-21 23:44:23 -0400
committerMarc-André Laperle2018-09-26 19:24:36 -0400
commit70a03a862e263385e253d11699859d1c5dab7895 (patch)
tree362c860beb7496e3460adc4cc60102739954c973 /core
parentc6abbfb6d31f673c7238a1d5a504d515031083ae (diff)
downloadorg.eclipse.cdt-70a03a862e263385e253d11699859d1c5dab7895.tar.gz
org.eclipse.cdt-70a03a862e263385e253d11699859d1c5dab7895.tar.xz
org.eclipse.cdt-70a03a862e263385e253d11699859d1c5dab7895.zip
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>
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java6
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java28
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/togglefunction/ToggleRefactoringTest.java59
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleNodeHelper.java6
4 files changed, 92 insertions, 7 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java
index f167de1837..b7d34d8ee4 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java
@@ -213,6 +213,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.
*/
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java
index 0aa2b78e94..7c4fd31fa2 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java
@@ -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);
+ }
+ }
}
}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/togglefunction/ToggleRefactoringTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/togglefunction/ToggleRefactoringTest.java
index f16f3c9e9d..4f6774f961 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/togglefunction/ToggleRefactoringTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/togglefunction/ToggleRefactoringTest.java
@@ -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();
+ }
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleNodeHelper.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleNodeHelper.java
index a3d3855a1e..afbbb9bc27 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleNodeHelper.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleNodeHelper.java
@@ -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;
}

Back to the top