View | Details | Raw Unified | Return to bug 405270 | Differences between
and this patch

Collapse All | Expand All

(-)resources/ReceiverParameter/testExtractInterface/in/A.java (+9 lines)
Added Link Here
1
package p;
2
@Target({ ElementType.TYPE_USE, ElementType.METHOD })
3
@interface NonNull {
4
5
}
6
class A{	
7
	public void foo1(@NonNull  A this){}
8
	public void foo2(@NonNull  A this, String s){}
9
}
(-)resources/ReceiverParameter/testExtractInterface/out/A.java (+15 lines)
Added Link Here
1
package p;
2
@Target({ ElementType.TYPE_USE, ElementType.METHOD })
3
@interface NonNull {
4
5
}
6
class A implements I{	
7
	/* (non-Javadoc)
8
	 * @see p.I#foo1()
9
	 */
10
	public void foo1(@NonNull  A this){}
11
	/* (non-Javadoc)
12
	 * @see p.I#foo2(java.lang.String)
13
	 */
14
	public void foo2(@NonNull  A this, String s){}
15
}
(-)resources/ReceiverParameter/testExtractInterface/out/I.java (+10 lines)
Added Link Here
1
package p;
2
3
/** typecomment template*/
4
interface I {
5
6
	public abstract void foo1(@NonNull I this);
7
8
	public abstract void foo2(@NonNull I this, String s);
9
10
}
(-)resources/ReceiverParameter/testExtractSuperclass/in/A.java (+14 lines)
Added Link Here
1
package p;
2
@Target({ ElementType.TYPE_USE, ElementType.METHOD })
3
@interface NonNull {
4
5
}
6
class A{
7
	void foo1(@NonNull A this){
8
		System.out.println("foo1");
9
	}
10
	void foo2(@NonNull A this, String s){
11
		System.out.println("foo2");
12
	}
13
	
14
}
(-)resources/ReceiverParameter/testExtractSuperclass/out/A.java (+8 lines)
Added Link Here
1
package p;
2
@Target({ ElementType.TYPE_USE, ElementType.METHOD })
3
@interface NonNull {
4
5
}
6
class A extends B{
7
	
8
}
(-)resources/ReceiverParameter/testExtractSuperclass/out/B.java (+17 lines)
Added Link Here
1
package p;
2
3
public class B {
4
5
	public B() {
6
		super();
7
	}
8
9
	void foo1(@NonNull B this) {
10
		System.out.println("foo1");
11
	}
12
13
	void foo2(@NonNull B this, String s) {
14
		System.out.println("foo2");
15
	}
16
17
}
(-)resources/ReceiverParameter/testMove/in/A.java (+19 lines)
Added Link Here
1
package p1;
2
3
import java.lang.annotation.ElementType;
4
import java.lang.annotation.Target;
5
6
@Target({ ElementType.TYPE_USE, ElementType.METHOD })
7
@interface NonNull {
8
9
}
10
public class A {
11
12
	public void mA1(@NonNull A this, B b) {
13
		b.mB1();
14
		System.out.println(b + "j");
15
	}
16
	
17
	public void mA2() {}
18
19
}
(-)resources/ReceiverParameter/testMove/in/B.java (+7 lines)
Added Link Here
1
package p1;
2
3
public class B {
4
	public void mB1() {}
5
	
6
	public void mB2() {}
7
}
(-)resources/ReceiverParameter/testMove/out/A.java (+18 lines)
Added Link Here
1
package p1;
2
3
import java.lang.annotation.ElementType;
4
import java.lang.annotation.Target;
5
6
@Target({ ElementType.TYPE_USE, ElementType.METHOD })
7
@interface NonNull {
8
9
}
10
public class A {
11
12
	public void mA1(@NonNull A this, B b) {
13
		b.mA1Moved();
14
	}
15
	
16
	public void mA2() {}
17
18
}
(-)resources/ReceiverParameter/testMove/out/B.java (+13 lines)
Added Link Here
1
package p1;
2
3
public class B {
4
	public void mB1() {}
5
	
6
	public void mB2() {}
7
8
	public void mA1Moved(@NonNull
9
	B this) {
10
		mB1();
11
		System.out.println(this + "j");
12
	}
13
}
(-)resources/ReceiverParameter/testMoveType2File/in/A.java (+14 lines)
Added Link Here
1
package p;
2
@Target({ ElementType.TYPE_USE, ElementType.METHOD })
3
@interface NonNull {
4
5
}
6
class A{
7
8
class Inner{
9
	Inner(@NonNull A A.this){}
10
	public void foo1(@NonNull Inner this){
11
		System.out.println("Hello");
12
	}
13
}
14
}
(-)resources/ReceiverParameter/testMoveType2File/out/A.java (+7 lines)
Added Link Here
1
package p;
2
@Target({ ElementType.TYPE_USE, ElementType.METHOD })
3
@interface NonNull {
4
5
}
6
class A{
7
}
(-)resources/ReceiverParameter/testMoveType2File/out/Inner.java (+7 lines)
Added Link Here
1
package p;
2
class Inner{
3
	Inner(){}
4
	public void foo1(@NonNull Inner this){
5
		System.out.println("Hello");
6
	}
7
}
(-)resources/ReceiverParameter/testPullUp/in/A.java (+3 lines)
Added Link Here
1
package p;
2
class A{	
3
}
(-)resources/ReceiverParameter/testPullUp/in/B.java (+7 lines)
Added Link Here
1
package p;
2
3
import java.util.List;
4
class B extends A{
5
	void foo1(@NonNull  B this, List l){}
6
	void foo2(@NonNull  B this, String s){}
7
}
(-)resources/ReceiverParameter/testPullUp/in/NonNull.java (+5 lines)
Added Link Here
1
package p;
2
@Target({ ElementType.TYPE_USE, ElementType.METHOD })
3
@interface NonNull {
4
5
}
(-)resources/ReceiverParameter/testPullUp/out/A.java (+10 lines)
Added Link Here
1
package p;
2
3
import java.util.List;
4
5
class A{
6
7
	void foo1(@NonNull A this, List l) {}
8
9
	void foo2(@NonNull A this, String s) {}	
10
}
(-)resources/ReceiverParameter/testPullUp/out/B.java (+4 lines)
Added Link Here
1
package p;
2
3
class B extends A{
4
}
(-)resources/ReceiverParameter/testPushDown/in/A.java (+15 lines)
Added Link Here
1
package p;
2
@Target({ ElementType.TYPE_USE, ElementType.METHOD })
3
@interface NonNull {
4
5
}
6
class A{
7
	public void foo1(@NonNull A this) {
8
		System.out.println("foo1");
9
	}
10
	public void foo2(@NonNull A this, String s) {
11
		System.out.println(s);
12
	}	
13
}
14
class B extends A{
15
}
(-)resources/ReceiverParameter/testPushDown/out/A.java (+17 lines)
Added Link Here
1
package p;
2
@Target({ ElementType.TYPE_USE, ElementType.METHOD })
3
@interface NonNull {
4
5
}
6
class A{	
7
}
8
class B extends A{
9
10
	public void foo1(@NonNull B this) {
11
		System.out.println("foo1");
12
	}
13
14
	public void foo2(@NonNull B this, String s) {
15
		System.out.println(s);
16
	}
17
}
(-)test (+453 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 Community Process (JCP) and
9
 * is made available for testing and evaluation purposes only.
10
 * 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 java.util.Arrays;
18
import java.util.Hashtable;
19
import java.util.List;
20
21
import junit.framework.Test;
22
import junit.framework.TestSuite;
23
24
import org.eclipse.jdt.testplugin.TestOptions;
25
26
import org.eclipse.core.runtime.Assert;
27
import org.eclipse.core.runtime.NullProgressMonitor;
28
29
import org.eclipse.ltk.core.refactoring.Refactoring;
30
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
31
import org.eclipse.ltk.core.refactoring.participants.MoveRefactoring;
32
import org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring;
33
34
import org.eclipse.jdt.core.ICompilationUnit;
35
import org.eclipse.jdt.core.IField;
36
import org.eclipse.jdt.core.IJavaElement;
37
import org.eclipse.jdt.core.IJavaProject;
38
import org.eclipse.jdt.core.IMember;
39
import org.eclipse.jdt.core.IMethod;
40
import org.eclipse.jdt.core.IPackageFragment;
41
import org.eclipse.jdt.core.IType;
42
import org.eclipse.jdt.core.JavaCore;
43
import org.eclipse.jdt.core.JavaModelException;
44
import org.eclipse.jdt.core.dom.IVariableBinding;
45
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
46
47
import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings;
48
import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility;
49
import org.eclipse.jdt.internal.corext.refactoring.RefactoringAvailabilityTester;
50
import org.eclipse.jdt.internal.corext.refactoring.structure.ExtractInterfaceProcessor;
51
import org.eclipse.jdt.internal.corext.refactoring.structure.ExtractSupertypeProcessor;
52
import org.eclipse.jdt.internal.corext.refactoring.structure.MoveInnerToTopRefactoring;
53
import org.eclipse.jdt.internal.corext.refactoring.structure.MoveInstanceMethodProcessor;
54
import org.eclipse.jdt.internal.corext.refactoring.structure.PullUpRefactoringProcessor;
55
import org.eclipse.jdt.internal.corext.refactoring.structure.PushDownRefactoringProcessor;
56
import org.eclipse.jdt.internal.corext.refactoring.structure.PushDownRefactoringProcessor.MemberActionInfo;
57
import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil;
58
import org.eclipse.jdt.internal.corext.template.java.CodeTemplateContextType;
59
60
import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings;
61
62
public class ReceiverParameterTests18 extends RefactoringTest {
63
64
	private static final Class clazz= ReceiverParameterTests18.class;
65
66
	private static final String REFACTORING_PATH= "ReceiverParameter/";
67
68
	private Hashtable fOldOptions;
69
70
	public ReceiverParameterTests18(String name) {
71
		super(name);
72
	}
73
74
	public static Test suite() {
75
		return new Java18Setup(new TestSuite(clazz));
76
	}
77
78
	public static Test setUpTest(Test someTest) {
79
		return new Java18Setup(someTest);
80
	}
81
82
	@Override
83
	protected void setUp() throws Exception {
84
		super.setUp();
85
		StubUtility.setCodeTemplate(CodeTemplateContextType.NEWTYPE_ID,
86
				"${package_declaration}" +
87
						System.getProperty("line.separator", "\n") +
88
						"${" + CodeTemplateContextType.TYPE_COMMENT + "}" +
89
						System.getProperty("line.separator", "\n") +
90
						"${type_declaration}", null);
91
92
		StubUtility.setCodeTemplate(CodeTemplateContextType.TYPECOMMENT_ID, "/** typecomment template*/", null);
93
94
		fOldOptions= JavaCore.getOptions();
95
96
		Hashtable options= TestOptions.getDefaultOptions();
97
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_ASSIGNMENT_OPERATOR, DefaultCodeFormatterConstants.TRUE);
98
		options.put(DefaultCodeFormatterConstants.FORMATTER_NUMBER_OF_EMPTY_LINES_TO_PRESERVE, "1");
99
		options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.TAB);
100
101
		JavaCore.setOptions(options);
102
	}
103
104
	@Override
105
	protected void tearDown() throws Exception {
106
		super.tearDown();
107
		JavaCore.setOptions(fOldOptions);
108
		fOldOptions= null;
109
	}
110
111
	@Override
112
	protected String getRefactoringPath() {
113
		return REFACTORING_PATH;
114
	}
115
116
	private static PullUpRefactoringProcessor createPullUpRefactoringProcessor(IMember[] methods) throws JavaModelException {
117
		IJavaProject project= null;
118
		if (methods != null && methods.length > 0)
119
			project= methods[0].getJavaProject();
120
		if (RefactoringAvailabilityTester.isPullUpAvailable(methods)) {
121
			PullUpRefactoringProcessor processor= new PullUpRefactoringProcessor(methods, JavaPreferencesSettings.getCodeGenerationSettings(project));
122
			new ProcessorBasedRefactoring(processor);
123
			return processor;
124
		}
125
		return null;
126
	}
127
128
	private static ExtractSupertypeProcessor createExtractSuperclassRefactoringProcessor(IMember[] members) throws JavaModelException {
129
		IJavaProject project= null;
130
		if (members != null && members.length > 0)
131
			project= members[0].getJavaProject();
132
		if (RefactoringAvailabilityTester.isExtractSupertypeAvailable(members)) {
133
			final CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings(project);
134
			settings.createComments= false;
135
			ExtractSupertypeProcessor processor= new ExtractSupertypeProcessor(members, settings);
136
			new ProcessorBasedRefactoring(processor);
137
			return processor;
138
		}
139
		return null;
140
	}
141
142
	private IPackageFragment getPackage(String name) throws JavaModelException {
143
		if ("p".equals(name))
144
			return getPackageP();
145
		IPackageFragment pack= getRoot().getPackageFragment(name);
146
		if (pack.exists())
147
			return pack;
148
		return getRoot().createPackageFragment(name, false, new NullProgressMonitor());
149
	}
150
151
	private static String getTopLevelTypeName(String typeQualifiedTyperName) {
152
		int dotIndex= typeQualifiedTyperName.indexOf('.');
153
		if (dotIndex == -1)
154
			return typeQualifiedTyperName;
155
		return typeQualifiedTyperName.substring(0, dotIndex);
156
	}
157
	
158
	private void prepareForInputCheck(PushDownRefactoringProcessor processor, IMethod[] selectedMethods, IField[] selectedFields, String[] namesOfMethodsToPullUp,
159
			String[][] signaturesOfMethodsToPullUp, String[] namesOfFieldsToPullUp, String[] namesOfMethodsToDeclareAbstract, String[][] signaturesOfMethodsToDeclareAbstract) {
160
		IMethod[] methodsToPushDown= findMethods(selectedMethods, namesOfMethodsToPullUp, signaturesOfMethodsToPullUp);
161
		IField[] fieldsToPushDown= findFields(selectedFields, namesOfFieldsToPullUp);
162
		List membersToPushDown= Arrays.asList(merge(methodsToPushDown, fieldsToPushDown));
163
		List methodsToDeclareAbstract= Arrays.asList(findMethods(selectedMethods, namesOfMethodsToDeclareAbstract, signaturesOfMethodsToDeclareAbstract));
164
165
		MemberActionInfo[] infos= processor.getMemberActionInfos();
166
		for (int i= 0; i < infos.length; i++) {
167
			if (membersToPushDown.contains(infos[i].getMember())) {
168
				infos[i].setAction(MemberActionInfo.PUSH_DOWN_ACTION);
169
				assertTrue(!methodsToDeclareAbstract.contains(infos[i].getMember()));
170
			}
171
			if (methodsToDeclareAbstract.contains(infos[i].getMember())) {
172
				infos[i].setAction(MemberActionInfo.PUSH_ABSTRACT_ACTION);
173
				assertTrue(!membersToPushDown.contains(infos[i].getMember()));
174
			}
175
		}
176
	}
177
178
	/**
179
	 * Tests "Pull Up" method refactoring involving receiver parameter.
180
	 * 
181
	 * @throws Exception any exception thrown from this test case
182
	 */
183
	public void testPullUp() throws Exception {
184
		String[] methodNames= new String[] { "foo1", "foo2" };
185
		String[][] signatures= new String[][] { new String[]{"QList;"}, new String[] { "QString;" } };
186
		boolean deleteAllInSourceType= true;
187
		boolean deleteAllMatchingMethods= false;
188
		ICompilationUnit cuA= createCUfromTestFile(getPackageP(), "A");
189
		ICompilationUnit cuB= createCUfromTestFile(getPackageP(), "B");
190
		IMethod[] methods= getMethods(cuB.getType("B"), methodNames, signatures);
191
192
		PullUpRefactoringProcessor processor= createPullUpRefactoringProcessor(methods);
193
		Refactoring ref= processor.getRefactoring();
194
195
		assertTrue("activation", ref.checkInitialConditions(new NullProgressMonitor()).isOK());
196
197
		IType[] possibleClasses= processor.getCandidateTypes(new RefactoringStatus(), new NullProgressMonitor());
198
		assertTrue("No possible class found!", possibleClasses.length > 0);
199
		processor.setDestinationType(processor.getCandidateTypes(new RefactoringStatus(), new NullProgressMonitor())[possibleClasses.length - 1 - 0]);
200
201
		if (deleteAllInSourceType)
202
			processor.setDeletedMethods(methods);
203
		if (deleteAllMatchingMethods) {
204
			List l= Arrays.asList(JavaElementUtil.getElementsOfType(processor.getMatchingElements(new NullProgressMonitor(), false), IJavaElement.METHOD));
205
			processor.setDeletedMethods((IMethod[])l.toArray(new IMethod[l.size()]));
206
		}
207
208
		RefactoringStatus checkInputResult= ref.checkFinalConditions(new NullProgressMonitor());
209
		assertTrue("precondition was supposed to pass", !checkInputResult.hasError());
210
		performChange(ref, false);
211
212
		String expected= getFileContents(getOutputTestFileName("A"));
213
		String actual= cuA.getSource();
214
		assertEqualLines(expected, actual);
215
		expected= getFileContents(getOutputTestFileName("B"));
216
		actual= cuB.getSource();
217
		assertEqualLines(expected, actual);
218
	}
219
220
	/**
221
	 * Tests "Push Down" method refactoring involving receiver parameter.
222
	 * 
223
	 * @throws Exception any exception thrown from this test case
224
	 */
225
	public void testPushDown() throws Exception {
226
		String[] namesOfMethodsToPushDown= { "foo1", "foo2" };
227
		String[][] signaturesOfMethodsToPushDown= { new String[0], new String[] { "QString;" } };
228
		String[] selectedFieldNames= {};
229
		String[] namesOfFieldsToPushDown= {};
230
		String[] namesOfMethodsToDeclareAbstract= {};
231
		String[][] signaturesOfMethodsToDeclareAbstract= {};
232
233
234
		ICompilationUnit cuA= createCUfromTestFile(getPackageP(), "A");
235
236
		IType type= getType(cuA, "A");
237
		IMethod[] selectedMethods= getMethods(type, namesOfMethodsToPushDown, signaturesOfMethodsToPushDown);
238
		IField[] selectedFields= getFields(type, selectedFieldNames);
239
		IMember[] selectedMembers= merge(selectedFields, selectedMethods);
240
241
		assertTrue(RefactoringAvailabilityTester.isPushDownAvailable(selectedMembers));
242
		PushDownRefactoringProcessor processor= new PushDownRefactoringProcessor(selectedMembers);
243
		Refactoring ref= new ProcessorBasedRefactoring(processor);
244
245
		assertTrue("activation", ref.checkInitialConditions(new NullProgressMonitor()).isOK());
246
247
		prepareForInputCheck(processor, selectedMethods, selectedFields, namesOfMethodsToPushDown, signaturesOfMethodsToPushDown, namesOfFieldsToPushDown, namesOfMethodsToDeclareAbstract,
248
				signaturesOfMethodsToDeclareAbstract);
249
250
		RefactoringStatus checkInputResult= ref.checkFinalConditions(new NullProgressMonitor());
251
		assertTrue("precondition was supposed to pass but got " + checkInputResult.toString(), !checkInputResult.hasError());
252
		performChange(ref, false);
253
254
		String expected= getFileContents(getOutputTestFileName("A"));
255
		String actual= cuA.getSource();
256
		assertEqualLines("A.java", expected, actual);
257
258
	}
259
260
	/**
261
	 * Tests "Move" method refactoring involving receiver parameter.
262
	 * 
263
	 * @throws Exception any exception thrown from this test case
264
	 */
265
	public void testMove() throws Exception {
266
		String[] cuQNames= new String[] { "p1.A", "p2.B" };
267
		String selectionCuQName= "p1.A";
268
		boolean inlineDelegator= false;
269
		boolean removeDelegator= false;
270
		int selectionCuIndex= -1;
271
		for (int i= 0; i < cuQNames.length; i++)
272
			if (cuQNames[i] == null || selectionCuQName.equals(cuQNames[i]))
273
				selectionCuIndex= i;
274
		Assert.isTrue(selectionCuIndex != -1, "parameter selectionCuQName must match some String in cuQNames.");
275
		ICompilationUnit cuA= createCUfromTestFile(getPackage("p1"), "A");
276
		ICompilationUnit cuB= createCUfromTestFile(getPackage("p1"), "B");
277
278
		int offset= cuA.getSource().indexOf("mA1(@NonNull A this, B b)");
279
		IJavaElement[] codeSelect= cuA.codeSelect(offset, 3);
280
		assertTrue(codeSelect.length > 0);
281
		assertTrue(codeSelect[0] instanceof IMethod);
282
		IMethod method= (IMethod)codeSelect[0];
283
		MoveInstanceMethodProcessor processor= new MoveInstanceMethodProcessor(method, JavaPreferencesSettings.getCodeGenerationSettings(cuA.getJavaProject()));
284
		Refactoring ref= new MoveRefactoring(processor);
285
286
		assertNotNull("refactoring should be created", ref);
287
		RefactoringStatus preconditionResult= ref.checkInitialConditions(new NullProgressMonitor());
288
289
		assertTrue("activation was supposed to be successful", preconditionResult.isOK());
290
291
		IVariableBinding target= null;
292
		IVariableBinding[] targets= processor.getPossibleTargets();
293
		for (int i= 0; i < targets.length; i++) {
294
			IVariableBinding candidate= targets[i];
295
			if (candidate.getName().equals("b")) {
296
				target= candidate;
297
				break;
298
			}
299
		}
300
		assertNotNull("Expected new target not available.", target);
301
		processor.setTarget(target);
302
303
		processor.setInlineDelegator(inlineDelegator);
304
		processor.setRemoveDelegator(removeDelegator);
305
		processor.setDeprecateDelegates(false);
306
		processor.setMethodName("mA1Moved");
307
308
		preconditionResult.merge(ref.checkFinalConditions(new NullProgressMonitor()));
309
310
		assertTrue("precondition was supposed to pass", !preconditionResult.hasError());
311
312
		performChange(ref, false);
313
314
		String outputTestFileName= getOutputTestFileName("A");
315
		assertEqualLines("Incorrect inline in " + outputTestFileName, getFileContents(outputTestFileName), cuA.getSource());
316
317
318
		outputTestFileName= getOutputTestFileName("B");
319
		assertEqualLines("Incorrect inline in " + outputTestFileName, getFileContents(outputTestFileName), cuB.getSource());
320
321
	}
322
323
	/**
324
	 * Tests "Move Type to New File" refactoring involving receiver parameter.
325
	 * 
326
	 * @throws Exception any exception thrown from this test case
327
	 */
328
	public void testMoveType2File() throws Exception {
329
		String parentClassName= "A";
330
		String enclosingInstanceName= "Inner";
331
		String[] cuNames= new String[] { "A" };
332
		String[] packageNames= new String[] { "p" };
333
		String packageName= "p";
334
		IType parentClas= getType(createCUfromTestFile(getPackage(packageName), parentClassName), parentClassName);
335
		IType clas= parentClas.getType(enclosingInstanceName);
336
337
		assertTrue("should be enabled", RefactoringAvailabilityTester.isMoveInnerAvailable(clas));
338
		MoveInnerToTopRefactoring ref= ((RefactoringAvailabilityTester.isMoveInnerAvailable(clas)) ? new MoveInnerToTopRefactoring(clas, JavaPreferencesSettings.getCodeGenerationSettings(clas
339
				.getJavaProject())) : null);
340
		RefactoringStatus preconditionResult= ref.checkInitialConditions(new NullProgressMonitor());
341
		assertTrue("activation was supposed to be successful" + preconditionResult.toString(), preconditionResult.isOK());
342
343
		assertEquals("reference creation possible", true, ref.isCreatingInstanceFieldPossible());
344
		assertEquals("reference creation mandatory", false, ref.isCreatingInstanceFieldMandatory());
345
		if (ref.isCreatingInstanceFieldPossible() && !ref.isCreatingInstanceFieldMandatory())
346
			ref.setCreateInstanceField(false);
347
		ref.setEnclosingInstanceName(enclosingInstanceName);
348
		assertTrue("name should be ok ", ref.checkEnclosingInstanceName(enclosingInstanceName).isOK());
349
		ref.setMarkInstanceFieldAsFinal(false);
350
		ICompilationUnit[] cus= new ICompilationUnit[cuNames.length];
351
		for (int i= 0; i < cuNames.length; i++) {
352
			if (cuNames[i].equals(clas.getCompilationUnit().findPrimaryType().getElementName()))
353
				cus[i]= clas.getCompilationUnit();
354
			else
355
				cus[i]= createCUfromTestFile(getPackage(packageNames[i]), cuNames[i]);
356
		}
357
358
		RefactoringStatus checkInputResult= ref.checkFinalConditions(new NullProgressMonitor());
359
		assertTrue("precondition was supposed to pass", !checkInputResult.hasError());
360
		performChange(ref, false);
361
362
		for (int i= 0; i < cus.length; i++) {
363
			String actual= cus[i].getSource();
364
			String expected= getFileContents(getOutputTestFileName(cuNames[i]));
365
			assertEqualLines(cus[i].getElementName(), expected, actual);
366
		}
367
		ICompilationUnit newCu= clas.getPackageFragment().getCompilationUnit(enclosingInstanceName + ".java");
368
		String expected= getFileContents(getOutputTestFileName(enclosingInstanceName));
369
		String actual= newCu.getSource();
370
		assertEqualLines("new Cu:", expected, actual);
371
372
	}
373
374
	/**
375
	 * Tests "Extract Interface" refactoring involving receiver parameter.
376
	 * 
377
	 * @throws Exception any exception thrown from this test case
378
	 */
379
	public void testExtractInterface() throws Exception {
380
		String className= "A";
381
		String newInterfaceName= "I";
382
383
		IType clas= getType(createCUfromTestFile(getPackageP(), getTopLevelTypeName(className)), className);
384
		ICompilationUnit cu= clas.getCompilationUnit();
385
		IPackageFragment pack= (IPackageFragment)cu.getParent();
386
387
		ExtractInterfaceProcessor processor= new ExtractInterfaceProcessor(clas, JavaPreferencesSettings.getCodeGenerationSettings(clas.getJavaProject()));
388
		Refactoring ref= new ProcessorBasedRefactoring(processor);
389
390
		processor.setTypeName(newInterfaceName);
391
		assertEquals("interface name should be accepted", RefactoringStatus.OK, processor.checkTypeName(newInterfaceName).getSeverity());
392
393
		processor.setExtractedMembers(processor.getExtractableMembers());
394
		processor.setReplace(true);
395
		processor.setAnnotations(false);
396
		assertEquals("was supposed to pass", null, performRefactoring(ref));
397
		assertEqualLines("incorrect changes in " + className,
398
				getFileContents(getOutputTestFileName(className)),
399
				cu.getSource());
400
401
		ICompilationUnit interfaceCu= pack.getCompilationUnit(newInterfaceName + ".java");
402
		assertEqualLines("incorrect interface created",
403
				getFileContents(getOutputTestFileName(newInterfaceName)),
404
				interfaceCu.getSource());
405
	}
406
407
	/**
408
	 * Tests "Extract Superclass" refactoring involving receiver parameter.
409
	 * 
410
	 * @throws Exception any exception thrown from this test case
411
	 */
412
	public void testExtractSuperclass() throws Exception {
413
		String[] methodNames= new String[] { "foo1", "foo2" };
414
		String[][] signatures= new String[][] { new String[0], new String[] { "QString;" } };
415
		boolean replaceOccurences= true;
416
417
418
		ICompilationUnit cu= createCUfromTestFile(getPackageP(), "A");
419
		IType type= getType(cu, "A");
420
		IMethod[] methods= getMethods(type, methodNames, signatures);
421
422
		ExtractSupertypeProcessor processor= createExtractSuperclassRefactoringProcessor(methods);
423
		Refactoring refactoring= processor.getRefactoring();
424
		processor.setMembersToMove(methods);
425
426
		assertTrue("activation", refactoring.checkInitialConditions(new NullProgressMonitor()).isOK());
427
428
		processor.setTypesToExtract(new IType[] { type });
429
		processor.setTypeName("B");
430
		processor.setCreateMethodStubs(true);
431
		processor.setInstanceOf(false);
432
		processor.setReplace(replaceOccurences);
433
		processor.setDeletedMethods(methods);
434
435
		RefactoringStatus status= refactoring.checkFinalConditions(new NullProgressMonitor());
436
		assertTrue("precondition was supposed to pass", !status.hasError());
437
		performChange(refactoring, false);
438
439
		String expected= getFileContents(getOutputTestFileName("A"));
440
		String actual= cu.getSource();
441
		assertEqualLines(expected, actual);
442
443
		expected= getFileContents(getOutputTestFileName("B"));
444
		ICompilationUnit unit= getPackageP().getCompilationUnit("B.java");
445
		if (!unit.exists())
446
			assertTrue("extracted compilation unit does not exist", false);
447
		actual= unit.getBuffer().getContents();
448
		assertEqualLines(expected, actual);
449
450
451
	}
452
453
}
(-)core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/ExtractInterfaceProcessor.java (-1 / +27 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 Community Process (JCP) and
9
 * is made available for testing and evaluation purposes only.
10
 * 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 79-84 Link Here
79
import org.eclipse.jdt.core.dom.Modifier;
83
import org.eclipse.jdt.core.dom.Modifier;
80
import org.eclipse.jdt.core.dom.NodeFinder;
84
import org.eclipse.jdt.core.dom.NodeFinder;
81
import org.eclipse.jdt.core.dom.ParameterizedType;
85
import org.eclipse.jdt.core.dom.ParameterizedType;
86
import org.eclipse.jdt.core.dom.SimpleName;
87
import org.eclipse.jdt.core.dom.SimpleType;
82
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
88
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
83
import org.eclipse.jdt.core.dom.Type;
89
import org.eclipse.jdt.core.dom.Type;
84
import org.eclipse.jdt.core.dom.TypeDeclaration;
90
import org.eclipse.jdt.core.dom.TypeDeclaration;
Lines 699-704 Link Here
699
		if (fAbstract && !abstractFound)
705
		if (fAbstract && !abstractFound)
700
			rewriter.setModifiers(Modifier.ABSTRACT, 0, null);
706
			rewriter.setModifiers(Modifier.ABSTRACT, 0, null);
701
		
707
		
708
		updateReceiverParameter(declaration, rewrite, targetDeclaration.getName().getIdentifier());
702
		for (SingleVariableDeclaration param : (List<SingleVariableDeclaration>) declaration.parameters()) {
709
		for (SingleVariableDeclaration param : (List<SingleVariableDeclaration>) declaration.parameters()) {
703
			ListRewrite modifierRewrite= rewrite.getListRewrite(param, SingleVariableDeclaration.MODIFIERS2_PROPERTY);
710
			ListRewrite modifierRewrite= rewrite.getListRewrite(param, SingleVariableDeclaration.MODIFIERS2_PROPERTY);
704
			for (IExtendedModifier extended : (List<IExtendedModifier>) param.modifiers()) {
711
			for (IExtendedModifier extended : (List<IExtendedModifier>) param.modifiers()) {
Lines 730-735 Link Here
730
			RefactoringFileBuffers.release(unit);
737
			RefactoringFileBuffers.release(unit);
731
		}
738
		}
732
	}
739
	}
740
	
741
	private void updateReceiverParameter(final MethodDeclaration declaration, final ASTRewrite rewrite, final String targetName) {
742
		if (declaration.getReceiverType() != null) {
743
			AST ast= rewrite.getAST();
744
			SimpleName simpleName= ast.newSimpleName(targetName);
745
			SimpleType simpleType= ast.newSimpleType(simpleName);
746
			Iterator<Annotation> iterator= declaration.getReceiverType().annotations().iterator();
747
			while (iterator.hasNext()) {
748
				Annotation annotation= iterator.next();
749
				simpleType.annotations().add(rewrite.createCopyTarget(annotation));
750
			}
751
			rewrite.set(declaration, MethodDeclaration.RECEIVER_TYPE_PROPERTY, simpleType, null);
752
753
			if (declaration.getReceiverQualifier() != null) {
754
				SimpleName qualifierName= ast.newSimpleName(targetName);
755
				rewrite.set(declaration, MethodDeclaration.RECEIVER_QUALIFIER_PROPERTY, qualifierName, null);
756
			}
757
		}
758
	}
733
759
734
	/**
760
	/**
735
	 * Creates the new signature of the source type.
761
	 * Creates the new signature of the source type.
(-)core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/HierarchyProcessor.java (+27 lines)
Lines 70-75 Link Here
70
import org.eclipse.jdt.core.dom.MethodDeclaration;
70
import org.eclipse.jdt.core.dom.MethodDeclaration;
71
import org.eclipse.jdt.core.dom.Modifier;
71
import org.eclipse.jdt.core.dom.Modifier;
72
import org.eclipse.jdt.core.dom.SimpleName;
72
import org.eclipse.jdt.core.dom.SimpleName;
73
import org.eclipse.jdt.core.dom.SimpleType;
73
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
74
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
74
import org.eclipse.jdt.core.dom.Type;
75
import org.eclipse.jdt.core.dom.Type;
75
import org.eclipse.jdt.core.dom.TypeDeclaration;
76
import org.eclipse.jdt.core.dom.TypeDeclaration;
Lines 731-734 Link Here
731
			return true;
732
			return true;
732
		return hasNonMovedReferences(member, monitor, status);
733
		return hasNonMovedReferences(member, monitor, status);
733
	}
734
	}
735
	
736
	/**
737
	 * Updates the receiver parameter properties of the new method.
738
	 * 
739
	 * @param type the new type where the new method will be placed
740
	 * @param oldMethod the existing method from where the receiver parameter properties will be
741
	 *            copied
742
	 * @param newMethod the method whose receiver parameter properties will be updated
743
	 * @since 3.9 BETA_JAVA8
744
	 */
745
	protected void updateReceiverParameter(IType type, MethodDeclaration oldMethod, MethodDeclaration newMethod) {
746
		AST ast= newMethod.getAST();
747
		String elementName= type.getElementName();
748
		if (oldMethod.getReceiverType() != null) {
749
			SimpleType simpleType= ast.newSimpleType(ast.newSimpleName(elementName));
750
			Iterator<Annotation> iterator= oldMethod.getReceiverType().annotations().iterator();
751
			while (iterator.hasNext()) {
752
				Annotation annotation= iterator.next();
753
				simpleType.annotations().add(ASTNode.copySubtree(ast, annotation));
754
			}
755
			newMethod.setReceiverType(simpleType);
756
			if (oldMethod.getReceiverQualifier() != null) {
757
				newMethod.setReceiverQualifier(ast.newSimpleName(elementName));
758
			}
759
		}
760
	}
734
}
761
}
(-)core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/MoveInnerToTopRefactoring.java (-1 / +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 Community Process (JCP) and
9
 * is made available for testing and evaluation purposes only.
10
 * 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 901-906 Link Here
901
					addInheritedTypeQualifications(declaration, targetRewrite, qualifierGroup);
905
					addInheritedTypeQualifications(declaration, targetRewrite, qualifierGroup);
902
					addEnclosingInstanceDeclaration(declaration, rewrite);
906
					addEnclosingInstanceDeclaration(declaration, rewrite);
903
				}
907
				}
908
				updateConstructorReceiverParameter(declaration, rewrite);
904
				fTypeImports= new HashSet<ITypeBinding>();
909
				fTypeImports= new HashSet<ITypeBinding>();
905
				fStaticImports= new HashSet<IBinding>();
910
				fStaticImports= new HashSet<IBinding>();
906
				ImportRewriteUtil.collectImports(fType.getJavaProject(), declaration, fTypeImports, fStaticImports, false);
911
				ImportRewriteUtil.collectImports(fType.getJavaProject(), declaration, fTypeImports, fStaticImports, false);
Lines 1392-1397 Link Here
1392
		}
1397
		}
1393
	}
1398
	}
1394
1399
1400
	/**
1401
	 * Updates the receiver parameter properties of the constructor. The receiver parameter properties are set to <code>null</code>.
1402
	 * 
1403
	 * @param declaration the type declaration AST node
1404
	 * @param rewrite the ASTRewrite node used for the modification
1405
	 * @since 3.9 BETA_JAVA8
1406
	 */
1407
	private void updateConstructorReceiverParameter(AbstractTypeDeclaration declaration, final ASTRewrite rewrite) {
1408
		final MethodDeclaration[] declarations= getConstructorDeclarationNodes(declaration);
1409
		for (int index= 0; index < declarations.length; index++) {
1410
			MethodDeclaration methodDeclaration= declarations[index];
1411
			if (methodDeclaration.getReceiverType() != null) {
1412
				rewrite.set(methodDeclaration, MethodDeclaration.RECEIVER_TYPE_PROPERTY, null, null);
1413
				if (methodDeclaration.getReceiverQualifier() != null) {
1414
					rewrite.set(methodDeclaration, MethodDeclaration.RECEIVER_QUALIFIER_PROPERTY, null, null);
1415
				}
1416
			}
1417
		}
1418
	}
1419
	
1395
	private void modifyInterfaceMemberModifiers(final ITypeBinding binding) {
1420
	private void modifyInterfaceMemberModifiers(final ITypeBinding binding) {
1396
		Assert.isNotNull(binding);
1421
		Assert.isNotNull(binding);
1397
		ITypeBinding declaring= binding.getDeclaringClass();
1422
		ITypeBinding declaring= binding.getDeclaringClass();
(-)core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/MoveInstanceMethodProcessor.java (-1 / +27 lines)
Lines 1-10 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
 *
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and 
9
 * is made available for testing and evaluation purposes only. 
10
 * 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 69-74 Link Here
69
import org.eclipse.jdt.core.dom.ASTNode;
73
import org.eclipse.jdt.core.dom.ASTNode;
70
import org.eclipse.jdt.core.dom.ASTVisitor;
74
import org.eclipse.jdt.core.dom.ASTVisitor;
71
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
75
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
76
import org.eclipse.jdt.core.dom.Annotation;
72
import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration;
77
import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration;
73
import org.eclipse.jdt.core.dom.AnonymousClassDeclaration;
78
import org.eclipse.jdt.core.dom.AnonymousClassDeclaration;
74
import org.eclipse.jdt.core.dom.Assignment;
79
import org.eclipse.jdt.core.dom.Assignment;
Lines 95-100 Link Here
95
import org.eclipse.jdt.core.dom.PrimitiveType;
100
import org.eclipse.jdt.core.dom.PrimitiveType;
96
import org.eclipse.jdt.core.dom.QualifiedName;
101
import org.eclipse.jdt.core.dom.QualifiedName;
97
import org.eclipse.jdt.core.dom.SimpleName;
102
import org.eclipse.jdt.core.dom.SimpleName;
103
import org.eclipse.jdt.core.dom.SimpleType;
98
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
104
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
99
import org.eclipse.jdt.core.dom.SuperFieldAccess;
105
import org.eclipse.jdt.core.dom.SuperFieldAccess;
100
import org.eclipse.jdt.core.dom.SuperMethodInvocation;
106
import org.eclipse.jdt.core.dom.SuperMethodInvocation;
Lines 2255-2260 Link Here
2255
					adjustments.put(fMethod, adjustment);
2261
					adjustments.put(fMethod, adjustment);
2256
				}
2262
				}
2257
			}
2263
			}
2264
			updateReceiverParameter(declaration, rewrite);			
2258
			target= createMethodArguments(rewrites, rewrite, declaration, adjustments, status);
2265
			target= createMethodArguments(rewrites, rewrite, declaration, adjustments, status);
2259
			createMethodTypeParameters(rewrite, declaration, status);
2266
			createMethodTypeParameters(rewrite, declaration, status);
2260
			createMethodComment(rewrite, declaration);
2267
			createMethodComment(rewrite, declaration);
Lines 2266-2271 Link Here
2266
		return target;
2273
		return target;
2267
	}
2274
	}
2268
2275
2276
	private void updateReceiverParameter(final MethodDeclaration declaration, final ASTRewrite rewrite) throws JavaModelException {
2277
		if (declaration.getReceiverType() != null) {
2278
			IType targetType= getTargetType();
2279
			AST ast= rewrite.getAST();
2280
			SimpleName simpleName= ast.newSimpleName(targetType.getElementName());
2281
			SimpleType simpleType= ast.newSimpleType(simpleName);
2282
			Iterator<Annotation> iterator= declaration.getReceiverType().annotations().iterator();
2283
			while (iterator.hasNext()) {
2284
				Annotation annotation= iterator.next();
2285
				simpleType.annotations().add(rewrite.createCopyTarget(annotation));
2286
			}
2287
			rewrite.set(declaration, MethodDeclaration.RECEIVER_TYPE_PROPERTY, simpleType, null);
2288
			if (declaration.getReceiverQualifier() != null) {
2289
				SimpleName qualifierName= ast.newSimpleName(targetType.getElementName());
2290
				rewrite.set(declaration, MethodDeclaration.RECEIVER_QUALIFIER_PROPERTY, qualifierName, null);
2291
			}
2292
		}
2293
	}
2294
2269
	/**
2295
	/**
2270
	 * Creates the necessary changes to replace the body of the method
2296
	 * Creates the necessary changes to replace the body of the method
2271
	 * declaration with an expression to invoke the delegate.
2297
	 * declaration with an expression to invoke the delegate.
(-)core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/PullUpRefactoringProcessor.java (+3 lines)
Lines 514-519 Link Here
514
		copyReturnType(rewriter.getASTRewrite(), getDeclaringType().getCompilationUnit(), methodToCreateStubFor, newMethod, mapping);
514
		copyReturnType(rewriter.getASTRewrite(), getDeclaringType().getCompilationUnit(), methodToCreateStubFor, newMethod, mapping);
515
		copyParameters(rewriter.getASTRewrite(), getDeclaringType().getCompilationUnit(), methodToCreateStubFor, newMethod, mapping);
515
		copyParameters(rewriter.getASTRewrite(), getDeclaringType().getCompilationUnit(), methodToCreateStubFor, newMethod, mapping);
516
		copyThrownExceptions(methodToCreateStubFor, newMethod);
516
		copyThrownExceptions(methodToCreateStubFor, newMethod);
517
		updateReceiverParameter(getDestinationType(), methodToCreateStubFor, newMethod);
517
		newMethod.setJavadoc(createJavadocForStub(typeToCreateStubIn.getName().getIdentifier(), methodToCreateStubFor, newMethod, newCu, rewriter.getASTRewrite()));
518
		newMethod.setJavadoc(createJavadocForStub(typeToCreateStubIn.getName().getIdentifier(), methodToCreateStubFor, newMethod, newCu, rewriter.getASTRewrite()));
518
		ImportRewriteContext context= new ContextSensitiveImportRewriteContext(typeToCreateStubIn, rewriter.getImportRewrite());
519
		ImportRewriteContext context= new ContextSensitiveImportRewriteContext(typeToCreateStubIn, rewriter.getImportRewrite());
519
		ImportRewriteUtil.addImports(rewriter, context, newMethod, new HashMap<Name, String>(), new HashMap<Name, String>(), false);
520
		ImportRewriteUtil.addImports(rewriter, context, newMethod, new HashMap<Name, String>(), new HashMap<Name, String>(), false);
Lines 1037-1042 Link Here
1037
		copyReturnType(targetRewrite.getASTRewrite(), getDeclaringType().getCompilationUnit(), oldMethod, newMethod, mapping);
1038
		copyReturnType(targetRewrite.getASTRewrite(), getDeclaringType().getCompilationUnit(), oldMethod, newMethod, mapping);
1038
		copyParameters(targetRewrite.getASTRewrite(), getDeclaringType().getCompilationUnit(), oldMethod, newMethod, mapping);
1039
		copyParameters(targetRewrite.getASTRewrite(), getDeclaringType().getCompilationUnit(), oldMethod, newMethod, mapping);
1039
		copyThrownExceptions(oldMethod, newMethod);
1040
		copyThrownExceptions(oldMethod, newMethod);
1041
		updateReceiverParameter(getDestinationType(), oldMethod, newMethod);
1040
		ImportRewriteContext context= new ContextSensitiveImportRewriteContext(destination, targetRewrite.getImportRewrite());
1042
		ImportRewriteContext context= new ContextSensitiveImportRewriteContext(destination, targetRewrite.getImportRewrite());
1041
		ImportRewriteUtil.addImports(targetRewrite, context, newMethod, new HashMap<Name, String>(), new HashMap<Name, String>(), false);
1043
		ImportRewriteUtil.addImports(targetRewrite, context, newMethod, new HashMap<Name, String>(), new HashMap<Name, String>(), false);
1042
		targetRewrite.getASTRewrite().getListRewrite(destination, destination.getBodyDeclarationsProperty()).insertAt(newMethod, ASTNodes.getInsertionIndex(newMethod, destination.bodyDeclarations()), targetRewrite.createCategorizedGroupDescription(RefactoringCoreMessages.PullUpRefactoring_add_abstract_method, SET_PULL_UP));
1044
		targetRewrite.getASTRewrite().getListRewrite(destination, destination.getBodyDeclarationsProperty()).insertAt(newMethod, ASTNodes.getInsertionIndex(newMethod, destination.bodyDeclarations()), targetRewrite.createCategorizedGroupDescription(RefactoringCoreMessages.PullUpRefactoring_add_abstract_method, SET_PULL_UP));
Lines 1343-1348 Link Here
1343
		copyParameters(rewrite, getDeclaringType().getCompilationUnit(), oldMethod, newMethod, mapping);
1345
		copyParameters(rewrite, getDeclaringType().getCompilationUnit(), oldMethod, newMethod, mapping);
1344
		copyThrownExceptions(oldMethod, newMethod);
1346
		copyThrownExceptions(oldMethod, newMethod);
1345
		copyTypeParameters(oldMethod, newMethod);
1347
		copyTypeParameters(oldMethod, newMethod);
1348
		updateReceiverParameter(getDestinationType(), oldMethod, newMethod);
1346
		return newMethod;
1349
		return newMethod;
1347
	}
1350
	}
1348
1351
(-)core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/PushDownRefactoringProcessor.java (-2 / +3 lines)
Lines 658-664 Link Here
658
						} else {
658
						} else {
659
							final MethodDeclaration oldMethod= ASTNodeSearchUtil.getMethodDeclarationNode((IMethod) infos[offset].getMember(), sourceRewriter.getRoot());
659
							final MethodDeclaration oldMethod= ASTNodeSearchUtil.getMethodDeclarationNode((IMethod) infos[offset].getMember(), sourceRewriter.getRoot());
660
							if (oldMethod != null) {
660
							if (oldMethod != null) {
661
								MethodDeclaration newMethod= createNewMethodDeclarationNode(infos[offset], mapping, unitRewriter, oldMethod);
661
								MethodDeclaration newMethod= createNewMethodDeclarationNode(type, infos[offset], mapping, unitRewriter, oldMethod);
662
								unitRewriter.getASTRewrite().getListRewrite(declaration, declaration.getBodyDeclarationsProperty()).insertAt(newMethod, ASTNodes.getInsertionIndex(newMethod, declaration.bodyDeclarations()), unitRewriter.createCategorizedGroupDescription(RefactoringCoreMessages.HierarchyRefactoring_add_member, SET_PUSH_DOWN));
662
								unitRewriter.getASTRewrite().getListRewrite(declaration, declaration.getBodyDeclarationsProperty()).insertAt(newMethod, ASTNodes.getInsertionIndex(newMethod, declaration.bodyDeclarations()), unitRewriter.createCategorizedGroupDescription(RefactoringCoreMessages.HierarchyRefactoring_add_member, SET_PUSH_DOWN));
663
								ImportRewriteUtil.addImports(unitRewriter, context, oldMethod, new HashMap<Name, String>(), new HashMap<Name, String>(), false);
663
								ImportRewriteUtil.addImports(unitRewriter, context, oldMethod, new HashMap<Name, String>(), new HashMap<Name, String>(), false);
664
							}
664
							}
Lines 823-829 Link Here
823
		return newField;
823
		return newField;
824
	}
824
	}
825
825
826
	private MethodDeclaration createNewMethodDeclarationNode(MemberActionInfo info, TypeVariableMaplet[] mapping, CompilationUnitRewrite rewriter, MethodDeclaration oldMethod) throws JavaModelException {
826
	private MethodDeclaration createNewMethodDeclarationNode(IType type, MemberActionInfo info, TypeVariableMaplet[] mapping, CompilationUnitRewrite rewriter, MethodDeclaration oldMethod) throws JavaModelException {
827
		Assert.isTrue(!info.isFieldInfo());
827
		Assert.isTrue(!info.isFieldInfo());
828
		IMethod method= (IMethod) info.getMember();
828
		IMethod method= (IMethod) info.getMember();
829
		ASTRewrite rewrite= rewriter.getASTRewrite();
829
		ASTRewrite rewrite= rewriter.getASTRewrite();
Lines 847-852 Link Here
847
		copyParameters(rewrite, method.getCompilationUnit(), oldMethod, newMethod, mapping);
847
		copyParameters(rewrite, method.getCompilationUnit(), oldMethod, newMethod, mapping);
848
		copyThrownExceptions(oldMethod, newMethod);
848
		copyThrownExceptions(oldMethod, newMethod);
849
		copyTypeParameters(oldMethod, newMethod);
849
		copyTypeParameters(oldMethod, newMethod);
850
		updateReceiverParameter(type, oldMethod, newMethod);
850
		return newMethod;
851
		return newMethod;
851
	}
852
	}
852
853
(-)core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeRefactoringProcessor.java (-77 / +86 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 Community Process (JCP) and
9
 * is made available for testing and evaluation purposes only.
10
 * 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 71-76 Link Here
71
import org.eclipse.jdt.core.dom.QualifiedName;
75
import org.eclipse.jdt.core.dom.QualifiedName;
72
import org.eclipse.jdt.core.dom.SimpleName;
76
import org.eclipse.jdt.core.dom.SimpleName;
73
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
77
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
78
import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor;
74
import org.eclipse.jdt.core.dom.Type;
79
import org.eclipse.jdt.core.dom.Type;
75
import org.eclipse.jdt.core.dom.TypeDeclaration;
80
import org.eclipse.jdt.core.dom.TypeDeclaration;
76
import org.eclipse.jdt.core.dom.TypeParameter;
81
import org.eclipse.jdt.core.dom.TypeParameter;
Lines 846-931 Link Here
846
		final CompilationUnit target= rewrite.getRoot();
851
		final CompilationUnit target= rewrite.getRoot();
847
		node= NodeFinder.perform(copy, range.getSourceRange());
852
		node= NodeFinder.perform(copy, range.getSourceRange());
848
		if (node != null) {
853
		if (node != null) {
849
			node= ASTNodes.getNormalizedNode(node).getParent();
854
			ASTNode normalizedNode= ASTNodes.getNormalizedNode(node);
850
			if (node instanceof VariableDeclaration) {
855
			if (normalizedNode != null) {
851
				binding= ((VariableDeclaration) node).resolveBinding();
856
				StructuralPropertyDescriptor locationInParent= normalizedNode.getLocationInParent();
852
				node= target.findDeclaringNode(binding.getKey());
857
				node= normalizedNode.getParent();
853
				if (node instanceof SingleVariableDeclaration) {
858
				if (node instanceof VariableDeclaration) {
854
					rewriteTypeOccurrence(estimate, rewrite, ((SingleVariableDeclaration) node).getType(), group);
859
					binding= ((VariableDeclaration) node).resolveBinding();
855
					if (node.getParent() instanceof MethodDeclaration) {
860
					node= target.findDeclaringNode(binding.getKey());
856
						binding= ((VariableDeclaration) node).resolveBinding();
861
					if (node instanceof SingleVariableDeclaration) {
857
						if (binding != null)
862
						rewriteTypeOccurrence(estimate, rewrite, ((SingleVariableDeclaration) node).getType(), group);
858
							replacements.add(binding.getKey());
863
						if (node.getParent() instanceof MethodDeclaration) {
859
					}
864
							binding= ((VariableDeclaration) node).resolveBinding();
860
				}
865
							if (binding != null)
861
			} else if (node instanceof VariableDeclarationStatement) {
866
								replacements.add(binding.getKey());
862
				binding= ((VariableDeclaration) ((VariableDeclarationStatement) node).fragments().get(0)).resolveBinding();
863
				node= target.findDeclaringNode(binding.getKey());
864
				if (node instanceof VariableDeclarationFragment)
865
					rewriteTypeOccurrence(estimate, rewrite, ((VariableDeclarationStatement) ((VariableDeclarationFragment) node).getParent()).getType(), group);
866
			} else if (node instanceof MethodDeclaration) {
867
				binding= ((MethodDeclaration) node).resolveBinding();
868
				node= target.findDeclaringNode(binding.getKey());
869
				if (node instanceof MethodDeclaration)
870
					rewriteTypeOccurrence(estimate, rewrite, ((MethodDeclaration) node).getReturnType2(), group);
871
			} else if (node instanceof FieldDeclaration) {
872
				binding= ((VariableDeclaration) ((FieldDeclaration) node).fragments().get(0)).resolveBinding();
873
				node= target.findDeclaringNode(binding.getKey());
874
				if (node instanceof VariableDeclarationFragment) {
875
					node= node.getParent();
876
					if (node instanceof FieldDeclaration)
877
						rewriteTypeOccurrence(estimate, rewrite, ((FieldDeclaration) node).getType(), group);
878
				}
879
			} else if (node instanceof ArrayType) {
880
				final ASTNode type= node;
881
				while (node != null && !(node instanceof MethodDeclaration) && !(node instanceof VariableDeclarationFragment))
882
					node= node.getParent();
883
				if (node != null) {
884
					final int delta= node.getStartPosition() + node.getLength() - type.getStartPosition();
885
					if (node instanceof MethodDeclaration)
886
						binding= ((MethodDeclaration) node).resolveBinding();
887
					else if (node instanceof VariableDeclarationFragment)
888
						binding= ((VariableDeclarationFragment) node).resolveBinding();
889
					if (binding != null) {
890
						node= target.findDeclaringNode(binding.getKey());
891
						if (node instanceof MethodDeclaration || node instanceof VariableDeclarationFragment) {
892
							node= NodeFinder.perform(target, (node.getStartPosition() + node.getLength() - delta), 0);
893
							if (node instanceof SimpleName)
894
								rewriteTypeOccurrence(estimate, rewrite, node, group);
895
						}
867
						}
896
					}
868
					}
897
				}
869
				} else if (node instanceof VariableDeclarationStatement) {
898
			} else if (node instanceof QualifiedName) {
870
					binding= ((VariableDeclaration) ((VariableDeclarationStatement) node).fragments().get(0)).resolveBinding();
899
				final ASTNode name= node;
871
					node= target.findDeclaringNode(binding.getKey());
900
				while (node != null && !(node instanceof MethodDeclaration) && !(node instanceof VariableDeclarationFragment))
872
					if (node instanceof VariableDeclarationFragment)
901
					node= node.getParent();
873
						rewriteTypeOccurrence(estimate, rewrite, ((VariableDeclarationStatement) ((VariableDeclarationFragment) node).getParent()).getType(), group);
902
				if (node != null) {
874
				} else if (node instanceof MethodDeclaration && MethodDeclaration.RETURN_TYPE2_PROPERTY.equals(locationInParent)) {
903
					final int delta= node.getStartPosition() + node.getLength() - name.getStartPosition();
904
					if (node instanceof MethodDeclaration)
905
						binding= ((MethodDeclaration) node).resolveBinding();
906
					else if (node instanceof VariableDeclarationFragment)
907
						binding= ((VariableDeclarationFragment) node).resolveBinding();
908
					if (binding != null) {
909
						node= target.findDeclaringNode(binding.getKey());
910
						if (node instanceof SimpleName || node instanceof MethodDeclaration || node instanceof VariableDeclarationFragment) {
911
							node= NodeFinder.perform(target, (node.getStartPosition() + node.getLength() - delta), 0);
912
							if (node instanceof SimpleName)
913
								rewriteTypeOccurrence(estimate, rewrite, node, group);
914
						}
915
					}
916
				}
917
			} else if (node instanceof CastExpression) {
918
				final ASTNode expression= node;
919
				while (node != null && !(node instanceof MethodDeclaration))
920
					node= node.getParent();
921
				if (node != null) {
922
					final int delta= node.getStartPosition() + node.getLength() - expression.getStartPosition();
923
					binding= ((MethodDeclaration) node).resolveBinding();
875
					binding= ((MethodDeclaration) node).resolveBinding();
924
					node= target.findDeclaringNode(binding.getKey());
876
					node= target.findDeclaringNode(binding.getKey());
925
					if (node instanceof MethodDeclaration) {
877
					if (node instanceof MethodDeclaration)
926
						node= NodeFinder.perform(target, (node.getStartPosition() + node.getLength() - delta), 0);
878
						rewriteTypeOccurrence(estimate, rewrite, ((MethodDeclaration) node).getReturnType2(), group);
927
						if (node instanceof CastExpression)
879
				} else if (node instanceof FieldDeclaration) {
928
							rewriteTypeOccurrence(estimate, rewrite, ((CastExpression) node).getType(), group);
880
					binding= ((VariableDeclaration) ((FieldDeclaration) node).fragments().get(0)).resolveBinding();
881
					node= target.findDeclaringNode(binding.getKey());
882
					if (node instanceof VariableDeclarationFragment) {
883
						node= node.getParent();
884
						if (node instanceof FieldDeclaration)
885
							rewriteTypeOccurrence(estimate, rewrite, ((FieldDeclaration) node).getType(), group);
886
					}
887
				} else if (node instanceof ArrayType) {
888
					final ASTNode type= node;
889
					while (node != null && !(node instanceof MethodDeclaration) && !(node instanceof VariableDeclarationFragment))
890
						node= node.getParent();
891
					if (node != null) {
892
						final int delta= node.getStartPosition() + node.getLength() - type.getStartPosition();
893
						if (node instanceof MethodDeclaration)
894
							binding= ((MethodDeclaration) node).resolveBinding();
895
						else if (node instanceof VariableDeclarationFragment)
896
							binding= ((VariableDeclarationFragment) node).resolveBinding();
897
						if (binding != null) {
898
							node= target.findDeclaringNode(binding.getKey());
899
							if (node instanceof MethodDeclaration || node instanceof VariableDeclarationFragment) {
900
								node= NodeFinder.perform(target, (node.getStartPosition() + node.getLength() - delta), 0);
901
								if (node instanceof SimpleName)
902
									rewriteTypeOccurrence(estimate, rewrite, node, group);
903
							}
904
						}
905
					}
906
				} else if (node instanceof QualifiedName) {
907
					final ASTNode name= node;
908
					while (node != null && !(node instanceof MethodDeclaration) && !(node instanceof VariableDeclarationFragment))
909
						node= node.getParent();
910
					if (node != null) {
911
						final int delta= node.getStartPosition() + node.getLength() - name.getStartPosition();
912
						if (node instanceof MethodDeclaration)
913
							binding= ((MethodDeclaration) node).resolveBinding();
914
						else if (node instanceof VariableDeclarationFragment)
915
							binding= ((VariableDeclarationFragment) node).resolveBinding();
916
						if (binding != null) {
917
							node= target.findDeclaringNode(binding.getKey());
918
							if (node instanceof SimpleName || node instanceof MethodDeclaration || node instanceof VariableDeclarationFragment) {
919
								node= NodeFinder.perform(target, (node.getStartPosition() + node.getLength() - delta), 0);
920
								if (node instanceof SimpleName)
921
									rewriteTypeOccurrence(estimate, rewrite, node, group);
922
							}
923
						}
924
					}
925
				} else if (node instanceof CastExpression) {
926
					final ASTNode expression= node;
927
					while (node != null && !(node instanceof MethodDeclaration))
928
						node= node.getParent();
929
					if (node != null) {
930
						final int delta= node.getStartPosition() + node.getLength() - expression.getStartPosition();
931
						binding= ((MethodDeclaration) node).resolveBinding();
932
						node= target.findDeclaringNode(binding.getKey());
933
						if (node instanceof MethodDeclaration) {
934
							node= NodeFinder.perform(target, (node.getStartPosition() + node.getLength() - delta), 0);
935
							if (node instanceof CastExpression)
936
								rewriteTypeOccurrence(estimate, rewrite, ((CastExpression) node).getType(), group);
937
						}
929
					}
938
					}
930
				}
939
				}
931
			}
940
			}
(-)ui/org/eclipse/jdt/internal/ui/text/correction/proposals/MissingReturnTypeInLambdaCorrectionProposal.java (+176 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.internal.ui.text.correction.proposals;
16
17
import java.util.List;
18
19
import org.eclipse.jdt.core.ICompilationUnit;
20
import org.eclipse.jdt.core.dom.AST;
21
import org.eclipse.jdt.core.dom.ASTNode;
22
import org.eclipse.jdt.core.dom.Block;
23
import org.eclipse.jdt.core.dom.CompilationUnit;
24
import org.eclipse.jdt.core.dom.Expression;
25
import org.eclipse.jdt.core.dom.ExpressionStatement;
26
import org.eclipse.jdt.core.dom.IBinding;
27
import org.eclipse.jdt.core.dom.IMethodBinding;
28
import org.eclipse.jdt.core.dom.ITypeBinding;
29
import org.eclipse.jdt.core.dom.IVariableBinding;
30
import org.eclipse.jdt.core.dom.LambdaExpression;
31
import org.eclipse.jdt.core.dom.Modifier;
32
import org.eclipse.jdt.core.dom.ReturnStatement;
33
import org.eclipse.jdt.core.dom.Statement;
34
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
35
36
import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer;
37
38
import org.eclipse.jdt.internal.ui.JavaPluginImages;
39
import org.eclipse.jdt.internal.ui.text.correction.CorrectionMessages;
40
41
public class MissingReturnTypeInLambdaCorrectionProposal extends LinkedCorrectionProposal {
42
43
	private static final String RETURN_EXPRESSION_KEY= "value"; //$NON-NLS-1$
44
45
	private LambdaExpression lambdaExpression;
46
	private ReturnStatement fExistingReturn;
47
48
	public MissingReturnTypeInLambdaCorrectionProposal(ICompilationUnit cu, LambdaExpression lambda, ReturnStatement existingReturn, int relevance) {
49
		super("", cu, null, relevance, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE)); //$NON-NLS-1$
50
		lambdaExpression= lambda;
51
		fExistingReturn= existingReturn;
52
	}
53
54
	@Override
55
	public String getName() {
56
		if (fExistingReturn != null) {
57
			return CorrectionMessages.MissingReturnTypeCorrectionProposal_changereturnstatement_description;
58
		} else {
59
			return CorrectionMessages.MissingReturnTypeCorrectionProposal_addreturnstatement_description;
60
		}
61
	}
62
63
	/*(non-Javadoc)
64
	 * @see org.eclipse.jdt.internal.ui.text.correction.ASTRewriteCorrectionProposal#getRewrite()
65
	 */
66
	@Override
67
	protected ASTRewrite getRewrite() {
68
		AST ast= lambdaExpression.getAST();
69
70
		ITypeBinding returnBinding= getReturnTypeBinding();
71
72
		if (fExistingReturn != null) {
73
			ASTRewrite rewrite= ASTRewrite.create(ast);
74
75
			Expression expression= evaluateReturnExpressions(ast, returnBinding, fExistingReturn.getStartPosition());
76
			if (expression != null) {
77
				rewrite.set(fExistingReturn, ReturnStatement.EXPRESSION_PROPERTY, expression, null);
78
79
				addLinkedPosition(rewrite.track(expression), true, RETURN_EXPRESSION_KEY);
80
			}
81
			return rewrite;
82
		} else {
83
			ASTRewrite rewrite= ASTRewrite.create(ast);
84
85
			ASTNode block= lambdaExpression.getBody();
86
87
			if (block instanceof Block) {
88
				List<Statement> statements= ((Block) block).statements();
89
				int nStatements= statements.size();
90
				ASTNode lastStatement= null;
91
				if (nStatements > 0) {
92
					lastStatement= statements.get(nStatements - 1);
93
				}
94
95
				if (returnBinding != null && lastStatement instanceof ExpressionStatement && lastStatement.getNodeType() != ASTNode.ASSIGNMENT) {
96
					Expression expression= ((ExpressionStatement) lastStatement).getExpression();
97
					ITypeBinding binding= expression.resolveTypeBinding();
98
					if (binding != null && binding.isAssignmentCompatible(returnBinding)) {
99
						Expression placeHolder= (Expression) rewrite.createMoveTarget(expression);
100
101
						ReturnStatement returnStatement= ast.newReturnStatement();
102
						returnStatement.setExpression(placeHolder);
103
104
						rewrite.replace(lastStatement, returnStatement, null);
105
						return rewrite;
106
					}
107
				}
108
109
				int offset;
110
				if (lastStatement == null) {
111
					offset= block.getStartPosition() + 1;
112
				} else {
113
					offset= lastStatement.getStartPosition() + lastStatement.getLength();
114
				}
115
			ReturnStatement returnStatement= ast.newReturnStatement();
116
				Expression expression= evaluateReturnExpressions(ast, returnBinding, offset);
117
118
				returnStatement.setExpression(expression);
119
120
			rewrite.getListRewrite(block, Block.STATEMENTS_PROPERTY).insertLast(returnStatement, null);
121
122
			addLinkedPosition(rewrite.track(returnStatement.getExpression()), true, RETURN_EXPRESSION_KEY);
123
			}
124
			return rewrite;
125
		}
126
	}
127
128
	private ITypeBinding getReturnTypeBinding() {
129
		IMethodBinding methodBinding= lambdaExpression.resolveMethodBinding();
130
		if (methodBinding != null && methodBinding.getReturnType() != null) {
131
			return methodBinding.getReturnType();
132
		}
133
		return null;
134
	}
135
136
	/*
137
	 * Evaluates possible return expressions. The favourite expression is returned.
138
	 */
139
	private Expression evaluateReturnExpressions(AST ast, ITypeBinding returnBinding, int returnOffset) {
140
		CompilationUnit root= (CompilationUnit) lambdaExpression.getRoot();
141
142
		Expression result= null;
143
		if (returnBinding != null) {
144
			ScopeAnalyzer analyzer= new ScopeAnalyzer(root);
145
			IBinding[] bindings= analyzer.getDeclarationsInScope(returnOffset, ScopeAnalyzer.VARIABLES | ScopeAnalyzer.CHECK_VISIBILITY );
146
			for (int i= 0; i < bindings.length; i++) {
147
				IVariableBinding curr= (IVariableBinding) bindings[i];
148
				ITypeBinding type= curr.getType();
149
				if (type != null && type.isAssignmentCompatible(returnBinding) && testModifier(curr)) {
150
					if (result == null) {
151
						result= ast.newSimpleName(curr.getName());
152
					}
153
					addLinkedPositionProposal(RETURN_EXPRESSION_KEY, curr.getName(), null);
154
				}
155
			}
156
		}
157
// TODO		Expression defaultExpression= ASTNodeFactory.newDefaultExpression(ast, lambdaExpression.getReturnType2(), lambdaExpression.getExtraDimensions());
158
//		addLinkedPositionProposal(RETURN_EXPRESSION_KEY, ASTNodes.asString(defaultExpression), null);
159
//		if (result == null) {
160
//			return defaultExpression;
161
//		}
162
		return result;
163
	}
164
165
	private boolean testModifier(IVariableBinding curr) {
166
		int modifiers= curr.getModifiers();
167
		int staticFinal= Modifier.STATIC | Modifier.FINAL;
168
		if ((modifiers & staticFinal) == staticFinal) {
169
			return false;
170
		}
171
//		if (Modifier.isStatic(modifiers) && !Modifier.isStatic(lambdaExpression.getModifiers())) {
172
//			return false;
173
//		}
174
		return true;
175
	}
176
}

Return to bug 405270