Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2018-03-24 01:33:36 +0000
committerNathan Ridge2018-04-08 05:17:06 +0000
commit91a142fcb71d924425168cd31e268700abbf9eb1 (patch)
tree9a7e05d5adc3c4e3606a0d433bb86958b97d106f /core/org.eclipse.cdt.ui/src/org/eclipse/cdt
parent54287859f062ed48c22891f9cf10f740dcaf235f (diff)
downloadorg.eclipse.cdt-91a142fcb71d924425168cd31e268700abbf9eb1.tar.gz
org.eclipse.cdt-91a142fcb71d924425168cd31e268700abbf9eb1.tar.xz
org.eclipse.cdt-91a142fcb71d924425168cd31e268700abbf9eb1.zip
Bug 319506 - Allow renaming class via constructor
Change-Id: I3c2f3e5337c7cdea4714732580806713aa28187b Signed-off-by: Ian Leslie <ian.leslie@lesliesoftware.com>
Diffstat (limited to 'core/org.eclipse.cdt.ui/src/org/eclipse/cdt')
-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
2 files changed, 37 insertions, 1 deletions
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