KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > java > source > gen > Field5Test


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.api.java.source.gen;
20
21 import com.sun.source.tree.ClassTree;
22 import com.sun.source.tree.IdentifierTree;
23 import com.sun.source.tree.MethodTree;
24 import com.sun.source.tree.VariableTree;
25 import java.io.File JavaDoc;
26 import org.netbeans.api.java.source.TestUtilities;
27 import org.netbeans.api.java.source.transform.Transformer;
28
29 /**
30  * Test name change.
31  *
32  * @author Pavel Flaska
33  */

34 public class Field5Test extends GeneratorTest {
35     
36     /**
37      * Creates a new instance of Field5Test
38      */

39     public Field5Test(String JavaDoc testName) {
40         super(testName);
41     }
42     
43     public void testChangeParName() throws Exception JavaDoc {
44         testFile = new File JavaDoc(getWorkDir(), "Test.java");
45         TestUtilities.copyStringToFile(testFile,
46             "package yerba.mate;\n\n" +
47             "import java.io.File;\n\n" +
48             "public class Test {\n" +
49             " public void hierbasDelLitoral(Test[] arrFile) {\n" +
50             " }\n" +
51             "}\n"
52             );
53         String JavaDoc golden =
54             "package yerba.mate;\n\n" +
55             "import java.io.File;\n\n" +
56             "public class Test2 {\n" +
57             " public void hierbasDelLitoral(Test2[] arrFile) {\n" +
58             " }\n" +
59             "}\n";
60
61         process(
62             new Transformer<Void JavaDoc, Object JavaDoc>() {
63             
64                 public Void JavaDoc visitClass(ClassTree node, Object JavaDoc p) {
65                     super.visitClass(node, p);
66                     if ("Test".contentEquals(node.getSimpleName())) {
67                         System.err.println("visitClass");
68                         changes.rewrite(node, make.setLabel(node, "Test2"));
69                     }
70                     return null;
71                 }
72                 
73                 public Void JavaDoc visitIdentifier(IdentifierTree node, Object JavaDoc p) {
74                     super.visitIdentifier(node, p);
75                     if ("Test".contentEquals(node.getName())) {
76                         System.err.println("visitIdentifier");
77                         changes.rewrite(node, make.setLabel(node, "Test2"));
78                     }
79                     return null;
80                 }
81             }
82         );
83         String JavaDoc res = TestUtilities.copyFileToString(testFile);
84         assertEquals(golden, res);
85     }
86     
87     protected void setUp() throws Exception JavaDoc {
88         super.setUp();
89         testFile = getFile(getSourceDir(), getSourcePckg() + "Test.java");
90     }
91
92     String JavaDoc getGoldenPckg() {
93         return "";
94     }
95
96     String JavaDoc getSourcePckg() {
97         return "";
98     }
99     
100 }
101
Popular Tags