Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameRegressionTests.java43
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTypeTests.java52
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRefactoringArgument.java6
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameProcessor.java32
4 files changed, 89 insertions, 44 deletions
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameRegressionTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameRegressionTests.java
index 6cb95f53aba..86171d2c80d 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameRegressionTests.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameRegressionTests.java
@@ -228,27 +228,6 @@ public class RenameRegressionTests extends RenameTestBase {
assertChange(changes, file, contents.indexOf("method1();//res2"), 7, "ooga");
}
- public void testConstructor_26() throws Exception {
- StringWriter writer = new StringWriter();
- writer.write("class Boo{ \n");
- writer.write(" Boo(){}//vp1,res1 \n");
- writer.write("}; \n");
- writer.write("void f() { \n");
- writer.write(" Boo a = new Boo(); \n");
- writer.write("} \n");
-
- String contents = writer.toString();
- IFile file = importFile("t.cpp", contents);
- int offset = contents.indexOf("Boo(){}") ;
- try {
- getRefactorChanges(file, offset, "ooga");
- } catch (AssertionFailedError e) {
- assertTrue(e.getMessage().startsWith("Input check on ooga failed."));
- return;
- }
- fail ("An error should have occurred in the input check.");
- }
-
// The constructor name is accepted, but the refactoring doesn't remove the return
// type and there is a compile error. Renaming to a constructor should be disabled.
// However, the UI does display the error in the preview panel. Defect 78769 states
@@ -277,28 +256,6 @@ public class RenameRegressionTests extends RenameTestBase {
fail ("An error should have occurred in the input check.");
}
- public void testDestructor_28() throws Exception {
- StringWriter writer = new StringWriter();
- writer.write("class Boo{ \n");
- writer.write(" ~Boo(){}//vp1 \n");
- writer.write("}; \n");
- writer.write("void f() { \n");
- writer.write(" Boo a ; \n");
- writer.write(" a.~Boo(); \n");
- writer.write("} \n");
-
- String contents = writer.toString();
- IFile file = importFile("t.cpp", contents);
- int offset = contents.indexOf("~Boo(){}") ;
- try {
- getRefactorChanges(file, offset, "ooga");
- } catch (AssertionFailedError e) {
- assertTrue(e.getMessage().startsWith("Input check on ooga failed."));
- return;
- }
- fail ("An error should have occurred in the input check.");
- }
-
public void testDestructor_29_72612() throws Exception {
StringWriter writer = new StringWriter();
writer.write("class Boo{ \n");
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTypeTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTypeTests.java
index 87b88665009..89c46307947 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTypeTests.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTypeTests.java
@@ -2277,6 +2277,58 @@ public class RenameTypeTests extends RenameTestBase {
assertTotalChanges(countOccurrences(contents, "String"), ch);
}
+ public void testRenameClassFromCtor() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write("class String \n"); //$NON-NLS-1$
+ writer.write("{ \n"); //$NON-NLS-1$
+ writer.write("public: \n"); //$NON-NLS-1$
+ writer.write(" String(); \n"); //$NON-NLS-1$
+ writer.write(" String(const String &other); \n"); //$NON-NLS-1$
+ writer.write(" ~String(); \n"); //$NON-NLS-1$
+ writer.write(" String &operator=(const String &other); \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write(" String::String() {} \n"); //$NON-NLS-1$
+ writer.write(" String::String(const String &other) {}; \n"); //$NON-NLS-1$
+ writer.write(" String::~String() {}; \n"); //$NON-NLS-1$
+ writer.write(" String& String::operator=(const String &other) \n"); //$NON-NLS-1$
+ writer.write(" {return *this;} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$
+
+ int offset= contents.indexOf("String()"); //$NON-NLS-1$
+
+ RefactoringStatus status= checkConditions(cpp, offset, "CString"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ Change ch= getRefactorChanges(cpp, offset, "CString"); //$NON-NLS-1$
+ assertTotalChanges(countOccurrences(contents, "String"), ch); //$NON-NLS-1$
+ }
+
+ public void testRenameClassFromDtor() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write("class String \n"); //$NON-NLS-1$
+ writer.write("{ \n"); //$NON-NLS-1$
+ writer.write("public: \n"); //$NON-NLS-1$
+ writer.write(" String(); \n"); //$NON-NLS-1$
+ writer.write(" String(const String &other); \n"); //$NON-NLS-1$
+ writer.write(" ~String(); \n"); //$NON-NLS-1$
+ writer.write(" String &operator=(const String &other); \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write(" String::String() {} \n"); //$NON-NLS-1$
+ writer.write(" String::String(const String &other) {}; \n"); //$NON-NLS-1$
+ writer.write(" String::~String() {}; \n"); //$NON-NLS-1$
+ writer.write(" String& String::operator=(const String &other) \n"); //$NON-NLS-1$
+ writer.write(" {return *this;} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$
+
+ int offset= contents.indexOf("~String") + 1; //$NON-NLS-1$
+
+ RefactoringStatus status= checkConditions(cpp, offset, "CString"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ Change ch= getRefactorChanges(cpp, offset, "CString"); //$NON-NLS-1$
+ assertTotalChanges(countOccurrences(contents, "String"), ch); //$NON-NLS-1$
+ }
+
public void testUsingDeclaration_332895() throws Exception {
StringWriter writer = new StringWriter();
writer.write("namespace ns { \n");
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRefactoringArgument.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRefactoringArgument.java
index c56fad98f28..9862d4bc6a6 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRefactoringArgument.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRefactoringArgument.java
@@ -94,10 +94,14 @@ public class CRefactoringArgument {
return fLength;
}
- public void setName(IASTName name) {
+ public void setName(String name) {
fText= name.toString();
}
+ public void setName(IASTName name) {
+ setName(name.toString());
+ }
+
public void setBinding(IASTTranslationUnit tu, IBinding binding, IScope scope) {
fTranslationUnit= tu;
fBinding= binding;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameProcessor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameProcessor.java
index 884a6983434..518c61cbc7e 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameProcessor.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameProcessor.java
@@ -30,10 +30,17 @@ import org.eclipse.ui.PlatformUI;
import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CProjectNature;
+import org.eclipse.cdt.core.dom.ast.DOMException;
+import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.IScope;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.ui.CUIPlugin;
/**
* This is the processor used for the rename. It decides which of the delegates to
@@ -120,6 +127,8 @@ public class CRenameProcessor extends RenameProcessor {
if (path == null) {
return RefactoringStatus.createFatalErrorStatus(RenameMessages.CRenameTopProcessor_error_renameWithoutSourceFile);
}
+
+ updateBinding();
fDelegate= createDelegate();
if (fDelegate == null) {
@@ -131,6 +140,29 @@ public class CRenameProcessor extends RenameProcessor {
return fInitialConditionsStatus;
}
+ /**
+ * Change the binding for the renaming of constructors and destructor to the class.
+ */
+ private void updateBinding() {
+ IBinding binding= fArgument.getBinding();
+ if (binding instanceof ICPPConstructor ||
+ (binding instanceof ICPPMethod && ((ICPPMethod) binding).isDestructor())) {
+ // Switch binding to class level when constructor or destructor selected
+ IBinding newBinding = ((ICPPMember) binding).getClassOwner();
+ IScope scope = fArgument.getScope();
+ try {
+ scope = newBinding.getScope();
+ } catch (DOMException e) {
+ CUIPlugin.log(e);
+ }
+ fArgument.setBinding(fArgument.getTranslationUnit(), newBinding, scope);
+
+ if (fArgument.getName().startsWith("~")) { //$NON-NLS-1$
+ fArgument.setName(newBinding.getName());
+ }
+ }
+ }
+
private CRenameProcessorDelegate createDelegate() {
switch (fArgument.getArgumentKind()) {
case CRefactory.ARGUMENT_LOCAL_VAR:

Back to the top