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 |
} |