Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2012-09-18 19:44:26 -0400
committerStephan Herrmann2012-09-18 19:44:26 -0400
commit3ff346ae69442fe57a4b12f9fe776b4c471695eb (patch)
tree14295c924472bfdcb6bfab1d83fecdd0215dc2b5
parenta41522640854ed503aa561e345848207cc597e79 (diff)
downloadorg.eclipse.objectteams-3ff346ae69442fe57a4b12f9fe776b4c471695eb.tar.gz
org.eclipse.objectteams-3ff346ae69442fe57a4b12f9fe776b4c471695eb.tar.xz
org.eclipse.objectteams-3ff346ae69442fe57a4b12f9fe776b4c471695eb.zip
Bug 389850 - [refactoring] change signature fails if role method is
bound in a signature-less callin
-rw-r--r--plugins/org.eclipse.objectteams.otdt.refactoring/src/org/eclipse/objectteams/otdt/internal/refactoring/RefactoringMessages.java1
-rw-r--r--plugins/org.eclipse.objectteams.otdt.refactoring/src/org/eclipse/objectteams/otdt/internal/refactoring/RefactoringMessages.properties1
-rw-r--r--plugins/org.eclipse.objectteams.otdt.refactoring/src/org/eclipse/objectteams/otdt/internal/refactoring/adaptor/ChangeSignatureAdaptor.java66
-rw-r--r--testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/misc/ChangeSignatureTests.java19
-rw-r--r--testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/ChangeSignature/canModify/A_testDelete03_in.java10
-rw-r--r--testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/ChangeSignature/canModify/A_testDelete03_out.java10
6 files changed, 86 insertions, 21 deletions
diff --git a/plugins/org.eclipse.objectteams.otdt.refactoring/src/org/eclipse/objectteams/otdt/internal/refactoring/RefactoringMessages.java b/plugins/org.eclipse.objectteams.otdt.refactoring/src/org/eclipse/objectteams/otdt/internal/refactoring/RefactoringMessages.java
index 4c7e00b22..9d3e978b9 100644
--- a/plugins/org.eclipse.objectteams.otdt.refactoring/src/org/eclipse/objectteams/otdt/internal/refactoring/RefactoringMessages.java
+++ b/plugins/org.eclipse.objectteams.otdt.refactoring/src/org/eclipse/objectteams/otdt/internal/refactoring/RefactoringMessages.java
@@ -11,6 +11,7 @@ public class RefactoringMessages extends NLS {
public static String ChangeSignatureAdaptor_cannotCreateParamMap_CTF_warning;
public static String ChangeSignatureAdaptor_cannotCreateParamMap_MultiCallin_warning;
public static String ChangeSignatureAdaptor_cannotUpdateParameterMapping_warning;
+ public static String ChangeSignatureAdaptor_singaturelessBindingIncomplete_info;
public static String ExtractInterfaceAdaptor_createAsRole_checkbox;
public static String ExtractInterfaceAdaptor_createInterface_changeName;
public static String MoveInstanceMethodAdaptor_ambiguousMethodSpec_error;
diff --git a/plugins/org.eclipse.objectteams.otdt.refactoring/src/org/eclipse/objectteams/otdt/internal/refactoring/RefactoringMessages.properties b/plugins/org.eclipse.objectteams.otdt.refactoring/src/org/eclipse/objectteams/otdt/internal/refactoring/RefactoringMessages.properties
index 41c7a93b9..b92f92699 100644
--- a/plugins/org.eclipse.objectteams.otdt.refactoring/src/org/eclipse/objectteams/otdt/internal/refactoring/RefactoringMessages.properties
+++ b/plugins/org.eclipse.objectteams.otdt.refactoring/src/org/eclipse/objectteams/otdt/internal/refactoring/RefactoringMessages.properties
@@ -5,6 +5,7 @@ ChangeSignatureAdaptor_calloutRoleArgDeleteIncomplete_info=Deleting arguments at
ChangeSignatureAdaptor_cannotCreateParamMap_CTF_warning=Need to create parameter mapping, which however is not yet implemented for callout-to-field
ChangeSignatureAdaptor_cannotCreateParamMap_MultiCallin_warning=Need to create parameter mapping, which however is not yet implemented for callin to multiple bases
ChangeSignatureAdaptor_cannotUpdateParameterMapping_warning=Cannot update existing parameter mapping
+ChangeSignatureAdaptor_singaturelessBindingIncomplete_info=Affected method binding has no signatures; consider adding signatures first so that the refactoring can absorb incompatible changes using parameter mappings
ExtractInterfaceAdaptor_createAsRole_checkbox=Create as role of the enclosing team
ExtractInterfaceAdaptor_createInterface_changeName=Create interface {0}
MoveInstanceMethodAdaptor_ambiguousMethodSpec_error=Refactoring cannot be performed\! There would be an ambiguous method specifier in a method binding after moving\!
diff --git a/plugins/org.eclipse.objectteams.otdt.refactoring/src/org/eclipse/objectteams/otdt/internal/refactoring/adaptor/ChangeSignatureAdaptor.java b/plugins/org.eclipse.objectteams.otdt.refactoring/src/org/eclipse/objectteams/otdt/internal/refactoring/adaptor/ChangeSignatureAdaptor.java
index 123429ae2..d999258f3 100644
--- a/plugins/org.eclipse.objectteams.otdt.refactoring/src/org/eclipse/objectteams/otdt/internal/refactoring/adaptor/ChangeSignatureAdaptor.java
+++ b/plugins/org.eclipse.objectteams.otdt.refactoring/src/org/eclipse/objectteams/otdt/internal/refactoring/adaptor/ChangeSignatureAdaptor.java
@@ -19,6 +19,7 @@ package org.eclipse.objectteams.otdt.internal.refactoring.adaptor;
import java.util.Iterator;
import java.util.List;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.AbstractMethodMappingDeclaration;
@@ -39,6 +40,7 @@ import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages;
import org.eclipse.jdt.internal.corext.refactoring.base.JavaStatusContext;
import org.eclipse.jdt.internal.corext.refactoring.rename.TempOccurrenceAnalyzer;
import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
+import org.eclipse.jdt.internal.corext.refactoring.util.TextChangeManager;
import org.eclipse.jdt.internal.ui.viewsupport.BasicElementLabels;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.RefactoringStatusContext;
@@ -82,18 +84,24 @@ public team class ChangeSignatureAdaptor {
CompilationUnitRewrite cuRewrite, RefactoringStatus refResult)
{
// base method cannot handle method spec, so check this first:
+ if (node.getNodeType() == ASTNode.SIMPLE_NAME) {
+ ASTNode parent = node.getParent();
+ if (parent.getNodeType() == ASTNode.METHOD_SPEC)
+ node = parent; // fall through
+ }
if (node.getNodeType() == ASTNode.METHOD_SPEC) {
- analyzeImpact(node, refResult);
+ MethodSpec spec = (MethodSpec)node;
+ analyzeImpact(spec, refResult);
activate(); // ensure nested role MethodSpecUpdate receives callin triggers
- return new MethodSpecUpdate((MethodSpec)node, cuRewrite, refResult);
- // don't bother to deactivate(), this direct team is temporary itself.
+ return new MethodSpecUpdate(spec, cuRewrite, refResult);
+ // to be deactivated after createChangeManager() (see below).
}
return base.createOccurrenceUpdate(node, cuRewrite, refResult);
}
/* Detect situations that are not fully supported by this refactoring and create INFOs for reporting. */
- void analyzeImpact(ASTNode node, RefactoringStatus refResult) {
- StructuralPropertyDescriptor locationInParent = node.getLocationInParent();
+ void analyzeImpact(MethodSpec spec, RefactoringStatus refResult) {
+ StructuralPropertyDescriptor locationInParent = spec.getLocationInParent();
boolean isSrcSide = false;
if (locationInParent == CalloutMappingDeclaration.ROLE_MAPPING_ELEMENT_PROPERTY) {
isSrcSide = true;
@@ -102,26 +110,41 @@ public team class ChangeSignatureAdaptor {
}
boolean hasDelections = !getDeletedInfos().isEmpty();
boolean hasAdditions = !getAddedInfos().isEmpty();
- if (!isSrcSide && hasAdditions) {
- if (node.getParent().getNodeType() == ASTNode.CALLIN_MAPPING_DECLARATION)
- refResult.merge(RefactoringStatus.createInfoStatus(RefactoringMessages.ChangeSignatureAdaptor_callinRoleArgAddIncomplete_info));
- else
- refResult.merge(RefactoringStatus.createInfoStatus(RefactoringMessages.ChangeSignatureAdaptor_calloutBaseArgAddIncomplete_info));
- } else if (isSrcSide && hasDelections) {
- if (node.getParent().getNodeType() == ASTNode.CALLIN_MAPPING_DECLARATION)
- refResult.merge(RefactoringStatus.createInfoStatus(RefactoringMessages.ChangeSignatureAdaptor_callinBaseArgDeleteIncomplete_info));
- else
- refResult.merge(RefactoringStatus.createInfoStatus(RefactoringMessages.ChangeSignatureAdaptor_calloutRoleArgDeleteIncomplete_info));
+ if (!spec.hasSignature()) {
+ if (hasDelections || hasAdditions || !isOrderSameAsInitial())
+ refResult.merge(RefactoringStatus.createInfoStatus(RefactoringMessages.ChangeSignatureAdaptor_singaturelessBindingIncomplete_info));
+ } else {
+ if (!isSrcSide && hasAdditions) {
+ if (spec.getParent().getNodeType() == ASTNode.CALLIN_MAPPING_DECLARATION)
+ refResult.merge(RefactoringStatus.createInfoStatus(RefactoringMessages.ChangeSignatureAdaptor_callinRoleArgAddIncomplete_info));
+ else
+ refResult.merge(RefactoringStatus.createInfoStatus(RefactoringMessages.ChangeSignatureAdaptor_calloutBaseArgAddIncomplete_info));
+ } else if (isSrcSide && hasDelections) {
+ if (spec.getParent().getNodeType() == ASTNode.CALLIN_MAPPING_DECLARATION)
+ refResult.merge(RefactoringStatus.createInfoStatus(RefactoringMessages.ChangeSignatureAdaptor_callinBaseArgDeleteIncomplete_info));
+ else
+ refResult.merge(RefactoringStatus.createInfoStatus(RefactoringMessages.ChangeSignatureAdaptor_calloutRoleArgDeleteIncomplete_info));
+ }
}
}
+
+ // not activity after createChangeManager():
+ void deactivate() <- after TextChangeManager createChangeManager(IProgressMonitor pm, RefactoringStatus refResult)
+ base when (ChangeSignatureAdaptor.this.hasRole(base, Processor.class));
+
+ public void deactivate() {
+ super.deactivate();
+ ChangeSignatureAdaptor.this.unregisterRole(this, Processor.class);
+ }
/* pure gateway */
protected class OccurrenceUpdate playedBy OccurrenceUpdate
when (this.fMethodSpec != null) // otherwise role was created by lifting, should not intercept anything
{
MethodSpec fMethodSpec;
- void addParamterMappings() <- after void reshuffleElements(); // final method cannot be bound from subrole
- void addParamterMappings() {
+ void addParamterMappings() <- replace void reshuffleElements(); // final method cannot be bound from subrole
+ callin void addParamterMappings() {
+ base.addParamterMappings();
// do nothing here, overrides will take over
}
}
@@ -177,6 +200,7 @@ public team class ChangeSignatureAdaptor {
@SuppressWarnings("inferredcallout") // almost verbatim copy from base
callin void checkIfDeletedParametersUsed() {
+ if (!fMethodSpec.hasSignature()) return;
for (Iterator iter= getDeletedInfos().iterator(); iter.hasNext();) {
ParameterInfo info= (ParameterInfo) iter.next();
SingleVariableDeclaration paramDecl= (SingleVariableDeclaration) fMethodSpec.parameters().get(info.getOldIndex());
@@ -210,9 +234,11 @@ public team class ChangeSignatureAdaptor {
@SuppressWarnings("inferredcallout")
@Override
- void addParamterMappings() {
- if (isOrderSameAsInitial())
- return;
+ callin void addParamterMappings() {
+ if (!this.fMethodSpec.hasSignature()) return;
+ base.addParamterMappings();
+ if (isOrderSameAsInitial()) return;
+
AbstractMethodMappingDeclaration mapping = (AbstractMethodMappingDeclaration) this.fMethodSpec.getParent();
if (mapping.hasParameterMapping()) {
fResult.merge(RefactoringStatus.createWarningStatus(RefactoringMessages.ChangeSignatureAdaptor_cannotUpdateParameterMapping_warning));
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/misc/ChangeSignatureTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/misc/ChangeSignatureTests.java
index bef867db1..b4c82f84e 100644
--- a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/misc/ChangeSignatureTests.java
+++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/misc/ChangeSignatureTests.java
@@ -16,6 +16,7 @@
**********************************************************************/
package org.eclipse.objectteams.otdt.ui.tests.refactoring.misc;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -23,6 +24,7 @@ import java.util.List;
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IMethod;
@@ -157,7 +159,14 @@ public class ChangeSignatureTests extends RefactoringTest {
private void helperDelete(String[] signature, int[] deleteIndices, boolean createDelegate, String expectedInfo) throws Exception {
ICompilationUnit cu= createCUfromTestFile(getPackageP(), true, true);
IType classA= getType(cu, "A");
- IMethod method = classA.getMethod("m", signature);
+ helperDelete(cu, classA, signature, deleteIndices,
+ createDelegate, expectedInfo);
+ }
+
+ void helperDelete(ICompilationUnit cu, IType declaringClass, String[] signature, int[] deleteIndices, boolean createDelegate, String expectedInfo)
+ throws JavaModelException, CoreException, Exception, IOException
+ {
+ IMethod method = declaringClass.getMethod("m", signature);
assertTrue("method does not exist", method.exists());
assertTrue("refactoring not available", RefactoringAvailabilityTester.isChangeSignatureAvailable(method));
@@ -308,6 +317,14 @@ public class ChangeSignatureTests extends RefactoringTest {
helperDelete(new String[]{"I", "I"}, deleteIndices, false/*delegate*/, "Deleting arguments at the role side of a callout binding is not fully supported. Please manually update transitive references."/*expectInfo*/);
}
+ // delete argument in role method bound in signature-less callin
+ public void testDelete03()throws Exception{
+ ICompilationUnit cu= createCUfromTestFile(getPackageP(), true, true);
+ IType roleR= getType(cu, "MyTeam").getType("R");
+ int[] deleteIndices= {1};
+ helperDelete(cu, roleR, new String[]{"I", "I"}, deleteIndices, false/*delegate*/, "Affected method binding has no signatures; consider adding signatures first so that the refactoring can absorb incompatible changes using parameter mappings"/*expectInfo*/);
+ }
+
public void testReorder01() throws Exception {
helperPermute(new String[]{"ignore", "b", "a"}, new String[]{"I", "Z", "QString;"}, false);
}
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/ChangeSignature/canModify/A_testDelete03_in.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/ChangeSignature/canModify/A_testDelete03_in.java
new file mode 100644
index 000000000..8643509c9
--- /dev/null
+++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/ChangeSignature/canModify/A_testDelete03_in.java
@@ -0,0 +1,10 @@
+package p;
+class B {
+ void m(int i, int x) {}
+}
+team class MyTeam {
+ protected class R playedBy B {
+ m <- after m;
+ void m(int i, int x) {}
+ }
+} \ No newline at end of file
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/ChangeSignature/canModify/A_testDelete03_out.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/ChangeSignature/canModify/A_testDelete03_out.java
new file mode 100644
index 000000000..4c6705214
--- /dev/null
+++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/ChangeSignature/canModify/A_testDelete03_out.java
@@ -0,0 +1,10 @@
+package p;
+class B {
+ void m(int i, int x) {}
+}
+team class MyTeam {
+ protected class R playedBy B {
+ m <- after m;
+ void m(int i) {}
+ }
+} \ No newline at end of file

Back to the top