1 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 ; 26 import org.netbeans.api.java.source.TestUtilities; 27 import org.netbeans.api.java.source.transform.Transformer; 28 29 34 public class Field5Test extends GeneratorTest { 35 36 39 public Field5Test(String testName) { 40 super(testName); 41 } 42 43 public void testChangeParName() throws Exception { 44 testFile = new File (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 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 , Object >() { 63 64 public Void visitClass(ClassTree node, Object 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 visitIdentifier(IdentifierTree node, Object 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 res = TestUtilities.copyFileToString(testFile); 84 assertEquals(golden, res); 85 } 86 87 protected void setUp() throws Exception { 88 super.setUp(); 89 testFile = getFile(getSourceDir(), getSourcePckg() + "Test.java"); 90 } 91 92 String getGoldenPckg() { 93 return ""; 94 } 95 96 String getSourcePckg() { 97 return ""; 98 } 99 100 } 101 | Popular Tags |