Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 229789 Details for
Bug 405270
[1.8][refactoring] Handling of receiver parameter during UI refactoring
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Test Patch.
eclipse.jdt.ui.tests.patch (text/plain), 32.81 KB, created by
Martin Mathew
on 2013-04-17 04:57:06 EDT
(
hide
)
Description:
Test Patch.
Filename:
MIME Type:
Creator:
Martin Mathew
Created:
2013-04-17 04:57:06 EDT
Size:
32.81 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.ui.tests.refactoring >diff --git resources/ReceiverParameter/testExtractInterface/in/A.java resources/ReceiverParameter/testExtractInterface/in/A.java >new file mode 100644 >index 0000000..368c2da >--- /dev/null >+++ resources/ReceiverParameter/testExtractInterface/in/A.java >@@ -0,0 +1,9 @@ >+package p; >+@Target({ ElementType.TYPE_USE, ElementType.METHOD }) >+@interface NonNull { >+ >+} >+class A{ >+ public void foo1(@NonNull A this){} >+ public void foo2(@NonNull A this, String s){} >+} >\ No newline at end of file >diff --git resources/ReceiverParameter/testExtractInterface/out/A.java resources/ReceiverParameter/testExtractInterface/out/A.java >new file mode 100644 >index 0000000..955a086 >--- /dev/null >+++ resources/ReceiverParameter/testExtractInterface/out/A.java >@@ -0,0 +1,15 @@ >+package p; >+@Target({ ElementType.TYPE_USE, ElementType.METHOD }) >+@interface NonNull { >+ >+} >+class A implements I{ >+ /* (non-Javadoc) >+ * @see p.I#foo1() >+ */ >+ public void foo1(@NonNull A this){} >+ /* (non-Javadoc) >+ * @see p.I#foo2(java.lang.String) >+ */ >+ public void foo2(@NonNull A this, String s){} >+} >\ No newline at end of file >diff --git resources/ReceiverParameter/testExtractInterface/out/I.java resources/ReceiverParameter/testExtractInterface/out/I.java >new file mode 100644 >index 0000000..6bd3ca9 >--- /dev/null >+++ resources/ReceiverParameter/testExtractInterface/out/I.java >@@ -0,0 +1,10 @@ >+package p; >+ >+/** typecomment template*/ >+interface I { >+ >+ public abstract void foo1(@NonNull I this); >+ >+ public abstract void foo2(@NonNull I this, String s); >+ >+} >\ No newline at end of file >diff --git resources/ReceiverParameter/testExtractSuperclass/in/A.java resources/ReceiverParameter/testExtractSuperclass/in/A.java >new file mode 100644 >index 0000000..fa79f14 >--- /dev/null >+++ resources/ReceiverParameter/testExtractSuperclass/in/A.java >@@ -0,0 +1,14 @@ >+package p; >+@Target({ ElementType.TYPE_USE, ElementType.METHOD }) >+@interface NonNull { >+ >+} >+class A{ >+ void foo1(@NonNull A this){ >+ System.out.println("foo1"); >+ } >+ void foo2(@NonNull A this, String s){ >+ System.out.println("foo2"); >+ } >+ >+} >diff --git resources/ReceiverParameter/testExtractSuperclass/out/A.java resources/ReceiverParameter/testExtractSuperclass/out/A.java >new file mode 100644 >index 0000000..93543be >--- /dev/null >+++ resources/ReceiverParameter/testExtractSuperclass/out/A.java >@@ -0,0 +1,8 @@ >+package p; >+@Target({ ElementType.TYPE_USE, ElementType.METHOD }) >+@interface NonNull { >+ >+} >+class A extends B{ >+ >+} >diff --git resources/ReceiverParameter/testExtractSuperclass/out/B.java resources/ReceiverParameter/testExtractSuperclass/out/B.java >new file mode 100644 >index 0000000..b3abe19 >--- /dev/null >+++ resources/ReceiverParameter/testExtractSuperclass/out/B.java >@@ -0,0 +1,17 @@ >+package p; >+ >+public class B { >+ >+ public B() { >+ super(); >+ } >+ >+ void foo1(@NonNull B this) { >+ System.out.println("foo1"); >+ } >+ >+ void foo2(@NonNull B this, String s) { >+ System.out.println("foo2"); >+ } >+ >+} >\ No newline at end of file >diff --git resources/ReceiverParameter/testMove/in/A.java resources/ReceiverParameter/testMove/in/A.java >new file mode 100644 >index 0000000..baf8e41 >--- /dev/null >+++ resources/ReceiverParameter/testMove/in/A.java >@@ -0,0 +1,19 @@ >+package p1; >+ >+import java.lang.annotation.ElementType; >+import java.lang.annotation.Target; >+ >+@Target({ ElementType.TYPE_USE, ElementType.METHOD }) >+@interface NonNull { >+ >+} >+public class A { >+ >+ public void mA1(@NonNull A this, B b) { >+ b.mB1(); >+ System.out.println(b + "j"); >+ } >+ >+ public void mA2() {} >+ >+} >\ No newline at end of file >diff --git resources/ReceiverParameter/testMove/in/B.java resources/ReceiverParameter/testMove/in/B.java >new file mode 100644 >index 0000000..e9d33c3 >--- /dev/null >+++ resources/ReceiverParameter/testMove/in/B.java >@@ -0,0 +1,7 @@ >+package p1; >+ >+public class B { >+ public void mB1() {} >+ >+ public void mB2() {} >+} >\ No newline at end of file >diff --git resources/ReceiverParameter/testMove/out/A.java resources/ReceiverParameter/testMove/out/A.java >new file mode 100644 >index 0000000..de0b237 >--- /dev/null >+++ resources/ReceiverParameter/testMove/out/A.java >@@ -0,0 +1,18 @@ >+package p1; >+ >+import java.lang.annotation.ElementType; >+import java.lang.annotation.Target; >+ >+@Target({ ElementType.TYPE_USE, ElementType.METHOD }) >+@interface NonNull { >+ >+} >+public class A { >+ >+ public void mA1(@NonNull A this, B b) { >+ b.mA1Moved(); >+ } >+ >+ public void mA2() {} >+ >+} >\ No newline at end of file >diff --git resources/ReceiverParameter/testMove/out/B.java resources/ReceiverParameter/testMove/out/B.java >new file mode 100644 >index 0000000..daa8e4a >--- /dev/null >+++ resources/ReceiverParameter/testMove/out/B.java >@@ -0,0 +1,13 @@ >+package p1; >+ >+public class B { >+ public void mB1() {} >+ >+ public void mB2() {} >+ >+ public void mA1Moved(@NonNull >+ B this) { >+ mB1(); >+ System.out.println(this + "j"); >+ } >+} >\ No newline at end of file >diff --git resources/ReceiverParameter/testMoveType2File/in/A.java resources/ReceiverParameter/testMoveType2File/in/A.java >new file mode 100644 >index 0000000..0545965 >--- /dev/null >+++ resources/ReceiverParameter/testMoveType2File/in/A.java >@@ -0,0 +1,14 @@ >+package p; >+@Target({ ElementType.TYPE_USE, ElementType.METHOD }) >+@interface NonNull { >+ >+} >+class A{ >+ >+class Inner{ >+ Inner(@NonNull A A.this){} >+ public void foo1(@NonNull Inner this){ >+ System.out.println("Hello"); >+ } >+} >+} >\ No newline at end of file >diff --git resources/ReceiverParameter/testMoveType2File/out/A.java resources/ReceiverParameter/testMoveType2File/out/A.java >new file mode 100644 >index 0000000..f33abc5 >--- /dev/null >+++ resources/ReceiverParameter/testMoveType2File/out/A.java >@@ -0,0 +1,7 @@ >+package p; >+@Target({ ElementType.TYPE_USE, ElementType.METHOD }) >+@interface NonNull { >+ >+} >+class A{ >+} >\ No newline at end of file >diff --git resources/ReceiverParameter/testMoveType2File/out/Inner.java resources/ReceiverParameter/testMoveType2File/out/Inner.java >new file mode 100644 >index 0000000..1a38455 >--- /dev/null >+++ resources/ReceiverParameter/testMoveType2File/out/Inner.java >@@ -0,0 +1,7 @@ >+package p; >+class Inner{ >+ Inner(){} >+ public void foo1(@NonNull Inner this){ >+ System.out.println("Hello"); >+ } >+} >\ No newline at end of file >diff --git resources/ReceiverParameter/testPullUp/in/A.java resources/ReceiverParameter/testPullUp/in/A.java >new file mode 100644 >index 0000000..66d2762 >--- /dev/null >+++ resources/ReceiverParameter/testPullUp/in/A.java >@@ -0,0 +1,11 @@ >+package p; >+@Target({ ElementType.TYPE_USE, ElementType.METHOD }) >+@interface NonNull { >+ >+} >+class A{ >+} >+class B extends A{ >+ void foo1(@NonNull B this){} >+ void foo2(@NonNull B this, String s){} >+} >\ No newline at end of file >diff --git resources/ReceiverParameter/testPullUp/out/A.java resources/ReceiverParameter/testPullUp/out/A.java >new file mode 100644 >index 0000000..f7abbf0 >--- /dev/null >+++ resources/ReceiverParameter/testPullUp/out/A.java >@@ -0,0 +1,13 @@ >+package p; >+@Target({ ElementType.TYPE_USE, ElementType.METHOD }) >+@interface NonNull { >+ >+} >+class A{ >+ >+ void foo1(@NonNull A this) {} >+ >+ void foo2(@NonNull A this, String s) {} >+} >+class B extends A{ >+} >\ No newline at end of file >diff --git resources/ReceiverParameter/testPushDown/in/A.java resources/ReceiverParameter/testPushDown/in/A.java >new file mode 100644 >index 0000000..67948c1 >--- /dev/null >+++ resources/ReceiverParameter/testPushDown/in/A.java >@@ -0,0 +1,15 @@ >+package p; >+@Target({ ElementType.TYPE_USE, ElementType.METHOD }) >+@interface NonNull { >+ >+} >+class A{ >+ public void foo1(@NonNull A this) { >+ System.out.println("foo1"); >+ } >+ public void foo2(@NonNull A this, String s) { >+ System.out.println(s); >+ } >+} >+class B extends A{ >+} >\ No newline at end of file >diff --git resources/ReceiverParameter/testPushDown/out/A.java resources/ReceiverParameter/testPushDown/out/A.java >new file mode 100644 >index 0000000..8fa1cf5 >--- /dev/null >+++ resources/ReceiverParameter/testPushDown/out/A.java >@@ -0,0 +1,17 @@ >+package p; >+@Target({ ElementType.TYPE_USE, ElementType.METHOD }) >+@interface NonNull { >+ >+} >+class A{ >+} >+class B extends A{ >+ >+ public void foo1(@NonNull B this) { >+ System.out.println("foo1"); >+ } >+ >+ public void foo2(@NonNull B this, String s) { >+ System.out.println(s); >+ } >+} >\ No newline at end of file >diff --git test cases/org/eclipse/jdt/ui/tests/refactoring/Java18Setup.java test cases/org/eclipse/jdt/ui/tests/refactoring/Java18Setup.java >new file mode 100644 >index 0000000..e79d402 >--- /dev/null >+++ test cases/org/eclipse/jdt/ui/tests/refactoring/Java18Setup.java >@@ -0,0 +1,39 @@ >+/******************************************************************************* >+ * Copyright (c) 2013 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and >+ * is made available for testing and evaluation purposes only. >+ * The code is not compatible with any specification of the JCP. >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jdt.ui.tests.refactoring; >+ >+import junit.framework.Test; >+ >+import org.eclipse.jdt.testplugin.JavaProjectHelper; >+ >+import org.eclipse.core.runtime.CoreException; >+ >+import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.IPackageFragmentRoot; >+ >+public class Java18Setup extends RefactoringTestSetup { >+ >+ public Java18Setup(Test test) { >+ super(test); >+ } >+ >+ /* >+ * @see org.eclipse.jdt.ui.tests.refactoring.RefactoringTestSetup#addRTJar(org.eclipse.jdt.core.IJavaProject) >+ */ >+ @Override >+ protected IPackageFragmentRoot addRTJar(IJavaProject project) throws CoreException { >+ return JavaProjectHelper.addRTJar18(project); >+ } >+} >diff --git test cases/org/eclipse/jdt/ui/tests/refactoring/ReceiverParameterTests18.java test cases/org/eclipse/jdt/ui/tests/refactoring/ReceiverParameterTests18.java >new file mode 100644 >index 0000000..b0e9def >--- /dev/null >+++ test cases/org/eclipse/jdt/ui/tests/refactoring/ReceiverParameterTests18.java >@@ -0,0 +1,450 @@ >+/******************************************************************************* >+ * Copyright (c) 2013 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and >+ * is made available for testing and evaluation purposes only. >+ * The code is not compatible with any specification of the JCP. >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jdt.ui.tests.refactoring; >+ >+import java.util.Arrays; >+import java.util.Hashtable; >+import java.util.List; >+ >+import junit.framework.Test; >+import junit.framework.TestSuite; >+ >+import org.eclipse.jdt.testplugin.TestOptions; >+ >+import org.eclipse.core.runtime.Assert; >+import org.eclipse.core.runtime.NullProgressMonitor; >+ >+import org.eclipse.ltk.core.refactoring.Refactoring; >+import org.eclipse.ltk.core.refactoring.RefactoringStatus; >+import org.eclipse.ltk.core.refactoring.participants.MoveRefactoring; >+import org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring; >+ >+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.IType; >+import org.eclipse.jdt.core.JavaCore; >+import org.eclipse.jdt.core.JavaModelException; >+import org.eclipse.jdt.core.dom.IVariableBinding; >+import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; >+ >+import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings; >+import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility; >+import org.eclipse.jdt.internal.corext.refactoring.RefactoringAvailabilityTester; >+import org.eclipse.jdt.internal.corext.refactoring.structure.ExtractInterfaceProcessor; >+import org.eclipse.jdt.internal.corext.refactoring.structure.ExtractSupertypeProcessor; >+import org.eclipse.jdt.internal.corext.refactoring.structure.MoveInnerToTopRefactoring; >+import org.eclipse.jdt.internal.corext.refactoring.structure.MoveInstanceMethodProcessor; >+import org.eclipse.jdt.internal.corext.refactoring.structure.PullUpRefactoringProcessor; >+import org.eclipse.jdt.internal.corext.refactoring.structure.PushDownRefactoringProcessor; >+import org.eclipse.jdt.internal.corext.refactoring.structure.PushDownRefactoringProcessor.MemberActionInfo; >+import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; >+import org.eclipse.jdt.internal.corext.template.java.CodeTemplateContextType; >+ >+import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings; >+ >+public class ReceiverParameterTests18 extends RefactoringTest { >+ >+ private static final Class clazz= ReceiverParameterTests18.class; >+ >+ private static final String REFACTORING_PATH= "ReceiverParameter/"; >+ >+ private Hashtable fOldOptions; >+ >+ public ReceiverParameterTests18(String name) { >+ super(name); >+ } >+ >+ public static Test suite() { >+ return new Java18Setup(new TestSuite(clazz)); >+ } >+ >+ public static Test setUpTest(Test someTest) { >+ return new Java18Setup(someTest); >+ } >+ >+ @Override >+ protected void setUp() throws Exception { >+ super.setUp(); >+ StubUtility.setCodeTemplate(CodeTemplateContextType.NEWTYPE_ID, >+ "${package_declaration}" + >+ System.getProperty("line.separator", "\n") + >+ "${" + CodeTemplateContextType.TYPE_COMMENT + "}" + >+ System.getProperty("line.separator", "\n") + >+ "${type_declaration}", null); >+ >+ StubUtility.setCodeTemplate(CodeTemplateContextType.TYPECOMMENT_ID, "/** typecomment template*/", null); >+ >+ fOldOptions= JavaCore.getOptions(); >+ >+ Hashtable options= TestOptions.getDefaultOptions(); >+ options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_ASSIGNMENT_OPERATOR, DefaultCodeFormatterConstants.TRUE); >+ options.put(DefaultCodeFormatterConstants.FORMATTER_NUMBER_OF_EMPTY_LINES_TO_PRESERVE, "1"); >+ options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.TAB); >+ >+ JavaCore.setOptions(options); >+ } >+ >+ @Override >+ protected void tearDown() throws Exception { >+ super.tearDown(); >+ JavaCore.setOptions(fOldOptions); >+ fOldOptions= null; >+ } >+ >+ @Override >+ protected String getRefactoringPath() { >+ return REFACTORING_PATH; >+ } >+ >+ private static PullUpRefactoringProcessor createPullUpRefactoringProcessor(IMember[] methods) throws JavaModelException { >+ IJavaProject project= null; >+ if (methods != null && methods.length > 0) >+ project= methods[0].getJavaProject(); >+ if (RefactoringAvailabilityTester.isPullUpAvailable(methods)) { >+ PullUpRefactoringProcessor processor= new PullUpRefactoringProcessor(methods, JavaPreferencesSettings.getCodeGenerationSettings(project)); >+ new ProcessorBasedRefactoring(processor); >+ return processor; >+ } >+ return null; >+ } >+ >+ private static ExtractSupertypeProcessor createExtractSuperclassRefactoringProcessor(IMember[] members) throws JavaModelException { >+ IJavaProject project= null; >+ if (members != null && members.length > 0) >+ project= members[0].getJavaProject(); >+ if (RefactoringAvailabilityTester.isExtractSupertypeAvailable(members)) { >+ final CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings(project); >+ settings.createComments= false; >+ ExtractSupertypeProcessor processor= new ExtractSupertypeProcessor(members, settings); >+ new ProcessorBasedRefactoring(processor); >+ return processor; >+ } >+ return null; >+ } >+ >+ private IPackageFragment getPackage(String name) throws JavaModelException { >+ if ("p".equals(name)) >+ return getPackageP(); >+ IPackageFragment pack= getRoot().getPackageFragment(name); >+ if (pack.exists()) >+ return pack; >+ return getRoot().createPackageFragment(name, false, new NullProgressMonitor()); >+ } >+ >+ private static String getTopLevelTypeName(String typeQualifiedTyperName) { >+ int dotIndex= typeQualifiedTyperName.indexOf('.'); >+ if (dotIndex == -1) >+ return typeQualifiedTyperName; >+ return typeQualifiedTyperName.substring(0, dotIndex); >+ } >+ >+ private void prepareForInputCheck(PushDownRefactoringProcessor processor, IMethod[] selectedMethods, IField[] selectedFields, String[] namesOfMethodsToPullUp, >+ String[][] signaturesOfMethodsToPullUp, String[] namesOfFieldsToPullUp, String[] namesOfMethodsToDeclareAbstract, String[][] signaturesOfMethodsToDeclareAbstract) { >+ IMethod[] methodsToPushDown= findMethods(selectedMethods, namesOfMethodsToPullUp, signaturesOfMethodsToPullUp); >+ IField[] fieldsToPushDown= findFields(selectedFields, namesOfFieldsToPullUp); >+ List membersToPushDown= Arrays.asList(merge(methodsToPushDown, fieldsToPushDown)); >+ List methodsToDeclareAbstract= Arrays.asList(findMethods(selectedMethods, namesOfMethodsToDeclareAbstract, signaturesOfMethodsToDeclareAbstract)); >+ >+ MemberActionInfo[] infos= processor.getMemberActionInfos(); >+ for (int i= 0; i < infos.length; i++) { >+ if (membersToPushDown.contains(infos[i].getMember())) { >+ infos[i].setAction(MemberActionInfo.PUSH_DOWN_ACTION); >+ assertTrue(!methodsToDeclareAbstract.contains(infos[i].getMember())); >+ } >+ if (methodsToDeclareAbstract.contains(infos[i].getMember())) { >+ infos[i].setAction(MemberActionInfo.PUSH_ABSTRACT_ACTION); >+ assertTrue(!membersToPushDown.contains(infos[i].getMember())); >+ } >+ } >+ } >+ >+ /** >+ * Tests "Pull Up" method refactoring involving receiver parameter. >+ * >+ * @throws Exception any exception thrown from this test case >+ */ >+ public void testPullUp() throws Exception { >+ String[] methodNames= new String[] { "foo1", "foo2" }; >+ String[][] signatures= new String[][] { new String[0], new String[] { "QString;" } }; >+ boolean deleteAllInSourceType= true; >+ boolean deleteAllMatchingMethods= false; >+ ICompilationUnit cu= createCUfromTestFile(getPackageP(), "A"); >+ IType type= getType(cu, "B"); >+ IMethod[] methods= getMethods(type, methodNames, signatures); >+ >+ PullUpRefactoringProcessor processor= createPullUpRefactoringProcessor(methods); >+ Refactoring ref= processor.getRefactoring(); >+ >+ assertTrue("activation", ref.checkInitialConditions(new NullProgressMonitor()).isOK()); >+ >+ IType[] possibleClasses= processor.getCandidateTypes(new RefactoringStatus(), new NullProgressMonitor()); >+ assertTrue("No possible class found!", possibleClasses.length > 0); >+ processor.setDestinationType(processor.getCandidateTypes(new RefactoringStatus(), new NullProgressMonitor())[possibleClasses.length - 1 - 0]); >+ >+ if (deleteAllInSourceType) >+ processor.setDeletedMethods(methods); >+ if (deleteAllMatchingMethods) { >+ List l= Arrays.asList(JavaElementUtil.getElementsOfType(processor.getMatchingElements(new NullProgressMonitor(), false), IJavaElement.METHOD)); >+ processor.setDeletedMethods((IMethod[])l.toArray(new IMethod[l.size()])); >+ } >+ >+ RefactoringStatus checkInputResult= ref.checkFinalConditions(new NullProgressMonitor()); >+ assertTrue("precondition was supposed to pass", !checkInputResult.hasError()); >+ performChange(ref, false); >+ >+ String expected= getFileContents(getOutputTestFileName("A")); >+ String actual= cu.getSource(); >+ assertEqualLines(expected, actual); >+ } >+ >+ /** >+ * Tests "Push Down" method refactoring involving receiver parameter. >+ * >+ * @throws Exception any exception thrown from this test case >+ */ >+ public void testPushDown() throws Exception { >+ String[] namesOfMethodsToPushDown= { "foo1", "foo2" }; >+ String[][] signaturesOfMethodsToPushDown= { new String[0], new String[] { "QString;" } }; >+ String[] selectedFieldNames= {}; >+ String[] namesOfFieldsToPushDown= {}; >+ String[] namesOfMethodsToDeclareAbstract= {}; >+ String[][] signaturesOfMethodsToDeclareAbstract= {}; >+ >+ >+ ICompilationUnit cuA= createCUfromTestFile(getPackageP(), "A"); >+ >+ IType type= getType(cuA, "A"); >+ IMethod[] selectedMethods= getMethods(type, namesOfMethodsToPushDown, signaturesOfMethodsToPushDown); >+ IField[] selectedFields= getFields(type, selectedFieldNames); >+ IMember[] selectedMembers= merge(selectedFields, selectedMethods); >+ >+ assertTrue(RefactoringAvailabilityTester.isPushDownAvailable(selectedMembers)); >+ PushDownRefactoringProcessor processor= new PushDownRefactoringProcessor(selectedMembers); >+ Refactoring ref= new ProcessorBasedRefactoring(processor); >+ >+ assertTrue("activation", ref.checkInitialConditions(new NullProgressMonitor()).isOK()); >+ >+ prepareForInputCheck(processor, selectedMethods, selectedFields, namesOfMethodsToPushDown, signaturesOfMethodsToPushDown, namesOfFieldsToPushDown, namesOfMethodsToDeclareAbstract, >+ signaturesOfMethodsToDeclareAbstract); >+ >+ RefactoringStatus checkInputResult= ref.checkFinalConditions(new NullProgressMonitor()); >+ assertTrue("precondition was supposed to pass but got " + checkInputResult.toString(), !checkInputResult.hasError()); >+ performChange(ref, false); >+ >+ String expected= getFileContents(getOutputTestFileName("A")); >+ String actual= cuA.getSource(); >+ assertEqualLines("A.java", expected, actual); >+ >+ } >+ >+ /** >+ * Tests "Move" method refactoring involving receiver parameter. >+ * >+ * @throws Exception any exception thrown from this test case >+ */ >+ public void testMove() throws Exception { >+ String[] cuQNames= new String[] { "p1.A", "p2.B" }; >+ String selectionCuQName= "p1.A"; >+ boolean inlineDelegator= false; >+ boolean removeDelegator= false; >+ int selectionCuIndex= -1; >+ for (int i= 0; i < cuQNames.length; i++) >+ if (cuQNames[i] == null || selectionCuQName.equals(cuQNames[i])) >+ selectionCuIndex= i; >+ Assert.isTrue(selectionCuIndex != -1, "parameter selectionCuQName must match some String in cuQNames."); >+ ICompilationUnit cuA= createCUfromTestFile(getPackage("p1"), "A"); >+ ICompilationUnit cuB= createCUfromTestFile(getPackage("p1"), "B"); >+ >+ int offset= cuA.getSource().indexOf("mA1(@NonNull A this, B b)"); >+ IJavaElement[] codeSelect= cuA.codeSelect(offset, 3); >+ assertTrue(codeSelect.length > 0); >+ assertTrue(codeSelect[0] instanceof IMethod); >+ IMethod method= (IMethod)codeSelect[0]; >+ MoveInstanceMethodProcessor processor= new MoveInstanceMethodProcessor(method, JavaPreferencesSettings.getCodeGenerationSettings(cuA.getJavaProject())); >+ Refactoring ref= new MoveRefactoring(processor); >+ >+ assertNotNull("refactoring should be created", ref); >+ RefactoringStatus preconditionResult= ref.checkInitialConditions(new NullProgressMonitor()); >+ >+ assertTrue("activation was supposed to be successful", preconditionResult.isOK()); >+ >+ IVariableBinding target= null; >+ IVariableBinding[] targets= processor.getPossibleTargets(); >+ for (int i= 0; i < targets.length; i++) { >+ IVariableBinding candidate= targets[i]; >+ if (candidate.getName().equals("b")) { >+ target= candidate; >+ break; >+ } >+ } >+ assertNotNull("Expected new target not available.", target); >+ processor.setTarget(target); >+ >+ processor.setInlineDelegator(inlineDelegator); >+ processor.setRemoveDelegator(removeDelegator); >+ processor.setDeprecateDelegates(false); >+ processor.setMethodName("mA1Moved"); >+ >+ preconditionResult.merge(ref.checkFinalConditions(new NullProgressMonitor())); >+ >+ assertTrue("precondition was supposed to pass", !preconditionResult.hasError()); >+ >+ performChange(ref, false); >+ >+ String outputTestFileName= getOutputTestFileName("A"); >+ assertEqualLines("Incorrect inline in " + outputTestFileName, getFileContents(outputTestFileName), cuA.getSource()); >+ >+ >+ outputTestFileName= getOutputTestFileName("B"); >+ assertEqualLines("Incorrect inline in " + outputTestFileName, getFileContents(outputTestFileName), cuB.getSource()); >+ >+ } >+ >+ /** >+ * Tests "Move Type to New File" refactoring involving receiver parameter. >+ * >+ * @throws Exception any exception thrown from this test case >+ */ >+ public void testMoveType2File() throws Exception { >+ String parentClassName= "A"; >+ String enclosingInstanceName= "Inner"; >+ String[] cuNames= new String[] { "A" }; >+ String[] packageNames= new String[] { "p" }; >+ String packageName= "p"; >+ IType parentClas= getType(createCUfromTestFile(getPackage(packageName), parentClassName), parentClassName); >+ IType clas= parentClas.getType(enclosingInstanceName); >+ >+ assertTrue("should be enabled", RefactoringAvailabilityTester.isMoveInnerAvailable(clas)); >+ MoveInnerToTopRefactoring ref= ((RefactoringAvailabilityTester.isMoveInnerAvailable(clas)) ? new MoveInnerToTopRefactoring(clas, JavaPreferencesSettings.getCodeGenerationSettings(clas >+ .getJavaProject())) : null); >+ RefactoringStatus preconditionResult= ref.checkInitialConditions(new NullProgressMonitor()); >+ assertTrue("activation was supposed to be successful" + preconditionResult.toString(), preconditionResult.isOK()); >+ >+ assertEquals("reference creation possible", true, ref.isCreatingInstanceFieldPossible()); >+ assertEquals("reference creation mandatory", false, ref.isCreatingInstanceFieldMandatory()); >+ if (ref.isCreatingInstanceFieldPossible() && !ref.isCreatingInstanceFieldMandatory()) >+ ref.setCreateInstanceField(false); >+ ref.setEnclosingInstanceName(enclosingInstanceName); >+ assertTrue("name should be ok ", ref.checkEnclosingInstanceName(enclosingInstanceName).isOK()); >+ ref.setMarkInstanceFieldAsFinal(false); >+ ICompilationUnit[] cus= new ICompilationUnit[cuNames.length]; >+ for (int i= 0; i < cuNames.length; i++) { >+ if (cuNames[i].equals(clas.getCompilationUnit().findPrimaryType().getElementName())) >+ cus[i]= clas.getCompilationUnit(); >+ else >+ cus[i]= createCUfromTestFile(getPackage(packageNames[i]), cuNames[i]); >+ } >+ >+ RefactoringStatus checkInputResult= ref.checkFinalConditions(new NullProgressMonitor()); >+ assertTrue("precondition was supposed to pass", !checkInputResult.hasError()); >+ performChange(ref, false); >+ >+ for (int i= 0; i < cus.length; i++) { >+ String actual= cus[i].getSource(); >+ String expected= getFileContents(getOutputTestFileName(cuNames[i])); >+ assertEqualLines(cus[i].getElementName(), expected, actual); >+ } >+ ICompilationUnit newCu= clas.getPackageFragment().getCompilationUnit(enclosingInstanceName + ".java"); >+ String expected= getFileContents(getOutputTestFileName(enclosingInstanceName)); >+ String actual= newCu.getSource(); >+ assertEqualLines("new Cu:", expected, actual); >+ >+ } >+ >+ /** >+ * Tests "Extract Interface" refactoring involving receiver parameter. >+ * >+ * @throws Exception any exception thrown from this test case >+ */ >+ public void testExtractInterface() throws Exception { >+ String className= "A"; >+ String newInterfaceName= "I"; >+ >+ IType clas= getType(createCUfromTestFile(getPackageP(), getTopLevelTypeName(className)), className); >+ ICompilationUnit cu= clas.getCompilationUnit(); >+ IPackageFragment pack= (IPackageFragment)cu.getParent(); >+ >+ ExtractInterfaceProcessor processor= new ExtractInterfaceProcessor(clas, JavaPreferencesSettings.getCodeGenerationSettings(clas.getJavaProject())); >+ Refactoring ref= new ProcessorBasedRefactoring(processor); >+ >+ processor.setTypeName(newInterfaceName); >+ assertEquals("interface name should be accepted", RefactoringStatus.OK, processor.checkTypeName(newInterfaceName).getSeverity()); >+ >+ processor.setExtractedMembers(processor.getExtractableMembers()); >+ processor.setReplace(true); >+ processor.setAnnotations(false); >+ assertEquals("was supposed to pass", null, performRefactoring(ref)); >+ assertEqualLines("incorrect changes in " + className, >+ getFileContents(getOutputTestFileName(className)), >+ cu.getSource()); >+ >+ ICompilationUnit interfaceCu= pack.getCompilationUnit(newInterfaceName + ".java"); >+ assertEqualLines("incorrect interface created", >+ getFileContents(getOutputTestFileName(newInterfaceName)), >+ interfaceCu.getSource()); >+ } >+ >+ /** >+ * Tests "Extract Superclass" refactoring involving receiver parameter. >+ * >+ * @throws Exception any exception thrown from this test case >+ */ >+ public void testExtractSuperclass() throws Exception { >+ String[] methodNames= new String[] { "foo1", "foo2" }; >+ String[][] signatures= new String[][] { new String[0], new String[] { "QString;" } }; >+ boolean replaceOccurences= true; >+ >+ >+ ICompilationUnit cu= createCUfromTestFile(getPackageP(), "A"); >+ IType type= getType(cu, "A"); >+ IMethod[] methods= getMethods(type, methodNames, signatures); >+ >+ ExtractSupertypeProcessor processor= createExtractSuperclassRefactoringProcessor(methods); >+ Refactoring refactoring= processor.getRefactoring(); >+ processor.setMembersToMove(methods); >+ >+ assertTrue("activation", refactoring.checkInitialConditions(new NullProgressMonitor()).isOK()); >+ >+ processor.setTypesToExtract(new IType[] { type }); >+ processor.setTypeName("B"); >+ processor.setCreateMethodStubs(true); >+ processor.setInstanceOf(false); >+ processor.setReplace(replaceOccurences); >+ processor.setDeletedMethods(methods); >+ >+ RefactoringStatus status= refactoring.checkFinalConditions(new NullProgressMonitor()); >+ assertTrue("precondition was supposed to pass", !status.hasError()); >+ performChange(refactoring, false); >+ >+ String expected= getFileContents(getOutputTestFileName("A")); >+ String actual= cu.getSource(); >+ assertEqualLines(expected, actual); >+ >+ expected= getFileContents(getOutputTestFileName("B")); >+ ICompilationUnit unit= getPackageP().getCompilationUnit("B.java"); >+ if (!unit.exists()) >+ assertTrue("extracted compilation unit does not exist", false); >+ actual= unit.getBuffer().getContents(); >+ assertEqualLines(expected, actual); >+ >+ >+ } >+ >+} >#P org.eclipse.jdt.ui.tests >diff --git test plugin/org/eclipse/jdt/testplugin/JavaProjectHelper.java test plugin/org/eclipse/jdt/testplugin/JavaProjectHelper.java >index 79369bb..a1734a6 100644 >--- test plugin/org/eclipse/jdt/testplugin/JavaProjectHelper.java >+++ test plugin/org/eclipse/jdt/testplugin/JavaProjectHelper.java >@@ -1,10 +1,14 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2012 IBM Corporation and others. >+ * Copyright (c) 2000, 2013 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at > * http://www.eclipse.org/legal/epl-v10.html > * >+ * This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and >+ * is made available for testing and evaluation purposes only. >+ * The code is not compatible with any specification of the JCP. >+ * > * Contributors: > * IBM Corporation - initial API and implementation > * Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar >@@ -87,6 +91,7 @@ > public static final IPath RT_STUBS_15= new Path("testresources/rtstubs15.jar"); > public static final IPath RT_STUBS_16= new Path("testresources/rtstubs16.jar"); > public static final IPath RT_STUBS_17= new Path("testresources/rtstubs17.jar"); >+ public static final IPath RT_STUBS_18= new Path("testresources/rtstubs18.jar"); > public static final IPath JUNIT_SRC_381= new Path("testresources/junit381-noUI-src.zip"); > public static final String JUNIT_SRC_ENCODING= "ISO-8859-1"; > >@@ -187,6 +192,18 @@ > } > > /** >+ * Sets the compiler options to 1.8 for the given project. >+ * >+ * @param project the java project >+ * @since 3.9 BETA_JAVA8 >+ */ >+ private static void set18CompilerOptions(IJavaProject project) { >+ Map options= project.getOptions(false); >+ JavaProjectHelper.set18CompilerOptions(options); >+ project.setOptions(options); >+ } >+ >+ /** > * Sets the compiler options to 1.7 for the given project. > * @param project the java project > */ >@@ -227,7 +244,18 @@ > } > > /** >+ * Sets the compiler options to 1.8 >+ * >+ * @param options The compiler options to configure >+ * @since 3.9 BETA_JAVA8 >+ */ >+ private static void set18CompilerOptions(Map options) { >+ JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options); >+ } >+ >+ /** > * Sets the compiler options to 1.7 >+ * > * @param options The compiler options to configure > */ > public static void set17CompilerOptions(Map options) { >@@ -645,6 +673,13 @@ > return addLibrary(jproject, rtJarPath[0], rtJarPath[1], rtJarPath[2]); > } > >+ >+ public static IPackageFragmentRoot addRTJar18(IJavaProject jproject) throws CoreException { >+ IPath[] rtJarPath= findRtJar(RT_STUBS_18); >+ set18CompilerOptions(jproject); >+ return addLibrary(jproject, rtJarPath[0], rtJarPath[1], rtJarPath[2]); >+ } >+ > /** > * Adds a variable entry with source attachment to a IJavaProject. > * Can return null if variable can not be resolved.
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 405270
:
229660
|
229789
|
235215