1 19 package org.netbeans.api.java.source.gen; 20 21 import com.sun.source.tree.*; 22 import java.io.*; 23 import java.util.Collections ; 24 import org.netbeans.api.java.source.*; 25 import org.netbeans.api.java.source.JavaSource.Phase; 26 import org.netbeans.junit.NbTestSuite; 27 28 34 public class VarArgsTest extends GeneratorTestMDRCompat { 35 36 37 public VarArgsTest(String testName) { 38 super(testName); 39 } 40 41 public static NbTestSuite suite() { 42 NbTestSuite suite = new NbTestSuite(); 43 suite.addTestSuite(VarArgsTest.class); 44 return suite; 45 } 46 47 public void testMethodWithVarargs() throws Exception { 48 testFile = new File(getWorkDir(), "Test.java"); 49 TestUtilities.copyStringToFile(testFile, 50 "package hierbas.del.litoral;\n\n" + 51 "import java.io.File;\n\n" + 52 "public class Test {\n\n" + 53 " void method(Object[] a) {\n" + 54 " }\n\n" + 55 "}\n" 56 ); 57 String golden = 58 "package hierbas.del.litoral;\n\n" + 59 "import java.io.File;\n\n" + 60 "public class Test {\n\n" + 61 " void method(Object... a) {\n" + 62 " }\n\n" + 63 "}\n"; 64 65 JavaSource src = getJavaSource(testFile); 66 67 CancellableTask task = new CancellableTask<WorkingCopy>() { 68 69 public void run(WorkingCopy workingCopy) throws IOException { 70 workingCopy.toPhase(Phase.RESOLVED); 71 CompilationUnitTree cut = workingCopy.getCompilationUnit(); 72 TreeMaker make = workingCopy.getTreeMaker(); 73 74 ClassTree clazz = (ClassTree) workingCopy.getCompilationUnit().getTypeDecls().get(0); 75 MethodTree method = (MethodTree) clazz.getMembers().get(1); 76 VariableTree parameter = method.getParameters().get(0); 77 long VARARGS = 1L<<34; 78 ModifiersTree newMods = make.Modifiers(VARARGS, Collections.<AnnotationTree>emptyList()); 79 workingCopy.rewrite(parameter.getModifiers(), newMods); 80 } 81 82 public void cancel() { 83 } 84 }; 85 src.runModificationTask(task).commit(); 86 String res = TestUtilities.copyFileToString(testFile); 87 System.err.println(res); 88 assertEquals(golden, res); 89 } 90 91 String getGoldenPckg() { 92 return ""; 93 } 94 95 String getSourcePckg() { 96 return ""; 97 } 98 } 99 | Popular Tags |