Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 406786 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/defaultMethods18_in/A_test1.java (+7 lines)
Added Link Here
1
package defaultMethods_in;
2
3
public interface A_test1 {
4
	default int foo() {
5
		/*[*/return 0;/*]*/
6
	}
7
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/defaultMethods18_in/A_test1a.java (+7 lines)
Added Link Here
1
package defaultMethods_in;
2
3
public interface A_test1a {
4
	public default int foo() {
5
		/*[*/return 0;/*]*/
6
	}
7
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/defaultMethods18_in/A_test2.java (+9 lines)
Added Link Here
1
package defaultMethods_in;
2
3
public class A_test2 {
4
	interface B {
5
		default int foo() {
6
			/*[*/return 0;/*]*/
7
		}
8
	}
9
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/defaultMethods18_in/A_test2a.java (+9 lines)
Added Link Here
1
package defaultMethods_in;
2
3
public class A_test2a {
4
	interface B {
5
		public default int foo() {
6
			/*[*/return 0;/*]*/
7
		}
8
	}
9
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/defaultMethods18_in/A_test3.java (+9 lines)
Added Link Here
1
package defaultMethods_in;
2
3
public interface A_test3 {
4
	interface B {
5
		default int foo() {
6
			/*[*/return 0;/*]*/
7
		}
8
	}
9
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/defaultMethods18_in/A_test3a.java (+9 lines)
Added Link Here
1
package defaultMethods_in;
2
3
public interface A_test3a {
4
	interface B {
5
		public default int foo() {
6
			/*[*/return 0;/*]*/
7
		}
8
	}
9
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/defaultMethods18_in/A_test4.java (+12 lines)
Added Link Here
1
package staticMethods_in;
2
3
interface A_test4 {
4
	default void foo() {
5
		Runnable r= new Runnable() {
6
			@Override
7
			public void run() {
8
				/*[*/int i = 0;/*]*/
9
			}
10
		};		
11
	}
12
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/defaultMethods18_out/A_test1.java (+11 lines)
Added Link Here
1
package defaultMethods_out;
2
3
public interface A_test1 {
4
	default int foo() {
5
		return extracted();
6
	}
7
8
	default int extracted() {
9
		/*[*/return 0;/*]*/
10
	}
11
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/defaultMethods18_out/A_test1a.java (+11 lines)
Added Link Here
1
package defaultMethods_out;
2
3
public interface A_test1a {
4
	public default int foo() {
5
		return extracted();
6
	}
7
8
	public default int extracted() {
9
		/*[*/return 0;/*]*/
10
	}
11
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/defaultMethods18_out/A_test2.java (+13 lines)
Added Link Here
1
package defaultMethods_out;
2
3
public class A_test2 {
4
	interface B {
5
		default int foo() {
6
			return extracted();
7
		}
8
	}
9
10
	protected static int extracted() {
11
		/*[*/return 0;/*]*/
12
	}
13
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/defaultMethods18_out/A_test2a.java (+13 lines)
Added Link Here
1
package defaultMethods_out;
2
3
public class A_test2a {
4
	interface B {
5
		public default int foo() {
6
			return extracted();
7
		}
8
	}
9
10
	protected static int extracted() {
11
		/*[*/return 0;/*]*/
12
	}
13
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/defaultMethods18_out/A_test3.java (+13 lines)
Added Link Here
1
package defaultMethods_out;
2
3
public interface A_test3 {
4
	interface B {
5
		default int foo() {
6
			return extracted();
7
		}
8
	}
9
10
	static int extracted() {
11
		/*[*/return 0;/*]*/
12
	}
13
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/defaultMethods18_out/A_test3a.java (+13 lines)
Added Link Here
1
package defaultMethods_out;
2
3
public interface A_test3a {
4
	interface B {
5
		public default int foo() {
6
			return extracted();
7
		}
8
	}
9
10
	static int extracted() {
11
		/*[*/return 0;/*]*/
12
	}
13
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/defaultMethods18_out/A_test4.java (+16 lines)
Added Link Here
1
package staticMethods_in;
2
3
interface A_test4 {
4
	default void foo() {
5
		Runnable r= new Runnable() {
6
			@Override
7
			public void run() {
8
				extracted();
9
			}
10
		};		
11
	}
12
13
	default void extracted() {
14
		/*[*/int i = 0;/*]*/
15
	}
16
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/destination18_in/A_test201.java (+9 lines)
Added Link Here
1
package destination18_in;
2
3
public class A_test201 {
4
	interface B {
5
		@interface C {
6
			int i= /*[*/0;/*]*/
7
		}		
8
	}
9
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/destination18_in/A_test202.java (+11 lines)
Added Link Here
1
package destination_in;
2
3
public class A_test202 {
4
	@interface C {
5
		interface B {
6
			default void foo() {
7
				int i= /*[*/0;/*]*/				
8
			}
9
		}
10
	}		
11
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/destination18_in/A_test203.java (+11 lines)
Added Link Here
1
package destination_in;
2
3
public class A_test203 {
4
	@interface C {
5
		interface B {
6
			default void foo() {
7
				int i= /*[*/0;/*]*/				
8
			}
9
		}
10
	}		
11
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/destination18_in/A_test204.java (+9 lines)
Added Link Here
1
package destination18_in;
2
3
public class A_test204 {
4
	interface B {
5
		@interface C {
6
			int i= /*[*/0;/*]*/
7
		}		
8
	}
9
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/destination18_out/A_test201.java (+13 lines)
Added Link Here
1
package destination_in;
2
3
public class A_test201 {
4
	interface B {
5
		@interface C {
6
			int i= /*[*/extracted();/*]*/
7
		}
8
9
		static int extracted() {
10
			return 0;
11
		}		
12
	}
13
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/destination18_out/A_test202.java (+15 lines)
Added Link Here
1
package destination_in;
2
3
public class A_test202 {
4
	@interface C {
5
		interface B {
6
			default void foo() {
7
				int i= /*[*/extracted();/*]*/				
8
			}
9
10
			default int extracted() {
11
				return 0;
12
			}
13
		}
14
	}		
15
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/destination18_out/A_test203.java (+15 lines)
Added Link Here
1
package destination_in;
2
3
public class A_test203 {
4
	@interface C {
5
		interface B {
6
			default void foo() {
7
				int i= /*[*/extracted();/*]*/				
8
			}
9
		}
10
	}
11
12
	protected static int extracted() {
13
		return 0;
14
	}		
15
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/destination18_out/A_test204.java (+13 lines)
Added Link Here
1
package destination18_in;
2
3
public class A_test204 {
4
	interface B {
5
		@interface C {
6
			int i= /*[*/extracted();/*]*/
7
		}		
8
	}
9
10
	protected static int extracted() {
11
		return 0;
12
	}
13
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/destination_in/A_test1059.java (+9 lines)
Added Link Here
1
package destination_in;
2
3
public class A_test1059 {
4
	interface B {
5
		@interface C {
6
			int i= /*[*/0;/*]*/
7
		}		
8
	}
9
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/destination_in/A_test1060.java (+11 lines)
Added Link Here
1
package destination_in;
2
3
public class A_test1060 {
4
	interface B {
5
		class C {
6
			int foo() {
7
				/*[*/return 0;/*]*/
8
			}
9
		}
10
	}
11
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/destination_in/A_test1061.java (+11 lines)
Added Link Here
1
package destination_in;
2
3
public class A_test1061 {
4
	static class B {
5
		class C {
6
			int foo() {
7
				/*[*/return 0;/*]*/
8
			}
9
		}
10
	}
11
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/destination_in/A_test1062.java (+11 lines)
Added Link Here
1
package destination_in;
2
3
public class A_test1062 {
4
	static class B {
5
		class C {
6
			int foo() {
7
				/*[*/return 0;/*]*/
8
			}
9
		}
10
	}
11
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/destination_out/A_test1059.java (+13 lines)
Added Link Here
1
package destination_in;
2
3
public class A_test1059 {
4
	interface B {
5
		@interface C {
6
			int i= /*[*/extracted();/*]*/
7
		}		
8
	}
9
10
	protected static int extracted() {
11
		return 0;
12
	}
13
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/destination_out/A_test1060.java (+15 lines)
Added Link Here
1
package destination_in;
2
3
public class A_test1060 {
4
	interface B {
5
		class C {
6
			int foo() {
7
				return extracted();
8
			}
9
		}
10
	}
11
12
	protected static int extracted() {
13
		/*[*/return 0;/*]*/
14
	}
15
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/destination_out/A_test1061.java (+15 lines)
Added Link Here
1
package destination_in;
2
3
public class A_test1061 {
4
	static class B {
5
		class C {
6
			int foo() {
7
				return extracted();
8
			}
9
		}
10
11
		protected int extracted() {
12
			/*[*/return 0;/*]*/
13
		}
14
	}
15
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/destination_out/A_test1062.java (+15 lines)
Added Link Here
1
package destination_in;
2
3
public class A_test1062 {
4
	static class B {
5
		class C {
6
			int foo() {
7
				return extracted();
8
			}
9
		}
10
	}
11
12
	protected static int extracted() {
13
		/*[*/return 0;/*]*/
14
	}
15
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/staticMethods18_in/A_test101.java (+9 lines)
Added Link Here
1
package staticMethods_in;
2
3
public interface A_test101 {
4
	class B {
5
		int foo() {
6
			/*[*/return 0;/*]*/
7
		}
8
	}
9
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/staticMethods18_in/A_test102.java (+9 lines)
Added Link Here
1
package staticMethods_in;
2
3
interface A_test102 {
4
	class B {
5
		static {
6
			/*[*/int i= 0;/*]*/
7
		}
8
	}
9
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/staticMethods18_in/A_test103.java (+6 lines)
Added Link Here
1
package staticMethods_in;
2
3
interface A_test103 {
4
	int i= 0;
5
	int j= /*[*/i + 10;/*]*/
6
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/staticMethods18_in/A_test104.java (+11 lines)
Added Link Here
1
package staticMethods_in;
2
3
interface A_test104 {
4
	Runnable r= new Runnable() {
5
		@Override
6
		public void run() {
7
			/*[*/int i = 0;/*]*/
8
			System.out.println(i);
9
		}
10
	};
11
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/staticMethods18_in/A_test105.java (+11 lines)
Added Link Here
1
package staticMethods_in;
2
3
interface A_test105 {
4
	enum E {
5
		A {
6
			int foo() {
7
				/*[*/return 0;/*]*/
8
			}
9
		}
10
	}
11
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/staticMethods18_in/A_test106.java (+10 lines)
Added Link Here
1
package staticMethods_in;
2
3
interface A_test106 {
4
	enum E {
5
		A;
6
		int foo() {
7
			/*[*/return 0;/*]*/
8
		}
9
	}
10
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/staticMethods18_in/A_test107.java (+9 lines)
Added Link Here
1
package staticMethods_in;
2
3
interface A_test107 {
4
	class B {
5
		{
6
			/*[*/int i= 0;/*]*/
7
		}
8
	}
9
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/staticMethods18_out/A_test101.java (+13 lines)
Added Link Here
1
package staticMethods_out;
2
3
public interface A_test101 {
4
	class B {
5
		int foo() {
6
			return extracted();
7
		}
8
	}
9
10
	static int extracted() {
11
		/*[*/return 0;/*]*/
12
	}
13
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/staticMethods18_out/A_test102.java (+13 lines)
Added Link Here
1
package staticMethods_in;
2
3
interface A_test102 {
4
	class B {
5
		static {
6
			extracted();
7
		}
8
	}
9
10
	static void extracted() {
11
		/*[*/int i= 0;/*]*/
12
	}
13
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/staticMethods18_out/A_test103.java (+9 lines)
Added Link Here
1
package staticMethods_in;
2
3
interface A_test103 {
4
	int i= 0;
5
	int j= /*[*/extracted();/*]*/
6
	static int extracted() {
7
		return i + 10;
8
	}
9
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/staticMethods18_out/A_test104.java (+16 lines)
Added Link Here
1
package staticMethods_in;
2
3
interface A_test104 {
4
	static int extracted() {
5
		/*[*/int i = 0;/*]*/
6
		return i;
7
	}
8
9
	Runnable r= new Runnable() {
10
		@Override
11
		public void run() {
12
			int i = extracted();
13
			System.out.println(i);
14
		}
15
	};
16
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/staticMethods18_out/A_test105.java (+15 lines)
Added Link Here
1
package staticMethods_in;
2
3
interface A_test105 {
4
	enum E {
5
		A {
6
			int foo() {
7
				return extracted();
8
			}
9
		}
10
	}
11
12
	static int extracted() {
13
		/*[*/return 0;/*]*/
14
	}
15
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/staticMethods18_out/A_test106.java (+14 lines)
Added Link Here
1
package staticMethods_in;
2
3
interface A_test106 {
4
	enum E {
5
		A;
6
		int foo() {
7
			return extracted();
8
		}
9
	}
10
11
	static int extracted() {
12
		/*[*/return 0;/*]*/
13
	}
14
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/staticMethods18_out/A_test107.java (+13 lines)
Added Link Here
1
package staticMethods_in;
2
3
interface A_test107 {
4
	class B {
5
		{
6
			extracted();
7
		}
8
	}
9
10
	static void extracted() {
11
		/*[*/int i= 0;/*]*/
12
	}
13
}
(-)a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/AllRefactoringTests.java (-1 / +6 lines)
Lines 1-9 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
2
 * Copyright (c) 2000, 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
7
 *
11
 *
8
 * Contributors:
12
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
13
 *     IBM Corporation - initial API and implementation
Lines 24-29 Link Here
24
		//--code
28
		//--code
25
		suite.addTest(ExtractMethodTests.suite());
29
		suite.addTest(ExtractMethodTests.suite());
26
		suite.addTest(ExtractMethodTests17.suite());
30
		suite.addTest(ExtractMethodTests17.suite());
31
		suite.addTest(ExtractMethodTests18.suite());
27
		suite.addTest(InlineMethodTests.suite());
32
		suite.addTest(InlineMethodTests.suite());
28
		suite.addTest(ReplaceInvocationsTests.suite());
33
		suite.addTest(ReplaceInvocationsTests.suite());
29
		suite.addTest(SefTests.suite());
34
		suite.addTest(SefTests.suite());
(-)a/org.eclipse.jdt.ui.tests.refactoring/test (+57 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
11
 *
12
 * Contributors:
13
 *     IBM Corporation - initial API and implementation
14
 *******************************************************************************/
15
package org.eclipse.jdt.ui.tests.refactoring;
16
17
import junit.framework.Test;
18
19
import org.eclipse.ltk.core.refactoring.RefactoringCore;
20
21
import org.eclipse.jdt.core.IPackageFragment;
22
import org.eclipse.jdt.core.IPackageFragmentRoot;
23
24
public class ExtractMethodTestSetup18 extends Java18Setup {
25
26
	private IPackageFragment fDefaultMethodsPackage;
27
	private IPackageFragment fStaticMethodsPackage;
28
	private IPackageFragment fDestinationPackage;
29
30
	public ExtractMethodTestSetup18(Test test) {
31
		super(test);
32
	}
33
34
	protected void setUp() throws Exception {
35
		super.setUp();
36
37
		RefactoringCore.getUndoManager().flush();
38
39
		IPackageFragmentRoot root= getDefaultSourceFolder();
40
		fDefaultMethodsPackage= root.createPackageFragment("defaultMethods18_in", true, null);
41
		fStaticMethodsPackage= root.createPackageFragment("staticMethods18_in", true, null);
42
		fDestinationPackage= root.createPackageFragment("destination18_in", true, null);
43
	}
44
45
	public IPackageFragment getDefaultMethodsPackage() {
46
		return fDefaultMethodsPackage;
47
	}
48
49
	public IPackageFragment getStaticMethodsPackage() {
50
		return fStaticMethodsPackage;
51
	}
52
53
	public IPackageFragment getDestinationPackage() {
54
		return fDestinationPackage;
55
	}
56
}
57
(-)a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractMethodTests.java (-2 / +26 lines)
Lines 1-9 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
2
 * Copyright (c) 2000, 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
7
 *
11
 *
8
 * Contributors:
12
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
13
 *     IBM Corporation - initial API and implementation
Lines 84-94 Link Here
84
	}
88
	}
85
89
86
	protected void performTest(IPackageFragment packageFragment, String id, int mode, String outputFolder, String[] newNames, int[] newOrder, int destination) throws Exception {
90
	protected void performTest(IPackageFragment packageFragment, String id, int mode, String outputFolder, String[] newNames, int[] newOrder, int destination) throws Exception {
91
		performTest(packageFragment, id, mode, outputFolder, newNames, newOrder, destination, Modifier.PROTECTED);
92
	}
93
94
	protected void performTest(IPackageFragment packageFragment, String id, int mode, String outputFolder, String[] newNames, int[] newOrder, int destination, int visibility) throws Exception {
87
		ICompilationUnit unit= createCU(packageFragment, id);
95
		ICompilationUnit unit= createCU(packageFragment, id);
88
		int[] selection= getSelection();
96
		int[] selection= getSelection();
89
		ExtractMethodRefactoring refactoring= new ExtractMethodRefactoring(unit, selection[0], selection[1]);
97
		ExtractMethodRefactoring refactoring= new ExtractMethodRefactoring(unit, selection[0], selection[1]);
90
		refactoring.setMethodName("extracted");
98
		refactoring.setMethodName("extracted");
91
		refactoring.setVisibility(Modifier.PROTECTED);
99
		refactoring.setVisibility(visibility);
92
		TestModelProvider.clearDelta();
100
		TestModelProvider.clearDelta();
93
		RefactoringStatus status= refactoring.checkInitialConditions(new NullProgressMonitor());
101
		RefactoringStatus status= refactoring.checkInitialConditions(new NullProgressMonitor());
94
		switch (mode) {
102
		switch (mode) {
Lines 1974-1979 Link Here
1974
		destinationTest(2);
1982
		destinationTest(2);
1975
	}
1983
	}
1976
	
1984
	
1985
	public void test1059() throws Exception {
1986
		destinationTest(0);
1987
	}
1988
	
1989
	public void test1060() throws Exception {
1990
		destinationTest(1);
1991
	}
1992
	
1993
	public void test1061() throws Exception {
1994
		destinationTest(1);
1995
	}
1996
	
1997
	public void test1062() throws Exception {
1998
		destinationTest(2);
1999
	}
2000
	
1977
	//---- Test Generics --------------------------------------------------
2001
	//---- Test Generics --------------------------------------------------
1978
2002
1979
	public void test1100() throws Exception {
2003
	public void test1100() throws Exception {
(-)a/org.eclipse.jdt.ui.tests.refactoring/test (+133 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
11
 *
12
 * Contributors:
13
 *     IBM Corporation - initial API and implementation
14
 *******************************************************************************/
15
package org.eclipse.jdt.ui.tests.refactoring;
16
17
import junit.framework.Test;
18
19
import org.eclipse.jdt.core.dom.Modifier;
20
21
public class ExtractMethodTests18 extends ExtractMethodTests {
22
	private static ExtractMethodTestSetup18 fgTestSetup;
23
24
	public ExtractMethodTests18(String name) {
25
		super(name);
26
	}
27
28
	public static Test suite() {
29
		fgTestSetup= new ExtractMethodTestSetup18(new NoSuperTestsSuite(ExtractMethodTests18.class));
30
		return fgTestSetup;
31
	}
32
33
	public static Test setUpTest(Test test) {
34
		fgTestSetup= new ExtractMethodTestSetup18(test);
35
		return fgTestSetup;
36
	}
37
38
	protected void defaultMethodsTest(int destination, int visibility) throws Exception {
39
		performTest(fgTestSetup.getDefaultMethodsPackage(), "A", COMPARE_WITH_OUTPUT, "defaultMethods18_out", null, null, destination, visibility);
40
	}
41
42
	protected void staticMethodsTest(int destination, int visibility) throws Exception {
43
		performTest(fgTestSetup.getStaticMethodsPackage(), "A", COMPARE_WITH_OUTPUT, "staticMethods18_out", null, null, destination, visibility);
44
	}
45
46
	protected void destinationTest(int destination, int visibility) throws Exception {
47
		performTest(fgTestSetup.getDestinationPackage(), "A", COMPARE_WITH_OUTPUT, "destination18_out", null, null, destination, visibility);
48
	}
49
50
	//====================================================================================
51
	// Testing Default Methods
52
	//====================================================================================
53
54
	public void test1() throws Exception {
55
		defaultMethodsTest(0, Modifier.PUBLIC);
56
	}
57
58
	public void test1a() throws Exception {
59
		defaultMethodsTest(0, Modifier.PUBLIC);
60
	}
61
62
	public void test2() throws Exception {
63
		defaultMethodsTest(1, Modifier.PROTECTED);
64
	}
65
66
	public void test2a() throws Exception {
67
		defaultMethodsTest(1, Modifier.PROTECTED);
68
	}
69
70
	public void test3() throws Exception {
71
		defaultMethodsTest(1, Modifier.PUBLIC);
72
	}
73
74
	public void test3a() throws Exception {
75
		defaultMethodsTest(1, Modifier.PUBLIC);
76
	}
77
78
	public void test4() throws Exception {
79
		defaultMethodsTest(1, Modifier.PUBLIC);
80
	}
81
82
	//====================================================================================
83
	// Testing Static Methods
84
	//====================================================================================
85
86
	public void test101() throws Exception {
87
		staticMethodsTest(1, Modifier.PUBLIC);
88
	}
89
90
	public void test102() throws Exception {
91
		staticMethodsTest(1, Modifier.PUBLIC);
92
	}
93
94
	public void test103() throws Exception {
95
		staticMethodsTest(0, Modifier.PUBLIC);
96
	}
97
98
	public void test104() throws Exception {
99
		staticMethodsTest(1, Modifier.PUBLIC);
100
	}
101
102
	public void test105() throws Exception {
103
		staticMethodsTest(2, Modifier.PUBLIC);
104
	}
105
106
	public void test106() throws Exception {
107
		staticMethodsTest(1, Modifier.PUBLIC);
108
	}
109
110
	public void test107() throws Exception {
111
		staticMethodsTest(1, Modifier.PUBLIC);
112
	}
113
114
	//====================================================================================
115
	// Testing Destination Types
116
	//====================================================================================
117
118
	public void test201() throws Exception {
119
		destinationTest(0, Modifier.PUBLIC);
120
	}
121
122
	public void test202() throws Exception {
123
		destinationTest(0, Modifier.PUBLIC);
124
	}
125
126
	public void test203() throws Exception {
127
		destinationTest(1, Modifier.PROTECTED);
128
	}
129
130
	public void test204() throws Exception {
131
		destinationTest(1, Modifier.PROTECTED);
132
	}
133
}
(-)a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/Checks.java (-10 / +23 lines)
Lines 1-9 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
2
 * Copyright (c) 2000, 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
7
 *
11
 *
8
 * Contributors:
12
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
13
 *     IBM Corporation - initial API and implementation
Lines 310-322 Link Here
310
	 */
314
	 */
311
	public static RefactoringStatus checkMethodInType(ITypeBinding type, String methodName, ITypeBinding[] parameters) {
315
	public static RefactoringStatus checkMethodInType(ITypeBinding type, String methodName, ITypeBinding[] parameters) {
312
		RefactoringStatus result= new RefactoringStatus();
316
		RefactoringStatus result= new RefactoringStatus();
313
		if (methodName.equals(type.getName()))
314
			result.addWarning(RefactoringCoreMessages.Checks_methodName_constructor);
315
		IMethodBinding method= org.eclipse.jdt.internal.corext.dom.Bindings.findMethodInType(type, methodName, parameters);
317
		IMethodBinding method= org.eclipse.jdt.internal.corext.dom.Bindings.findMethodInType(type, methodName, parameters);
316
		if (method != null)
318
		if (method != null) {
317
			result.addError(Messages.format(RefactoringCoreMessages.Checks_methodName_exists,
319
			if (method.isConstructor()) {
318
				new Object[] {BasicElementLabels.getJavaElementName(methodName), BasicElementLabels.getJavaElementName(type.getName())}),
320
				result.addWarning(Messages.format(RefactoringCoreMessages.Checks_methodName_constructor,
319
				JavaStatusContext.create(method));
321
						new Object[] { BasicElementLabels.getJavaElementName(type.getName()) }));
322
			} else {
323
				result.addError(Messages.format(RefactoringCoreMessages.Checks_methodName_exists,
324
						new Object[] { BasicElementLabels.getJavaElementName(methodName), BasicElementLabels.getJavaElementName(type.getName()) }),
325
						JavaStatusContext.create(method));
326
			}
327
		}
320
		return result;
328
		return result;
321
	}
329
	}
322
330
Lines 354-362 Link Here
354
					new Object[] {BasicElementLabels.getJavaElementName(methodName), BasicElementLabels.getJavaElementName(dc.getName())}),
362
					new Object[] {BasicElementLabels.getJavaElementName(methodName), BasicElementLabels.getJavaElementName(dc.getName())}),
355
					JavaStatusContext.create(method));
363
					JavaStatusContext.create(method));
356
			} else {
364
			} else {
357
				result.addError(Messages.format(RefactoringCoreMessages.Checks_methodName_overrides,
365
				if (method.isConstructor()) {
358
					new Object[] {BasicElementLabels.getJavaElementName(methodName), BasicElementLabels.getJavaElementName(dc.getName())}),
366
					result.addWarning(Messages.format(RefactoringCoreMessages.Checks_methodName_constructor,
359
					JavaStatusContext.create(method));
367
							new Object[] { BasicElementLabels.getJavaElementName(dc.getName()) }));
368
				} else {
369
					result.addError(Messages.format(RefactoringCoreMessages.Checks_methodName_overrides,
370
							new Object[] { BasicElementLabels.getJavaElementName(methodName), BasicElementLabels.getJavaElementName(dc.getName()) }),
371
							JavaStatusContext.create(method));
372
				}
360
			}
373
			}
361
		}
374
		}
362
		return result;
375
		return result;
(-)a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/RefactoringCoreMessages.java (-1 / +7 lines)
Lines 1-9 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
2
 * Copyright (c) 2000, 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
7
 *
11
 *
8
 * Contributors:
12
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
13
 *     IBM Corporation - initial API and implementation
Lines 561-566 Link Here
561
565
562
	public static String ExtractMethodAnalyzer_leftHandSideOfAssignment;
566
	public static String ExtractMethodAnalyzer_leftHandSideOfAssignment;
563
567
568
	public static String ExtractMethodAnalyzer_no_valid_destination_type;
569
564
	public static String ExtractMethodAnalyzer_only_method_body;
570
	public static String ExtractMethodAnalyzer_only_method_body;
565
571
566
	public static String ExtractMethodAnalyzer_parent_mismatch;
572
	public static String ExtractMethodAnalyzer_parent_mismatch;
(-)a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractMethodAnalyzer.java (-2 / +35 lines)
Lines 1-9 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
2
 * Copyright (c) 2000, 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
7
 *
11
 *
8
 * Contributors:
12
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
13
 *     IBM Corporation - initial API and implementation
Lines 31-36 Link Here
31
import org.eclipse.jdt.core.dom.ASTNode;
35
import org.eclipse.jdt.core.dom.ASTNode;
32
import org.eclipse.jdt.core.dom.ASTVisitor;
36
import org.eclipse.jdt.core.dom.ASTVisitor;
33
import org.eclipse.jdt.core.dom.Annotation;
37
import org.eclipse.jdt.core.dom.Annotation;
38
import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration;
34
import org.eclipse.jdt.core.dom.AnonymousClassDeclaration;
39
import org.eclipse.jdt.core.dom.AnonymousClassDeclaration;
35
import org.eclipse.jdt.core.dom.Assignment;
40
import org.eclipse.jdt.core.dom.Assignment;
36
import org.eclipse.jdt.core.dom.Block;
41
import org.eclipse.jdt.core.dom.Block;
Lines 64-69 Link Here
64
import org.eclipse.jdt.core.dom.ThisExpression;
69
import org.eclipse.jdt.core.dom.ThisExpression;
65
import org.eclipse.jdt.core.dom.TryStatement;
70
import org.eclipse.jdt.core.dom.TryStatement;
66
import org.eclipse.jdt.core.dom.Type;
71
import org.eclipse.jdt.core.dom.Type;
72
import org.eclipse.jdt.core.dom.TypeDeclaration;
67
import org.eclipse.jdt.core.dom.VariableDeclaration;
73
import org.eclipse.jdt.core.dom.VariableDeclaration;
68
import org.eclipse.jdt.core.dom.VariableDeclarationExpression;
74
import org.eclipse.jdt.core.dom.VariableDeclarationExpression;
69
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
75
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
Lines 86-95 Link Here
86
import org.eclipse.jdt.internal.corext.refactoring.code.flow.InOutFlowAnalyzer;
92
import org.eclipse.jdt.internal.corext.refactoring.code.flow.InOutFlowAnalyzer;
87
import org.eclipse.jdt.internal.corext.refactoring.code.flow.InputFlowAnalyzer;
93
import org.eclipse.jdt.internal.corext.refactoring.code.flow.InputFlowAnalyzer;
88
import org.eclipse.jdt.internal.corext.refactoring.util.CodeAnalyzer;
94
import org.eclipse.jdt.internal.corext.refactoring.util.CodeAnalyzer;
95
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
89
import org.eclipse.jdt.internal.corext.util.Messages;
96
import org.eclipse.jdt.internal.corext.util.Messages;
90
97
91
import org.eclipse.jdt.ui.JavaElementLabels;
98
import org.eclipse.jdt.ui.JavaElementLabels;
92
99
100
import org.eclipse.jdt.internal.ui.text.correction.ASTResolving;
93
import org.eclipse.jdt.internal.ui.viewsupport.BasicElementLabels;
101
import org.eclipse.jdt.internal.ui.viewsupport.BasicElementLabels;
94
import org.eclipse.jdt.internal.ui.viewsupport.BindingLabelProvider;
102
import org.eclipse.jdt.internal.ui.viewsupport.BindingLabelProvider;
95
103
Lines 198-208 Link Here
198
206
199
	//---- Activation checking ---------------------------------------------------------------------------
207
	//---- Activation checking ---------------------------------------------------------------------------
200
208
209
	boolean isValidDestination(ASTNode node) {
210
		boolean isInterface= node instanceof TypeDeclaration && ((TypeDeclaration) node).isInterface();
211
		return !(node instanceof AnnotationTypeDeclaration) &&
212
				!(isInterface && !JavaModelUtil.is18OrHigher(fCUnit.getJavaProject()));
213
	}
214
201
	public RefactoringStatus checkInitialConditions(ImportRewrite rewriter) {
215
	public RefactoringStatus checkInitialConditions(ImportRewrite rewriter) {
202
		RefactoringStatus result= getStatus();
216
		RefactoringStatus result= getStatus();
203
		checkExpression(result);
217
		checkExpression(result);
204
		if (result.hasFatalError())
218
		if (result.hasFatalError())
205
			return result;
219
			return result;
220
221
		List<ASTNode> validDestinations= new ArrayList<ASTNode>();
222
		ASTNode destination= ASTResolving.findParentType(fEnclosingBodyDeclaration.getParent());
223
		while (destination != null) {
224
			if (isValidDestination(destination)) {
225
				validDestinations.add(destination);
226
			}
227
			destination= ASTResolving.findParentType(destination.getParent());
228
		}
229
		if (validDestinations.size() == 0) {
230
			result.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_no_valid_destination_type);
231
			return result;
232
		}
206
233
207
		fReturnKind= UNDEFINED;
234
		fReturnKind= UNDEFINED;
208
		fMaxVariableId= LocalVariableIndex.perform(fEnclosingBodyDeclaration);
235
		fMaxVariableId= LocalVariableIndex.perform(fEnclosingBodyDeclaration);
Lines 318-324 Link Here
318
		ITypeBinding[] arguments= getArgumentTypes();
345
		ITypeBinding[] arguments= getArgumentTypes();
319
		ITypeBinding type= ASTNodes.getEnclosingType(destination);
346
		ITypeBinding type= ASTNodes.getEnclosingType(destination);
320
		status.merge(Checks.checkMethodInType(type, methodName, arguments));
347
		status.merge(Checks.checkMethodInType(type, methodName, arguments));
321
		status.merge(Checks.checkMethodInHierarchy(type.getSuperclass(), methodName, null, arguments));
348
		ITypeBinding superClass= type.getSuperclass();
349
		if (superClass != null) {
350
			status.merge(Checks.checkMethodInHierarchy(superClass, methodName, null, arguments));			
351
		}
352
		for (ITypeBinding superInterface : type.getInterfaces()) {
353
			status.merge(Checks.checkMethodInHierarchy(superInterface, methodName, null, arguments));
354
		}
322
	}
355
	}
323
356
324
	private ITypeBinding[] getArgumentTypes() {
357
	private ITypeBinding[] getArgumentTypes() {
(-)a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractMethodRefactoring.java (-28 / +41 lines)
Lines 1-9 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
2
 * Copyright (c) 2000, 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
7
 *
11
 *
8
 * Contributors:
12
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
13
 *     IBM Corporation - initial API and implementation
Lines 75-81 Link Here
75
import org.eclipse.jdt.core.dom.MethodDeclaration;
79
import org.eclipse.jdt.core.dom.MethodDeclaration;
76
import org.eclipse.jdt.core.dom.MethodInvocation;
80
import org.eclipse.jdt.core.dom.MethodInvocation;
77
import org.eclipse.jdt.core.dom.Modifier;
81
import org.eclipse.jdt.core.dom.Modifier;
78
import org.eclipse.jdt.core.dom.Name;
79
import org.eclipse.jdt.core.dom.ParenthesizedExpression;
82
import org.eclipse.jdt.core.dom.ParenthesizedExpression;
80
import org.eclipse.jdt.core.dom.QualifiedName;
83
import org.eclipse.jdt.core.dom.QualifiedName;
81
import org.eclipse.jdt.core.dom.ReturnStatement;
84
import org.eclipse.jdt.core.dom.ReturnStatement;
Lines 528-534 Link Here
528
			TextEditGroup insertDesc= new TextEditGroup(Messages.format(RefactoringCoreMessages.ExtractMethodRefactoring_add_method, BasicElementLabels.getJavaElementName(fMethodName)));
531
			TextEditGroup insertDesc= new TextEditGroup(Messages.format(RefactoringCoreMessages.ExtractMethodRefactoring_add_method, BasicElementLabels.getJavaElementName(fMethodName)));
529
			result.addTextEditGroup(insertDesc);
532
			result.addTextEditGroup(insertDesc);
530
533
531
			if (fDestination == fDestinations[0]) {
534
			if (fDestination == ASTResolving.findParentType(declaration.getParent())) {
532
				ChildListPropertyDescriptor desc= (ChildListPropertyDescriptor)declaration.getLocationInParent();
535
				ChildListPropertyDescriptor desc= (ChildListPropertyDescriptor)declaration.getLocationInParent();
533
				ListRewrite container= fRewriter.getListRewrite(declaration.getParent(), desc);
536
				ListRewrite container= fRewriter.getListRewrite(declaration.getParent(), desc);
534
				container.insertAfter(mm, declaration, insertDesc);
537
				container.insertAfter(mm, declaration, insertDesc);
Lines 741-746 Link Here
741
		return fGenerateJavadoc;
744
		return fGenerateJavadoc;
742
	}
745
	}
743
746
747
	public boolean isDestinationInterface() {
748
		return fDestination instanceof TypeDeclaration && ((TypeDeclaration) fDestination).isInterface();
749
	}
750
744
	//---- Helper methods ------------------------------------------------------------------------
751
	//---- Helper methods ------------------------------------------------------------------------
745
752
746
	private void initializeParameterInfos() {
753
	private void initializeParameterInfos() {
Lines 789-815 Link Here
789
	private void initializeDestinations() {
796
	private void initializeDestinations() {
790
		List<ASTNode> result= new ArrayList<ASTNode>();
797
		List<ASTNode> result= new ArrayList<ASTNode>();
791
		BodyDeclaration decl= fAnalyzer.getEnclosingBodyDeclaration();
798
		BodyDeclaration decl= fAnalyzer.getEnclosingBodyDeclaration();
792
		ASTNode current= getNextParent(decl);
799
		ASTNode current= ASTResolving.findParentType(decl.getParent());
793
		result.add(current);
800
		if (fAnalyzer.isValidDestination(current)) {
794
		if (decl instanceof MethodDeclaration || decl instanceof Initializer || decl instanceof FieldDeclaration) {
801
			result.add(current);
802
		}
803
		if (current != null && (decl instanceof MethodDeclaration || decl instanceof Initializer || decl instanceof FieldDeclaration)) {
795
			ITypeBinding binding= ASTNodes.getEnclosingType(current);
804
			ITypeBinding binding= ASTNodes.getEnclosingType(current);
796
			ASTNode next= getNextParent(current);
805
			ASTNode next= ASTResolving.findParentType(current.getParent());
797
			while (next != null && binding != null && binding.isNested()) {
806
			while (next != null && binding != null && binding.isNested()) {
798
				result.add(next);
807
				if (fAnalyzer.isValidDestination(next)) {
808
					result.add(next);
809
				}
799
				current= next;
810
				current= next;
800
				binding= ASTNodes.getEnclosingType(current);
811
				binding= ASTNodes.getEnclosingType(current);
801
				next= getNextParent(next);
812
				next= ASTResolving.findParentType(next.getParent());
802
			}
813
			}
803
		}
814
		}
804
		fDestinations= result.toArray(new ASTNode[result.size()]);
815
		fDestinations= result.toArray(new ASTNode[result.size()]);
805
		fDestination= fDestinations[fDestinationIndex];
816
		fDestination= fDestinations[fDestinationIndex];
806
	}
807
808
	private ASTNode getNextParent(ASTNode node) {
809
		do {
810
			node= node.getParent();
811
		} while (node != null && !(node instanceof AbstractTypeDeclaration || node instanceof AnonymousClassDeclaration));
812
		return node;
813
	}
817
	}
814
818
815
	private RefactoringStatus mergeTextSelectionStatus(RefactoringStatus status) {
819
	private RefactoringStatus mergeTextSelectionStatus(RefactoringStatus status) {
Lines 974-991 Link Here
974
		MethodDeclaration result= fAST.newMethodDeclaration();
978
		MethodDeclaration result= fAST.newMethodDeclaration();
975
979
976
		int modifiers= fVisibility;
980
		int modifiers= fVisibility;
977
		ASTNode enclosingBodyDeclaration= fAnalyzer.getEnclosingBodyDeclaration();
981
		BodyDeclaration enclosingBodyDeclaration= fAnalyzer.getEnclosingBodyDeclaration();
978
		while (enclosingBodyDeclaration != null && enclosingBodyDeclaration.getParent() != fDestination) {
982
		boolean isDestinationInterface= isDestinationInterface();
979
			enclosingBodyDeclaration= enclosingBodyDeclaration.getParent();
983
		if (isDestinationInterface && !(enclosingBodyDeclaration instanceof MethodDeclaration &&
984
				enclosingBodyDeclaration.getParent() == fDestination &&
985
				Modifier.isPublic(enclosingBodyDeclaration.getModifiers()))) {
986
			modifiers= Modifier.NONE;
980
		}
987
		}
981
		if (enclosingBodyDeclaration instanceof BodyDeclaration) { // should always be the case
988
982
			int enclosingModifiers= ((BodyDeclaration)enclosingBodyDeclaration).getModifiers();
989
		boolean shouldBeStatic= false;
983
			boolean shouldBeStatic= Modifier.isStatic(enclosingModifiers)
990
		ASTNode currentParent= enclosingBodyDeclaration;
984
					|| enclosingBodyDeclaration instanceof EnumDeclaration
991
		do {
985
					|| fAnalyzer.getForceStatic();
992
			if (currentParent instanceof BodyDeclaration) {
986
			if (shouldBeStatic) {
993
				shouldBeStatic= shouldBeStatic || JdtFlags.isStatic((BodyDeclaration) currentParent);
987
				modifiers|= Modifier.STATIC;
988
			}
994
			}
995
			currentParent= currentParent.getParent();
996
		} while (!shouldBeStatic && currentParent != null && currentParent != fDestination);
997
998
		if (shouldBeStatic || fAnalyzer.getForceStatic()) {
999
			modifiers|= Modifier.STATIC;
1000
		} else if (isDestinationInterface) {
1001
			modifiers|= Modifier.DEFAULT;
989
		}
1002
		}
990
1003
991
		ITypeBinding[] typeVariables= computeLocalTypeVariables();
1004
		ITypeBinding[] typeVariables= computeLocalTypeVariables();
Lines 1018-1028 Link Here
1018
			parameters.add(parameter);
1031
			parameters.add(parameter);
1019
		}
1032
		}
1020
1033
1021
		List<Name> exceptions= result.thrownExceptions();
1034
		List<Type> exceptions= result.thrownExceptionTypes();
1022
		ITypeBinding[] exceptionTypes= fAnalyzer.getExceptions(fThrowRuntimeExceptions);
1035
		ITypeBinding[] exceptionTypes= fAnalyzer.getExceptions(fThrowRuntimeExceptions);
1023
		for (int i= 0; i < exceptionTypes.length; i++) {
1036
		for (int i= 0; i < exceptionTypes.length; i++) {
1024
			ITypeBinding exceptionType= exceptionTypes[i];
1037
			ITypeBinding exceptionType= exceptionTypes[i];
1025
			exceptions.add(ASTNodeFactory.newName(fAST, fImportRewriter.addImport(exceptionType, context)));
1038
			exceptions.add(ASTNodeFactory.newType(fAST, fImportRewriter.addImport(exceptionType, context)));
1026
		}
1039
		}
1027
		return result;
1040
		return result;
1028
	}
1041
	}
(-)a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/refactoring.properties (-3 / +4 lines)
Lines 36-42 Link Here
36
Checks_no_dot=Type name cannot contain a dot (.).
36
Checks_no_dot=Type name cannot contain a dot (.).
37
Checks_cu_name_used=Compilation unit ''{0}'' already exists
37
Checks_cu_name_used=Compilation unit ''{0}'' already exists
38
Checks_method_native=Method ''{1}'' in type ''{0}'' is native. Running the modified program will cause {2}.
38
Checks_method_native=Method ''{1}'' in type ''{0}'' is native. Running the modified program will cause {2}.
39
Checks_methodName_constructor=New method name has constructor name.
39
Checks_methodName_constructor=New method has same name as constructor of type ''{0}''.
40
Checks_methodName_exists=Method ''{0}'' already exists in type ''{1}''.
40
Checks_methodName_exists=Method ''{0}'' already exists in type ''{1}''.
41
Checks_methodName_overrides=New method ''{0}'' overrides an existing method in type ''{1}''.
41
Checks_methodName_overrides=New method ''{0}'' overrides an existing method in type ''{1}''.
42
Checks_methodName_returnTypeClash=New method ''{0}'' overrides a method declared in type ''{1}'' that uses a different return type.
42
Checks_methodName_returnTypeClash=New method ''{0}'' overrides a method declared in type ''{1}'' that uses a different return type.
Lines 124-137 Link Here
124
ExtractMethodAnalyzer_cannot_extract_type_reference=Cannot extract a single type reference.
124
ExtractMethodAnalyzer_cannot_extract_type_reference=Cannot extract a single type reference.
125
ExtractMethodAnalyzer_cannot_extract_switch_case=Cannot extract the expression of a case statement.
125
ExtractMethodAnalyzer_cannot_extract_switch_case=Cannot extract the expression of a case statement.
126
ExtractMethodAnalyzer_cannot_extract_method_name_reference=Cannot extract a single method name.
126
ExtractMethodAnalyzer_cannot_extract_method_name_reference=Cannot extract a single method name.
127
ExtractMethodAnalyzer_cannot_extract_part_of_qualified_name=Can not extract part of a qualified name
127
ExtractMethodAnalyzer_cannot_extract_part_of_qualified_name=Cannot extract part of a qualified name
128
ExtractMethodAnalyzer_cannot_extract_name_in_declaration=Cannot extract the name part of a declaration.
128
ExtractMethodAnalyzer_cannot_extract_name_in_declaration=Cannot extract the name part of a declaration.
129
ExtractMethodAnalyzer_compile_errors_no_parent_binding=The selection cannot cannot be analyzed because of compilation errors in the enclosing type. To perform the operation you will need to fix the errors.
129
ExtractMethodAnalyzer_compile_errors_no_parent_binding=The selection cannot be analyzed because of compilation errors in the enclosing type. To perform the operation you will need to fix the errors.
130
ExtractMethodAnalyzer_ambiguous_return_value=Ambiguous return value: Expression, access to local or return statement extracted.
130
ExtractMethodAnalyzer_ambiguous_return_value=Ambiguous return value: Expression, access to local or return statement extracted.
131
ExtractMethodAnalyzer_compile_errors=The method''s body cannot be analyzed because of compilation errors in method ''{0}''. To perform the operation you will need to fix the errors.
131
ExtractMethodAnalyzer_compile_errors=The method''s body cannot be analyzed because of compilation errors in method ''{0}''. To perform the operation you will need to fix the errors.
132
ExtractMethodAnalyzer_leftHandSideOfAssignment=Cannot extract the left-hand side of an assignment.
132
ExtractMethodAnalyzer_leftHandSideOfAssignment=Cannot extract the left-hand side of an assignment.
133
ExtractMethodAnalyzer_single_expression_or_set=Can only extract a single expression or a set of statements.
133
ExtractMethodAnalyzer_single_expression_or_set=Can only extract a single expression or a set of statements.
134
ExtractMethodAnalyzer_cannot_extract_null_type=Cannot extract null expression.
134
ExtractMethodAnalyzer_cannot_extract_null_type=Cannot extract null expression.
135
ExtractMethodAnalyzer_no_valid_destination_type=No valid destination type exists.
135
ExtractMethodAnalyzer_resource_in_try_with_resources=Cannot extract a resource declared in a 'try-with-resources' statement.
136
ExtractMethodAnalyzer_resource_in_try_with_resources=Cannot extract a resource declared in a 'try-with-resources' statement.
136
137
137
ExtractMethodRefactoring_name=Extract Method
138
ExtractMethodRefactoring_name=Extract Method
(-)a/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/code/ExtractMethodInputPage.java (-7 / +43 lines)
Lines 1-9 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
2
 * Copyright (c) 2000, 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
7
 *
11
 *
8
 * Contributors:
12
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
13
 *     IBM Corporation - initial API and implementation
Lines 24-29 Link Here
24
import org.eclipse.swt.widgets.Button;
28
import org.eclipse.swt.widgets.Button;
25
import org.eclipse.swt.widgets.Combo;
29
import org.eclipse.swt.widgets.Combo;
26
import org.eclipse.swt.widgets.Composite;
30
import org.eclipse.swt.widgets.Composite;
31
import org.eclipse.swt.widgets.Control;
27
import org.eclipse.swt.widgets.Label;
32
import org.eclipse.swt.widgets.Label;
28
import org.eclipse.swt.widgets.Text;
33
import org.eclipse.swt.widgets.Text;
29
34
Lines 70-75 Link Here
70
	private boolean fFirstTime;
75
	private boolean fFirstTime;
71
	private JavaSourceViewer fSignaturePreview;
76
	private JavaSourceViewer fSignaturePreview;
72
	private IDialogSettings fSettings;
77
	private IDialogSettings fSettings;
78
	private Composite accessModifiersGroup;
73
79
74
	private static final String DESCRIPTION = RefactoringMessages.ExtractMethodInputPage_description;
80
	private static final String DESCRIPTION = RefactoringMessages.ExtractMethodInputPage_description;
75
	private static final String THROW_RUNTIME_EXCEPTIONS= "ThrowRuntimeExceptions"; //$NON-NLS-1$
81
	private static final String THROW_RUNTIME_EXCEPTIONS= "ThrowRuntimeExceptions"; //$NON-NLS-1$
Lines 121-126 Link Here
121
				@Override
127
				@Override
122
				public void widgetSelected(SelectionEvent e) {
128
				public void widgetSelected(SelectionEvent e) {
123
					fRefactoring.setDestination(combo.getSelectionIndex());
129
					fRefactoring.setDestination(combo.getSelectionIndex());
130
					updateAccessModifiers();
124
					updatePreview(getText());
131
					updatePreview(getText());
125
				}
132
				}
126
			});
133
			});
Lines 129-139 Link Here
129
		label= new Label(result, SWT.NONE);
136
		label= new Label(result, SWT.NONE);
130
		label.setText(RefactoringMessages.ExtractMethodInputPage_access_Modifiers);
137
		label.setText(RefactoringMessages.ExtractMethodInputPage_access_Modifiers);
131
138
132
		Composite group= new Composite(result, SWT.NONE);
139
		accessModifiersGroup= new Composite(result, SWT.NONE);
133
		group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
140
		accessModifiersGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
134
		layout= new GridLayout();
141
		layout= new GridLayout();
135
		layout.numColumns= 4; layout.marginWidth= 0;
142
		layout.numColumns= 4; layout.marginWidth= 0;
136
		group.setLayout(layout);
143
		accessModifiersGroup.setLayout(layout);
137
144
138
		String[] labels= new String[] {
145
		String[] labels= new String[] {
139
			RefactoringMessages.ExtractMethodInputPage_public,
146
			RefactoringMessages.ExtractMethodInputPage_public,
Lines 144-150 Link Here
144
		Integer[] data= new Integer[] {new Integer(Modifier.PUBLIC), new Integer(Modifier.PROTECTED), new Integer(Modifier.NONE), new Integer(Modifier.PRIVATE)};
151
		Integer[] data= new Integer[] {new Integer(Modifier.PUBLIC), new Integer(Modifier.PROTECTED), new Integer(Modifier.NONE), new Integer(Modifier.PRIVATE)};
145
		Integer visibility= new Integer(fRefactoring.getVisibility());
152
		Integer visibility= new Integer(fRefactoring.getVisibility());
146
		for (int i= 0; i < labels.length; i++) {
153
		for (int i= 0; i < labels.length; i++) {
147
			Button radio= new Button(group, SWT.RADIO);
154
			Button radio= new Button(accessModifiersGroup, SWT.RADIO);
148
			radio.setText(labels[i]);
155
			radio.setText(labels[i]);
149
			radio.setData(data[i]);
156
			radio.setData(data[i]);
150
			if (data[i].equals(visibility))
157
			if (data[i].equals(visibility))
Lines 158-164 Link Here
158
				}
165
				}
159
			});
166
			});
160
		}
167
		}
161
		layouter.perform(label, group, 1);
168
		updateAccessModifiers();
169
		layouter.perform(label, accessModifiersGroup, 1);
162
170
163
		if (!fRefactoring.getParameterInfos().isEmpty()) {
171
		if (!fRefactoring.getParameterInfos().isEmpty()) {
164
			ChangeParametersControl cp= new ChangeParametersControl(result, SWT.NONE,
172
			ChangeParametersControl cp= new ChangeParametersControl(result, SWT.NONE,
Lines 234-240 Link Here
234
		Dialog.applyDialogFont(result);
242
		Dialog.applyDialogFont(result);
235
		PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaHelpContextIds.EXTRACT_METHOD_WIZARD_PAGE);
243
		PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaHelpContextIds.EXTRACT_METHOD_WIZARD_PAGE);
236
	}
244
	}
237
245
	
246
	private void updateAccessModifiers() {
247
		final Control[] radioButtons= accessModifiersGroup.getChildren();
248
		if (fRefactoring.isDestinationInterface()) {
249
			Integer visibility= new Integer(Modifier.PUBLIC);
250
			fRefactoring.setVisibility(visibility.intValue());
251
			for (int i= 0; i < radioButtons.length; i++) {
252
				radioButtons[i].setEnabled(false);
253
				if (radioButtons[i].getData().equals(visibility)) {
254
					((Button) radioButtons[i]).setSelection(true);
255
				} else {
256
					((Button) radioButtons[i]).setSelection(false);
257
				}
258
			}
259
		} else {
260
			final String accessModifier= fSettings.get(ACCESS_MODIFIER);
261
			Integer visibility= accessModifier != null ? new Integer(accessModifier) : new Integer(fRefactoring.getVisibility());
262
			fRefactoring.setVisibility(visibility.intValue());
263
			for (int i= 0; i < radioButtons.length; i++) {
264
				radioButtons[i].setEnabled(true);
265
				if (radioButtons[i].getData().equals(visibility)) {
266
					((Button) radioButtons[i]).setSelection(true);
267
				} else {
268
					((Button) radioButtons[i]).setSelection(false);
269
				}
270
			}
271
		}
272
	}
273
	
238
	private String getLabel(ASTNode node) {
274
	private String getLabel(ASTNode node) {
239
		if (node instanceof AbstractTypeDeclaration) {
275
		if (node instanceof AbstractTypeDeclaration) {
240
			return ((AbstractTypeDeclaration)node).getName().getIdentifier();
276
			return ((AbstractTypeDeclaration)node).getName().getIdentifier();
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/ASTProvider.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
2
 * Copyright (c) 2000, 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 202-208 Link Here
202
		}
202
		}
203
	}
203
	}
204
204
205
	public static final int SHARED_AST_LEVEL= AST.JLS4;
205
	public static final int SHARED_AST_LEVEL= AST.JLS8;
206
	public static final boolean SHARED_AST_STATEMENT_RECOVERY= true;
206
	public static final boolean SHARED_AST_STATEMENT_RECOVERY= true;
207
	public static final boolean SHARED_BINDING_RECOVERY= true;
207
	public static final boolean SHARED_BINDING_RECOVERY= true;
208
208
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ASTResolving.java (-4 / +19 lines)
Lines 5-10 Link Here
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
11
 *
8
 * Contributors:
12
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
13
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
14
 *******************************************************************************/
Lines 651-661 Link Here
651
	}
655
	}
652
656
653
	/**
657
	/**
654
	 * Finds the parent type of a node.
658
	 * Finds the ancestor type of <code>node</code> (includes <code>node</code> in the search).
655
	 *
659
	 *
656
	 * @param node the node inside the type to find
660
	 * @param node the node to start the search from, can be <code>null</code>
657
	 * @param treatModifiersOutside if set, modifiers are not part of their type, but of the type's parent
661
	 * @param treatModifiersOutside if set, modifiers are not part of their type, but of the type's
658
	 * @return returns either a AbstractTypeDeclaration or an AnonymousTypeDeclaration
662
	 *            parent
663
	 * @return returns the ancestor type of <code>node</code> (AbstractTypeDeclaration or
664
	 *         AnonymousTypeDeclaration) if any (including <code>node</code>), <code>null</code>
665
	 *         otherwise
659
	 */
666
	 */
660
	public static ASTNode findParentType(ASTNode node, boolean treatModifiersOutside) {
667
	public static ASTNode findParentType(ASTNode node, boolean treatModifiersOutside) {
661
		StructuralPropertyDescriptor lastLocation= null;
668
		StructuralPropertyDescriptor lastLocation= null;
Lines 675-680 Link Here
675
		return null;
682
		return null;
676
	}
683
	}
677
684
685
	/**
686
	 * Finds the ancestor type of <code>node</code> (includes <code>node</code> in the search).
687
	 *
688
	 * @param node the node to start the search from, can be <code>null</code>
689
	 * @return returns the ancestor type of <code>node</code> (AbstractTypeDeclaration or
690
	 *         AnonymousTypeDeclaration) if any (including <code>node</code>), <code>null</code>
691
	 *         otherwise
692
	 */
678
	public static ASTNode findParentType(ASTNode node) {
693
	public static ASTNode findParentType(ASTNode node) {
679
		return findParentType(node, false);
694
		return findParentType(node, false);
680
	}
695
	}

Return to bug 406786