1 19 20 package org.netbeans.api.java.source.gen; 21 22 import com.sun.source.tree.MethodTree; 23 import com.sun.source.tree.ModifiersTree; 24 import java.io.IOException ; 25 import java.util.HashSet ; 26 import java.util.Map ; 27 import java.util.Set ; 28 import javax.lang.model.element.Modifier; 29 import org.netbeans.api.java.source.CancellableTask; 30 import org.netbeans.api.java.source.CompilationController; 31 import org.netbeans.api.lexer.TokenHierarchy; 32 import org.netbeans.junit.NbTestSuite; 33 import org.netbeans.api.java.source.transform.Transformer; 34 35 39 40 public class CompareTreeTest extends GeneratorTest { 41 42 43 public CompareTreeTest(String name) { 44 super(name); 45 } 46 47 public static NbTestSuite suite() { 48 NbTestSuite suite = new NbTestSuite(CompareTreeTest.class); 49 return suite; 50 } 51 52 protected void setUp() throws Exception { 53 super.setUp(); 54 testFile = getFile(getSourceDir(), getSourcePckg() + "MethodTest1.java"); 55 } 56 94 95 public void testMethodName() throws IOException { 96 final TokenHierarchy[] cut = new TokenHierarchy[2]; 97 getJavaSource(getTestFile()).runUserActionTask(new CancellableTask<CompilationController>() { 98 public void cancel() { 99 } 100 public void run(CompilationController cc) { 101 cut[0] = cc.getTokenHierarchy(); 102 } 103 },true); 104 process( 105 new Transformer<Void , Object >() { 106 public Void visitMethod(MethodTree node, Object p) { 107 super.visitMethod(node, p); 108 if ("secondMethod".contentEquals(node.getName())) { 109 MethodTree njuMethod = make.setLabel(node, "druhaMetoda"); 110 changes.rewrite(node, njuMethod); 111 } 112 return null; 113 } 114 } 115 ); 116 getJavaSource(getTestFile()).runUserActionTask(new CancellableTask<CompilationController>() { 117 public void cancel() { 118 } 119 public void run(CompilationController cc) { 120 cut[1] = cc.getTokenHierarchy(); 121 } 122 },true); 123 Map <Object , CharSequence []> result = TreeChecker.compareTokens(cut[0], cut[1]); 124 for (Map.Entry <Object , CharSequence []> item : result.entrySet()) { 126 System.out.println(item.getKey() + ": '" + item.getValue()[0] + "' != '" + item.getValue()[1] + "'"); 127 } 128 } 129 130 String getGoldenPckg() { 131 return "org/netbeans/jmi/javamodel/codegen/MethodTest1/MethodTest1/"; 132 } 133 134 String getSourcePckg() { 135 return "org/netbeans/test/codegen/"; 136 } 137 138 } 139 | Popular Tags |