Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2012-08-08 09:48:29 +0000
committerStephan Herrmann2012-08-08 09:48:29 +0000
commitfcc667b6bcc1c67385b0ab8a0a48e53a3aee7864 (patch)
tree411920559256887450f82a63d000cb328d6e4617 /testplugins
parent739c20e9f52f9d70d2bb0dfe0329c0f8f4dad79e (diff)
downloadorg.eclipse.objectteams-fcc667b6bcc1c67385b0ab8a0a48e53a3aee7864.tar.gz
org.eclipse.objectteams-fcc667b6bcc1c67385b0ab8a0a48e53a3aee7864.tar.xz
org.eclipse.objectteams-fcc667b6bcc1c67385b0ab8a0a48e53a3aee7864.zip
Bug 386587 - [refactoring] pull-up refactoring cannot handle callout
bindings
Diffstat (limited to 'testplugins')
-rw-r--r--testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/RefactoringTest.java140
-rw-r--r--testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/pullup/PullUpTests.java21
-rw-r--r--testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout1/in/B.java (renamed from testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout/in/B.java)0
-rw-r--r--testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout1/in/T.java (renamed from testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout/in/T.java)0
-rw-r--r--testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout1/out/B.java (renamed from testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout/out/B.java)0
-rw-r--r--testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout1/out/T.java (renamed from testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout/out/T.java)0
-rw-r--r--testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout2/in/B.java4
-rw-r--r--testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout2/in/T.java13
-rw-r--r--testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout2/out/B.java4
-rw-r--r--testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout2/out/T.java20
10 files changed, 141 insertions, 61 deletions
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/RefactoringTest.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/RefactoringTest.java
index 1e169f339..803f37c4e 100644
--- a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/RefactoringTest.java
+++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/RefactoringTest.java
@@ -20,50 +20,52 @@
**********************************************************************/
package org.eclipse.objectteams.otdt.ui.tests.refactoring;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.StringBufferInputStream;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import junit.framework.TestCase;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IField;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.IMember;
-import org.eclipse.jdt.core.IMethod;
-import org.eclipse.jdt.core.IPackageFragment;
-import org.eclipse.jdt.core.IPackageFragmentRoot;
-import org.eclipse.jdt.core.ISourceManipulation;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.search.IJavaSearchConstants;
-import org.eclipse.jdt.core.search.ITypeNameRequestor;
-import org.eclipse.jdt.core.search.SearchEngine;
-import org.eclipse.jdt.core.search.SearchPattern;
-import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil;
-import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
-import org.eclipse.jdt.internal.corext.util.Strings;
-import org.eclipse.ltk.core.refactoring.Change;
-import org.eclipse.ltk.core.refactoring.CheckConditionsOperation;
-import org.eclipse.ltk.core.refactoring.CreateChangeOperation;
-import org.eclipse.ltk.core.refactoring.IUndoManager;
-import org.eclipse.ltk.core.refactoring.PerformChangeOperation;
-import org.eclipse.ltk.core.refactoring.Refactoring;
-import org.eclipse.ltk.core.refactoring.RefactoringCore;
-import org.eclipse.ltk.core.refactoring.RefactoringStatus;
-
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringBufferInputStream;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.ISourceManipulation;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.search.IJavaSearchConstants;
+import org.eclipse.jdt.core.search.ITypeNameRequestor;
+import org.eclipse.jdt.core.search.SearchEngine;
+import org.eclipse.jdt.core.search.SearchPattern;
+import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil;
+import org.eclipse.jdt.internal.corext.util.Strings;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.CheckConditionsOperation;
+import org.eclipse.ltk.core.refactoring.CreateChangeOperation;
+import org.eclipse.ltk.core.refactoring.IUndoManager;
+import org.eclipse.ltk.core.refactoring.PerformChangeOperation;
+import org.eclipse.ltk.core.refactoring.Refactoring;
+import org.eclipse.ltk.core.refactoring.RefactoringCore;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.objectteams.otdt.core.IOTJavaElement;
+import org.eclipse.objectteams.otdt.internal.core.AbstractCalloutMapping;
+
+@SuppressWarnings("restriction")
public abstract class RefactoringTest extends TestCase
{
private IPackageFragmentRoot _root;
@@ -496,7 +498,7 @@ public abstract class RefactoringTest extends TestCase
{
return new IField[0];
}
- Set fields = new HashSet();
+ Set<IField> fields = new HashSet<IField>();
for (int i = 0; i < names.length; i++)
{
IField field = type.getField(names[i]);
@@ -504,7 +506,7 @@ public abstract class RefactoringTest extends TestCase
field.exists());
fields.add(field);
}
- return (IField[])fields.toArray(new IField[fields.size()]);
+ return fields.toArray(new IField[fields.size()]);
}
public static IType[] getMemberTypes(IType type, String[] names)
@@ -514,7 +516,7 @@ public abstract class RefactoringTest extends TestCase
{
return new IType[0];
}
- Set memberTypes = new HashSet();
+ Set<IType> memberTypes = new HashSet<IType>();
for (int i = 0; i < names.length; i++)
{
IType memberType = type.getType(names[i]);
@@ -522,20 +524,42 @@ public abstract class RefactoringTest extends TestCase
+ " does not exist", memberType.exists());
memberTypes.add(memberType);
}
- return (IType[])memberTypes.toArray(new IType[memberTypes.size()]);
+ return memberTypes.toArray(new IType[memberTypes.size()]);
}
public static IMethod[] getMethods(IType type, String[] names,
String[][] signatures) throws JavaModelException
+ {
+ return getMethods(type, names, signatures, null, false);
+ }
+ public static IMethod[] getMethods(IType type, String[] names, String[][] signatures,
+ boolean[] flags, boolean flag)
+ throws JavaModelException
{
if (names == null || signatures == null)
{
return new IMethod[0];
}
- List methods = new ArrayList(names.length);
+ List<IMethod> methods = new ArrayList<IMethod>(names.length);
for (int i = 0; i < names.length; i++)
- {
- IMethod method = type.getMethod(names[i], signatures[i]);
+ {
+ // use flags to filter sub-set of names/signatures:
+ if (flags != null && flags[i] != flag) continue;
+
+ IMethod method = type.getMethod(names[i], signatures[i]);
+ if (!method.exists()) {
+ // search a callout mapping that might be "equal" to this method:
+ for (IJavaElement child : type.getChildren()) {
+ int elementType = child.getElementType();
+ if (elementType == IOTJavaElement.CALLOUT_MAPPING || elementType == IOTJavaElement.CALLOUT_TO_FIELD_MAPPING) {
+ AbstractCalloutMapping map = (AbstractCalloutMapping) child;
+ if (method.equals(map.getCorrespondingJavaElement())) {
+ method = map;
+ break;
+ }
+ }
+ }
+ }
assertTrue("method " + method.getElementName() + " does not exist",
method.exists());
if (!methods.contains(method))
@@ -543,12 +567,12 @@ public abstract class RefactoringTest extends TestCase
methods.add(method);
}
}
- return (IMethod[])methods.toArray(new IMethod[methods.size()]);
+ return methods.toArray(new IMethod[methods.size()]);
}
public static IType[] findTypes(IType[] types, String[] namesOfTypesToPullUp)
{
- List found = new ArrayList(types.length);
+ List<IType> found = new ArrayList<IType>(types.length);
for (int i = 0; i < types.length; i++)
{
IType type = types[i];
@@ -561,13 +585,13 @@ public abstract class RefactoringTest extends TestCase
}
}
}
- return (IType[])found.toArray(new IType[found.size()]);
+ return found.toArray(new IType[found.size()]);
}
public static IField[] findFields(IField[] fields,
String[] namesOfFieldsToPullUp)
{
- List found = new ArrayList(fields.length);
+ List<IField> found = new ArrayList<IField>(fields.length);
for (int i = 0; i < fields.length; i++)
{
IField field = fields[i];
@@ -580,13 +604,13 @@ public abstract class RefactoringTest extends TestCase
}
}
}
- return (IField[])found.toArray(new IField[found.size()]);
+ return found.toArray(new IField[found.size()]);
}
public static IMethod[] findMethods(IMethod[] selectedMethods,
String[] namesOfMethods, String[][] signaturesOfMethods)
{
- List found = new ArrayList(selectedMethods.length);
+ List<IMethod> found = new ArrayList<IMethod>(selectedMethods.length);
for (int i = 0; i < selectedMethods.length; i++)
{
IMethod method = selectedMethods[i];
@@ -606,7 +630,7 @@ public abstract class RefactoringTest extends TestCase
found.add(method);
}
}
- return (IMethod[])found.toArray(new IMethod[found.size()]);
+ return found.toArray(new IMethod[found.size()]);
}
private static boolean areSameSignatures(String[] s1, String[] s2)
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/pullup/PullUpTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/pullup/PullUpTests.java
index 0c1ada317..947c724d3 100644
--- a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/pullup/PullUpTests.java
+++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/pullup/PullUpTests.java
@@ -129,15 +129,21 @@ public class PullUpTests extends RefactoringTest {
*/
private void performPullUp_pass(String[] cuNames, String[] methodNames, String[][] signatures, String[] fieldNames, boolean deleteAllInSourceType,
boolean deleteAllMatchingMethods, int targetClassIndex, String nameOfDeclaringType) throws Exception {
+ performPullUp_pass(cuNames, methodNames, signatures, null, fieldNames, deleteAllInSourceType, deleteAllMatchingMethods, targetClassIndex, nameOfDeclaringType);
+ }
+ private void performPullUp_pass(String[] cuNames, String[] methodNames, String[][] signatures, boolean[] makeAbstract, String[] fieldNames,
+ boolean deleteAllInSourceType, boolean deleteAllMatchingMethods, int targetClassIndex, String nameOfDeclaringType) throws Exception {
ICompilationUnit[] cus = createCUs(cuNames);
try {
IType declaringType = getType(cus[0], nameOfDeclaringType);
- IMethod[] methods = getMethods(declaringType, methodNames, signatures);
+ IMethod[] methods = getMethods(declaringType, methodNames, signatures, makeAbstract, false);
IField[] fields = getFields(declaringType, fieldNames);
IMember[] members = merge(methods, fields);
PullUpRefactoringProcessor processor = createRefactoringProcessor(members);
+ if (makeAbstract != null)
+ processor.setAbstractMethods(getMethods(declaringType, methodNames, signatures, makeAbstract, true));
Refactoring ref = processor.getRefactoring();
assertTrue("activation", ref.checkInitialConditions(new NullProgressMonitor()).isOK());
@@ -329,7 +335,16 @@ public class PullUpTests extends RefactoringTest {
}
// Bug 374841 - [refactoring] pull up does not work among (nested) roles
- public void testPullUpWithReferenceToCallout() throws Exception {
- performPullUp_pass(new String[] {"T", "B"}, new String[]{"foo"}, new String[][] { new String[0] }, new String[0], true, true, 0, "RSub");
+ public void testPullUpWithReferenceToCallout1() throws Exception {
+ // without pull-up of getS1/getS2 we cannot succeed:
+ performPullUp_failing(new String[] {"T", "B"}, new String[]{"foo"}, new String[][] { new String[0] }, new String[0], true, true, 0, "RSub");
+ }
+ // Bug 386587 - [refactoring] pull-up refactoring cannot handle callout bindings
+ public void testPullUpWithReferenceToCallout2() throws Exception {
+ performPullUp_pass(new String[] {"T", "B"},
+ new String[]{"foo", "getS1", "getS2"},
+ new String[][] { new String[0], new String[0], new String[0] },
+ new boolean[] {false, true, true},
+ new String[0], true, true, 0, "RSub");
}
}
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout/in/B.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout1/in/B.java
index 2f8b9309b..2f8b9309b 100644
--- a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout/in/B.java
+++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout1/in/B.java
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout/in/T.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout1/in/T.java
index b2af6c4fc..b2af6c4fc 100644
--- a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout/in/T.java
+++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout1/in/T.java
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout/out/B.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout1/out/B.java
index 2f8b9309b..2f8b9309b 100644
--- a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout/out/B.java
+++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout1/out/B.java
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout/out/T.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout1/out/T.java
index f4ec07e3e..f4ec07e3e 100644
--- a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout/out/T.java
+++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout1/out/T.java
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout2/in/B.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout2/in/B.java
new file mode 100644
index 000000000..2f8b9309b
--- /dev/null
+++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout2/in/B.java
@@ -0,0 +1,4 @@
+public class B {
+ String s;
+ String getS() { return s; }
+} \ No newline at end of file
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout2/in/T.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout2/in/T.java
new file mode 100644
index 000000000..b2af6c4fc
--- /dev/null
+++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout2/in/T.java
@@ -0,0 +1,13 @@
+public team class T {
+ protected class RSuper {
+
+ }
+ protected class RSub extends RSuper playedBy B {
+ String getS1() -> get String s;
+ String getS2() -> String getS();
+ void foo()
+ {
+ System.out.println(getS1()+getS2());
+ }
+ }
+} \ No newline at end of file
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout2/out/B.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout2/out/B.java
new file mode 100644
index 000000000..2f8b9309b
--- /dev/null
+++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout2/out/B.java
@@ -0,0 +1,4 @@
+public class B {
+ String s;
+ String getS() { return s; }
+} \ No newline at end of file
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout2/out/T.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout2/out/T.java
new file mode 100644
index 000000000..3779040ab
--- /dev/null
+++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/testdata/PullUp/testPullUpWithReferenceToCallout2/out/T.java
@@ -0,0 +1,20 @@
+public team class T {
+ protected abstract class RSuper {
+
+ protected abstract String getS2();
+
+ protected abstract String getS1();
+
+ void foo()
+ {
+ System.out.println(getS1()+getS2());
+ }
+
+ }
+ protected class RSub extends RSuper playedBy B {
+ @Override
+ protected String getS1() -> get String s;
+ @Override
+ protected String getS2() -> String getS();
+ }
+} \ No newline at end of file

Back to the top