001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.api.java.source.gen;
042:
043: import com.sun.source.tree.ClassTree;
044: import com.sun.source.tree.CompilationUnitTree;
045: import com.sun.source.tree.IdentifierTree;
046: import com.sun.source.tree.Tree;
047: import java.io.File;
048: import java.io.IOException;
049: import org.netbeans.api.java.source.Task;
050: import org.netbeans.api.java.source.JavaSource;
051: import static org.netbeans.api.java.source.JavaSource.*;
052: import org.netbeans.api.java.source.TestUtilities;
053: import org.netbeans.api.java.source.TreeMaker;
054: import org.netbeans.api.java.source.WorkingCopy;
055: import org.netbeans.junit.NbTestSuite;
056:
057: /**
058: * Tests modifying implements clause in the source.
059: *
060: * @author Pavel Flaska
061: */
062: public class ClassImplementsTest extends GeneratorTestMDRCompat {
063:
064: /** Creates a new instance of ClassImplementsTest */
065: public ClassImplementsTest(String testName) {
066: super (testName);
067: }
068:
069: public static NbTestSuite suite() {
070: NbTestSuite suite = new NbTestSuite();
071: suite.addTestSuite(ClassImplementsTest.class);
072: // suite.addTest(new ClassImplementsTest("testAddFirst"));
073: // suite.addTest(new ClassImplementsTest("testAddFirstToExisting"));
074: // suite.addTest(new ClassImplementsTest("testAddFirstTwo"));
075: // suite.addTest(new ClassImplementsTest("testAddThirdToExisting"));
076: // suite.addTest(new ClassImplementsTest("testRemoveAll"));
077: // suite.addTest(new ClassImplementsTest("testRemoveMid"));
078: // suite.addTest(new ClassImplementsTest("testRemoveFirst"));
079: // suite.addTest(new ClassImplementsTest("testRemoveLast"));
080: // suite.addTest(new ClassImplementsTest("testRemoveJust"));
081: // suite.addTest(new ClassImplementsTest("testAddFirstTypeParam"));
082: // suite.addTest(new ClassImplementsTest("testRemoveAllImplTypeParam"));
083: // suite.addTest(new ClassImplementsTest("testAddFirstImplExtends"));
084: // suite.addTest(new ClassImplementsTest("testRemoveAllImplExtends"));
085: // suite.addTest(new ClassImplementsTest("testRenameInImpl"));
086: // suite.addTest(new ClassImplementsTest("testRenameInImpl2"));
087: return suite;
088: }
089:
090: public void testAddFirst() throws Exception {
091: testFile = new File(getWorkDir(), "Test.java");
092: TestUtilities.copyStringToFile(testFile,
093: "package hierbas.del.litoral;\n\n"
094: + "import java.util.*;\n\n"
095: + "public class Test {\n"
096: + " public void taragui() {\n" + " }\n"
097: + "}\n");
098: String golden = "package hierbas.del.litoral;\n\n"
099: + "import java.util.*;\n\n"
100: + "public class Test implements List {\n"
101: + " public void taragui() {\n" + " }\n" + "}\n";
102:
103: JavaSource src = getJavaSource(testFile);
104: Task task = new Task<WorkingCopy>() {
105:
106: public void run(WorkingCopy workingCopy) throws IOException {
107: workingCopy.toPhase(Phase.RESOLVED);
108: CompilationUnitTree cut = workingCopy
109: .getCompilationUnit();
110: TreeMaker make = workingCopy.getTreeMaker();
111: for (Tree typeDecl : cut.getTypeDecls()) {
112: // should check kind, here we can be sure!
113: ClassTree clazz = (ClassTree) typeDecl;
114: ClassTree copy = make.addClassImplementsClause(
115: clazz, make.Identifier("List"));
116: workingCopy.rewrite(clazz, copy);
117: }
118: }
119:
120: };
121: src.runModificationTask(task).commit();
122: String res = TestUtilities.copyFileToString(testFile);
123: System.err.println(res);
124: assertEquals(golden, res);
125: }
126:
127: // public void testAddMakeInterface() throws Exception {
128: // testFile = new File(getWorkDir(), "Hombre.java");
129: // TestUtilities.copyStringToFile(testFile,
130: // "package hierbas.del.litoral;\n\n" +
131: // "import java.util.*;\n\n" +
132: // "public class Hombre {\n" +
133: // " public void taragui() {\n" +
134: // " }\n" +
135: // "}\n"
136: // );
137: // String golden =
138: // "package hierbas.del.litoral;\n\n" +
139: // "import java.util.*;\n\n" +
140: // "public class Hombre implements DeMundo {\n" +
141: // " public void taragui() {\n" +
142: // " }\n" +
143: // "}\n";
144: //
145: // JavaSource src = getJavaSource(testFile);
146: // Task task = new Task<WorkingCopy>() {
147: //
148: // public void run(WorkingCopy workingCopy) throws IOException {
149: // workingCopy.toPhase(Phase.RESOLVED);
150: // CompilationUnitTree cut = workingCopy.getCompilationUnit();
151: // TreeMaker make = workingCopy.getTreeMaker();
152: // ClassTree inf = make.Interface(
153: // make.Modifiers(Collections.<Modifier>emptySet()),
154: // "DeMundo",
155: // Collections.<TypeParameterTree>emptyList(),
156: // Collections.<ExpressionTree>emptyList(),
157: // Collections.<Tree>emptyList()
158: // );
159: // for (Tree typeDecl : cut.getTypeDecls()) {
160: // // should check kind, here we can be sure!
161: // ClassTree clazz = (ClassTree) typeDecl;
162: // ClassTree copy = make.addClassImplementsClause(
163: // clazz, inf
164: // );
165: // workingCopy.rewrite(clazz, copy);
166: // }
167: // }
168: //
169: // public void cancel() {
170: // throw new UnsupportedOperationException("Not supported yet.");
171: // }
172: // };
173: // src.runModificationTask(task).commit();
174: // String res = TestUtilities.copyFileToString(testFile);
175: // System.err.println(res);
176: // assertEquals(golden, res);
177: // }
178:
179: public void testAddFirstTwo() throws Exception {
180: testFile = new File(getWorkDir(), "Test.java");
181: TestUtilities.copyStringToFile(testFile,
182: "package hierbas.del.litoral;\n\n"
183: + "import java.io.*;\n\n"
184: + "public class Test extends Object {\n"
185: + " public void taragui() {\n" + " }\n"
186: + "}\n");
187: String golden = "package hierbas.del.litoral;\n\n"
188: + "import java.io.*;\n\n"
189: + "public class Test extends Object implements Collection, List {\n"
190: + " public void taragui() {\n" + " }\n" + "}\n";
191:
192: JavaSource src = getJavaSource(testFile);
193: Task task = new Task<WorkingCopy>() {
194:
195: public void run(WorkingCopy workingCopy) throws IOException {
196: workingCopy.toPhase(Phase.RESOLVED);
197: CompilationUnitTree cut = workingCopy
198: .getCompilationUnit();
199: TreeMaker make = workingCopy.getTreeMaker();
200: for (Tree typeDecl : cut.getTypeDecls()) {
201: // should check kind, here we can be sure!
202: ClassTree clazz = (ClassTree) typeDecl;
203: ClassTree copy = make.addClassImplementsClause(
204: clazz, make.Identifier("Collection"));
205: copy = make.addClassImplementsClause(copy, make
206: .Identifier("List"));
207: workingCopy.rewrite(clazz, copy);
208: }
209: }
210:
211: };
212: src.runModificationTask(task).commit();
213: String res = TestUtilities.copyFileToString(testFile);
214: System.err.println(res);
215: assertEquals(golden, res);
216: }
217:
218: public void testRemoveAll() throws Exception {
219: testFile = new File(getWorkDir(), "Test.java");
220: TestUtilities
221: .copyStringToFile(
222: testFile,
223: "package hierbas.del.litoral;\n\n"
224: + "import java.io.*;\n\n"
225: + "public class Test implements Serializable, List, Collection {\n"
226: + " public void taragui() {\n"
227: + " }\n" + "}\n");
228: String golden = "package hierbas.del.litoral;\n\n"
229: + "import java.io.*;\n\n" + "public class Test {\n"
230: + " public void taragui() {\n" + " }\n" + "}\n";
231:
232: JavaSource src = getJavaSource(testFile);
233: Task task = new Task<WorkingCopy>() {
234:
235: public void run(WorkingCopy workingCopy) throws IOException {
236: workingCopy.toPhase(Phase.RESOLVED);
237: CompilationUnitTree cut = workingCopy
238: .getCompilationUnit();
239: TreeMaker make = workingCopy.getTreeMaker();
240: for (Tree typeDecl : cut.getTypeDecls()) {
241: // should check kind, here we can be sure!
242: ClassTree clazz = (ClassTree) typeDecl;
243: ClassTree copy = make.removeClassImplementsClause(
244: clazz, 0);
245: copy = make.removeClassImplementsClause(copy, 0);
246: copy = make.removeClassImplementsClause(copy, 0);
247: workingCopy.rewrite(clazz, copy);
248: }
249: }
250:
251: };
252: src.runModificationTask(task).commit();
253: String res = TestUtilities.copyFileToString(testFile);
254: System.err.println(res);
255: assertEquals(golden, res);
256: }
257:
258: public void testAddThirdToExisting() throws Exception {
259: testFile = new File(getWorkDir(), "Test.java");
260: TestUtilities
261: .copyStringToFile(
262: testFile,
263: "package hierbas.del.litoral;\n\n"
264: + "import java.util.*;\n\n"
265: + "public class Test implements List, Serializable {\n"
266: + " public void taragui() {\n"
267: + " }\n" + "}\n");
268: String golden = "package hierbas.del.litoral;\n\n"
269: + "import java.util.*;\n\n"
270: + "public class Test implements List, Serializable, Collection {\n"
271: + " public void taragui() {\n" + " }\n" + "}\n";
272:
273: JavaSource src = getJavaSource(testFile);
274: Task task = new Task<WorkingCopy>() {
275:
276: public void run(WorkingCopy workingCopy) throws IOException {
277: workingCopy.toPhase(Phase.RESOLVED);
278: CompilationUnitTree cut = workingCopy
279: .getCompilationUnit();
280: TreeMaker make = workingCopy.getTreeMaker();
281: for (Tree typeDecl : cut.getTypeDecls()) {
282: // should check kind, here we can be sure!
283: ClassTree clazz = (ClassTree) typeDecl;
284: ClassTree copy = make.addClassImplementsClause(
285: clazz, make.Identifier("Collection"));
286: workingCopy.rewrite(clazz, copy);
287: }
288: }
289:
290: };
291: src.runModificationTask(task).commit();
292: String res = TestUtilities.copyFileToString(testFile);
293: System.err.println(res);
294: assertEquals(golden, res);
295: }
296:
297: public void testAddFirstToExisting() throws Exception {
298: testFile = new File(getWorkDir(), "Test.java");
299: TestUtilities.copyStringToFile(testFile,
300: "package hierbas.del.litoral;\n\n"
301: + "import java.util.*;\n\n"
302: + "public class Test implements List {\n"
303: + " public void taragui() {\n" + " }\n"
304: + "}\n");
305: String golden = "package hierbas.del.litoral;\n\n"
306: + "import java.util.*;\n\n"
307: + "public class Test implements Serializable, List {\n"
308: + " public void taragui() {\n" + " }\n" + "}\n";
309:
310: JavaSource src = getJavaSource(testFile);
311: Task task = new Task<WorkingCopy>() {
312:
313: public void run(WorkingCopy workingCopy) throws IOException {
314: workingCopy.toPhase(Phase.RESOLVED);
315: CompilationUnitTree cut = workingCopy
316: .getCompilationUnit();
317: TreeMaker make = workingCopy.getTreeMaker();
318: for (Tree typeDecl : cut.getTypeDecls()) {
319: // should check kind, here we can be sure!
320: ClassTree clazz = (ClassTree) typeDecl;
321: ClassTree copy = make.insertClassImplementsClause(
322: clazz, 0, make.Identifier("Serializable"));
323: workingCopy.rewrite(clazz, copy);
324: }
325: }
326:
327: };
328: src.runModificationTask(task).commit();
329: String res = TestUtilities.copyFileToString(testFile);
330: System.err.println(res);
331: assertEquals(golden, res);
332: }
333:
334: public void testRemoveMid() throws Exception {
335: testFile = new File(getWorkDir(), "Test.java");
336: TestUtilities
337: .copyStringToFile(
338: testFile,
339: "package hierbas.del.litoral;\n\n"
340: + "import java.util.*;\n\n"
341: + "public class Test implements List, Serializable, Collection {\n"
342: + " public void taragui() {\n"
343: + " }\n" + "}\n");
344: String golden = "package hierbas.del.litoral;\n\n"
345: + "import java.util.*;\n\n"
346: + "public class Test implements List, Collection {\n"
347: + " public void taragui() {\n" + " }\n" + "}\n";
348:
349: JavaSource src = getJavaSource(testFile);
350: Task task = new Task<WorkingCopy>() {
351:
352: public void run(WorkingCopy workingCopy) throws IOException {
353: workingCopy.toPhase(Phase.RESOLVED);
354: CompilationUnitTree cut = workingCopy
355: .getCompilationUnit();
356: TreeMaker make = workingCopy.getTreeMaker();
357: for (Tree typeDecl : cut.getTypeDecls()) {
358: // should check kind, here we can be sure!
359: ClassTree clazz = (ClassTree) typeDecl;
360: ClassTree copy = make.removeClassImplementsClause(
361: clazz, 1);
362: workingCopy.rewrite(clazz, copy);
363: }
364: }
365:
366: };
367: src.runModificationTask(task).commit();
368: String res = TestUtilities.copyFileToString(testFile);
369: System.err.println(res);
370: assertEquals(golden, res);
371: }
372:
373: public void testRemoveFirst() throws Exception {
374: testFile = new File(getWorkDir(), "Test.java");
375: TestUtilities.copyStringToFile(testFile,
376: "package hierbas.del.litoral;\n\n"
377: + "import java.util.*;\n\n"
378: + "public class Test implements List {\n"
379: + " public void taragui() {\n" + " }\n"
380: + "}\n");
381: String golden = "package hierbas.del.litoral;\n\n"
382: + "import java.util.*;\n\n" + "public class Test {\n"
383: + " public void taragui() {\n" + " }\n" + "}\n";
384:
385: JavaSource src = getJavaSource(testFile);
386: Task task = new Task<WorkingCopy>() {
387:
388: public void run(WorkingCopy workingCopy) throws IOException {
389: workingCopy.toPhase(Phase.RESOLVED);
390: CompilationUnitTree cut = workingCopy
391: .getCompilationUnit();
392: TreeMaker make = workingCopy.getTreeMaker();
393: for (Tree typeDecl : cut.getTypeDecls()) {
394: // should check kind, here we can be sure!
395: ClassTree clazz = (ClassTree) typeDecl;
396: ClassTree copy = make.removeClassImplementsClause(
397: clazz, 0);
398: workingCopy.rewrite(clazz, copy);
399: }
400: }
401:
402: };
403: src.runModificationTask(task).commit();
404: String res = TestUtilities.copyFileToString(testFile);
405: System.err.println(res);
406: assertEquals(golden, res);
407: }
408:
409: public void testRemoveLast() throws Exception {
410: testFile = new File(getWorkDir(), "Test.java");
411: TestUtilities
412: .copyStringToFile(
413: testFile,
414: "package hierbas.del.litoral;\n\n"
415: + "import java.util.*;\n\n"
416: + "public class Test implements List, Collection, Serializable {\n"
417: + " public void taragui() {\n"
418: + " }\n" + "}\n");
419: String golden = "package hierbas.del.litoral;\n\n"
420: + "import java.util.*;\n\n"
421: + "public class Test implements List, Collection {\n"
422: + " public void taragui() {\n" + " }\n" + "}\n";
423:
424: JavaSource src = getJavaSource(testFile);
425: Task task = new Task<WorkingCopy>() {
426:
427: public void run(WorkingCopy workingCopy) throws IOException {
428: workingCopy.toPhase(Phase.RESOLVED);
429: CompilationUnitTree cut = workingCopy
430: .getCompilationUnit();
431: TreeMaker make = workingCopy.getTreeMaker();
432: for (Tree typeDecl : cut.getTypeDecls()) {
433: // should check kind, here we can be sure!
434: ClassTree clazz = (ClassTree) typeDecl;
435: ClassTree copy = make.removeClassImplementsClause(
436: clazz, 2);
437: workingCopy.rewrite(clazz, copy);
438: }
439: }
440:
441: };
442: src.runModificationTask(task).commit();
443: String res = TestUtilities.copyFileToString(testFile);
444: System.err.println(res);
445: assertEquals(golden, res);
446: }
447:
448: public void testRemoveJust() throws Exception {
449: testFile = new File(getWorkDir(), "Test.java");
450: TestUtilities
451: .copyStringToFile(
452: testFile,
453: "package hierbas.del.litoral;\n\n"
454: + "import java.util.*;\n\n"
455: + "public class Test implements List, Collection {\n"
456: + " public void taragui() {\n"
457: + " }\n" + "}\n");
458: String golden = "package hierbas.del.litoral;\n\n"
459: + "import java.util.*;\n\n" + "public class Test {\n"
460: + " public void taragui() {\n" + " }\n" + "}\n";
461:
462: JavaSource src = getJavaSource(testFile);
463: Task task = new Task<WorkingCopy>() {
464:
465: public void run(WorkingCopy workingCopy) throws IOException {
466: workingCopy.toPhase(Phase.RESOLVED);
467: CompilationUnitTree cut = workingCopy
468: .getCompilationUnit();
469: TreeMaker make = workingCopy.getTreeMaker();
470: for (Tree typeDecl : cut.getTypeDecls()) {
471: // should check kind, here we can be sure!
472: ClassTree clazz = (ClassTree) typeDecl;
473: ClassTree copy = make.removeClassImplementsClause(
474: clazz, 1);
475: copy = make.removeClassImplementsClause(copy, 0);
476: workingCopy.rewrite(clazz, copy);
477: }
478: }
479:
480: };
481: src.runModificationTask(task).commit();
482: String res = TestUtilities.copyFileToString(testFile);
483: System.err.println(res);
484: assertEquals(golden, res);
485: }
486:
487: public void testAddFirstTypeParam() throws Exception {
488: testFile = new File(getWorkDir(), "Test.java");
489: TestUtilities.copyStringToFile(testFile,
490: "package hierbas.del.litoral;\n\n"
491: + "import java.util.*;\n\n"
492: + "public class Test<E> {\n"
493: + " public void taragui() {\n" + " }\n"
494: + "}\n");
495: String golden = "package hierbas.del.litoral;\n\n"
496: + "import java.util.*;\n\n"
497: + "public class Test<E> implements List {\n"
498: + " public void taragui() {\n" + " }\n" + "}\n";
499:
500: JavaSource src = getJavaSource(testFile);
501: Task task = new Task<WorkingCopy>() {
502:
503: public void run(WorkingCopy workingCopy) throws IOException {
504: workingCopy.toPhase(Phase.RESOLVED);
505: CompilationUnitTree cut = workingCopy
506: .getCompilationUnit();
507: TreeMaker make = workingCopy.getTreeMaker();
508: for (Tree typeDecl : cut.getTypeDecls()) {
509: // should check kind, here we can be sure!
510: ClassTree clazz = (ClassTree) typeDecl;
511: ClassTree copy = make.addClassImplementsClause(
512: clazz, make.Identifier("List"));
513: workingCopy.rewrite(clazz, copy);
514: }
515: }
516:
517: };
518: src.runModificationTask(task).commit();
519: String res = TestUtilities.copyFileToString(testFile);
520: System.err.println(res);
521: assertEquals(golden, res);
522: }
523:
524: public void testRemoveAllImplTypeParam() throws Exception {
525: testFile = new File(getWorkDir(), "Test.java");
526: TestUtilities.copyStringToFile(testFile,
527: "package hierbas.del.litoral;\n\n"
528: + "import java.util.*;\n\n"
529: + "public class Test<E> implements List {\n"
530: + " public void taragui() {\n" + " }\n"
531: + "}\n");
532: String golden = "package hierbas.del.litoral;\n\n"
533: + "import java.util.*;\n\n"
534: + "public class Test<E> {\n"
535: + " public void taragui() {\n" + " }\n" + "}\n";
536:
537: JavaSource src = getJavaSource(testFile);
538: Task task = new Task<WorkingCopy>() {
539:
540: public void run(WorkingCopy workingCopy) throws IOException {
541: workingCopy.toPhase(Phase.RESOLVED);
542: CompilationUnitTree cut = workingCopy
543: .getCompilationUnit();
544: TreeMaker make = workingCopy.getTreeMaker();
545: for (Tree typeDecl : cut.getTypeDecls()) {
546: // should check kind, here we can be sure!
547: ClassTree clazz = (ClassTree) typeDecl;
548: ClassTree copy = make.removeClassImplementsClause(
549: clazz, 0);
550: workingCopy.rewrite(clazz, copy);
551: }
552: }
553:
554: };
555: src.runModificationTask(task).commit();
556: String res = TestUtilities.copyFileToString(testFile);
557: System.err.println(res);
558: assertEquals(golden, res);
559: }
560:
561: public void testAddFirstImplExtends() throws Exception {
562: testFile = new File(getWorkDir(), "Test.java");
563: TestUtilities.copyStringToFile(testFile,
564: "package hierbas.del.litoral;\n\n"
565: + "import java.util.*;\n\n"
566: + "public class Test<E> extends Object {\n"
567: + " public void taragui() {\n" + " }\n"
568: + "}\n");
569: String golden = "package hierbas.del.litoral;\n\n"
570: + "import java.util.*;\n\n"
571: + "public class Test<E> extends Object implements List {\n"
572: + " public void taragui() {\n" + " }\n" + "}\n";
573:
574: JavaSource src = getJavaSource(testFile);
575: Task task = new Task<WorkingCopy>() {
576:
577: public void run(WorkingCopy workingCopy) throws IOException {
578: workingCopy.toPhase(Phase.RESOLVED);
579: CompilationUnitTree cut = workingCopy
580: .getCompilationUnit();
581: TreeMaker make = workingCopy.getTreeMaker();
582: for (Tree typeDecl : cut.getTypeDecls()) {
583: // should check kind, here we can be sure!
584: ClassTree clazz = (ClassTree) typeDecl;
585: ClassTree copy = make.addClassImplementsClause(
586: clazz, make.Identifier("List"));
587: workingCopy.rewrite(clazz, copy);
588: }
589: }
590:
591: };
592: src.runModificationTask(task).commit();
593: String res = TestUtilities.copyFileToString(testFile);
594: System.err.println(res);
595: assertEquals(golden, res);
596: }
597:
598: public void testRemoveAllImplExtends() throws Exception {
599: testFile = new File(getWorkDir(), "Test.java");
600: TestUtilities
601: .copyStringToFile(
602: testFile,
603: "package hierbas.del.litoral;\n\n"
604: + "import java.util.*;\n\n"
605: + "public class Test<E> extends Object implements List {\n"
606: + " public void taragui() {\n"
607: + " }\n" + "}\n");
608: String golden = "package hierbas.del.litoral;\n\n"
609: + "import java.util.*;\n\n"
610: + "public class Test<E> extends Object {\n"
611: + " public void taragui() {\n" + " }\n" + "}\n";
612:
613: JavaSource src = getJavaSource(testFile);
614: Task task = new Task<WorkingCopy>() {
615:
616: public void run(WorkingCopy workingCopy) throws IOException {
617: workingCopy.toPhase(Phase.RESOLVED);
618: CompilationUnitTree cut = workingCopy
619: .getCompilationUnit();
620: TreeMaker make = workingCopy.getTreeMaker();
621: for (Tree typeDecl : cut.getTypeDecls()) {
622: // should check kind, here we can be sure!
623: ClassTree clazz = (ClassTree) typeDecl;
624: ClassTree copy = make.removeClassImplementsClause(
625: clazz, 0);
626: workingCopy.rewrite(clazz, copy);
627: }
628: }
629:
630: };
631: src.runModificationTask(task).commit();
632: String res = TestUtilities.copyFileToString(testFile);
633: System.err.println(res);
634: assertEquals(golden, res);
635: }
636:
637: public void testRenameInImpl() throws Exception {
638: testFile = new File(getWorkDir(), "Test.java");
639: TestUtilities
640: .copyStringToFile(
641: testFile,
642: "package hierbas.del.litoral;\n\n"
643: + "import java.util.*;\n\n"
644: + "public class Test<E> extends Object implements List {\n"
645: + " public void taragui() {\n"
646: + " }\n" + "}\n");
647: String golden = "package hierbas.del.litoral;\n\n"
648: + "import java.util.*;\n\n"
649: + "public class Test<E> extends Object implements Seznam {\n"
650: + " public void taragui() {\n" + " }\n" + "}\n";
651:
652: JavaSource src = getJavaSource(testFile);
653: Task task = new Task<WorkingCopy>() {
654:
655: public void run(WorkingCopy workingCopy) throws IOException {
656: workingCopy.toPhase(Phase.RESOLVED);
657: CompilationUnitTree cut = workingCopy
658: .getCompilationUnit();
659: TreeMaker make = workingCopy.getTreeMaker();
660: for (Tree typeDecl : cut.getTypeDecls()) {
661: // should check kind, here we can be sure!
662: ClassTree clazz = (ClassTree) typeDecl;
663: IdentifierTree ident = (IdentifierTree) clazz
664: .getImplementsClause().get(0);
665: workingCopy.rewrite(ident, make.setLabel(ident,
666: "Seznam"));
667: }
668: }
669:
670: };
671: src.runModificationTask(task).commit();
672: String res = TestUtilities.copyFileToString(testFile);
673: System.err.println(res);
674: assertEquals(golden, res);
675: }
676:
677: public void testRenameInImpl2() throws Exception {
678: testFile = new File(getWorkDir(), "Test.java");
679: TestUtilities
680: .copyStringToFile(
681: testFile,
682: "package hierbas.del.litoral;\n\n"
683: + "import java.util.*;\n\n"
684: + "public class Test<E> extends Object implements PropertyChangeListener, List {\n"
685: + " public void taragui() {\n"
686: + " }\n" + "}\n");
687: String golden = "package hierbas.del.litoral;\n\n"
688: + "import java.util.*;\n\n"
689: + "public class Test<E> extends Object implements PropertyChangeListener, Seznam {\n"
690: + " public void taragui() {\n" + " }\n" + "}\n";
691:
692: JavaSource src = getJavaSource(testFile);
693: Task task = new Task<WorkingCopy>() {
694:
695: public void run(WorkingCopy workingCopy) throws IOException {
696: workingCopy.toPhase(Phase.RESOLVED);
697: CompilationUnitTree cut = workingCopy
698: .getCompilationUnit();
699: TreeMaker make = workingCopy.getTreeMaker();
700: for (Tree typeDecl : cut.getTypeDecls()) {
701: // should check kind, here we can be sure!
702: ClassTree clazz = (ClassTree) typeDecl;
703: IdentifierTree ident = (IdentifierTree) clazz
704: .getImplementsClause().get(1);
705: workingCopy.rewrite(ident, make.setLabel(ident,
706: "Seznam"));
707: }
708: }
709:
710: };
711: src.runModificationTask(task).commit();
712: String res = TestUtilities.copyFileToString(testFile);
713: System.err.println(res);
714: assertEquals(golden, res);
715: }
716:
717: protected void setUp() throws Exception {
718: super .setUp();
719: testFile = getFile(getSourceDir(), getSourcePckg()
720: + "Test.java");
721: }
722:
723: String getGoldenPckg() {
724: return "";
725: }
726:
727: String getSourcePckg() {
728: return "";
729: }
730:
731: }
|