1 19 package org.netbeans.api.java.source.gen; 20 21 import com.sun.source.tree.BreakTree; 22 import com.sun.source.tree.ClassTree; 23 import com.sun.source.tree.ContinueTree; 24 import com.sun.source.tree.IdentifierTree; 25 import com.sun.source.tree.LabeledStatementTree; 26 import com.sun.source.tree.MemberSelectTree; 27 import com.sun.source.tree.MethodTree; 28 import com.sun.source.tree.TypeParameterTree; 29 import com.sun.source.tree.VariableTree; 30 import java.io.IOException ; 31 import org.netbeans.junit.NbTestSuite; 32 import junit.textui.TestRunner; 33 import org.netbeans.api.java.source.transform.Transformer; 34 35 39 public class LabelsTest extends GeneratorTest { 40 41 42 public LabelsTest(String name) { 43 super(name); 44 } 45 46 public static NbTestSuite suite() { 47 NbTestSuite suite = new NbTestSuite(); 48 suite.addTest(new LabelsTest("testIdentifiers")); 49 return suite; 50 } 51 52 protected void setUp() throws Exception { 53 super.setUp(); 54 testFile = getFile(getSourceDir(), getSourcePckg() + "SetLabelTestClass.java"); 55 System.err.println(testFile.getAbsoluteFile().toString()); 56 } 57 58 public void testIdentifiers() throws IOException { 59 process(new LabelVisitor()); 60 assertFiles("testIdentifiers.pass"); 61 } 62 63 class LabelVisitor<Void, Object> extends Transformer<Void , Object > { 64 65 public Void visitMethod(MethodTree node, Object p) { 66 System.err.println("visitMethod: " + node.getName()); 67 super.visitMethod(node, p); 68 MethodTree copy = make.setLabel(node, node.getName() + "0"); 69 changes.rewrite(node, copy); 70 return null; 71 } 72 73 public Void visitBreak(BreakTree node, Object p) { 74 System.err.println("visitBreak: " + node.getLabel()); 75 super.visitBreak(node, p); 76 BreakTree copy = make.setLabel(node, node.getLabel() + "0"); 77 changes.rewrite(node, copy); 78 return null; 79 } 80 81 public Void visitContinue(ContinueTree node, Object p) { 82 System.err.println("visitContinue: " + node.getLabel()); 83 super.visitContinue(node, p); 84 ContinueTree copy = make.setLabel(node, node.getLabel() + "0"); 85 changes.rewrite(node, copy); 86 return null; 87 } 88 89 public Void visitClass(ClassTree node, Object p) { 90 System.err.println("visitClass: " + node.getSimpleName()); 91 super.visitClass(node, p); 92 ClassTree copy = make.setLabel(node, node.getSimpleName() + "0"); 93 changes.rewrite(node, copy); 94 return null; 95 } 96 97 public Void visitLabeledStatement(LabeledStatementTree node, Object p) { 98 System.err.println("visitLabeledStatement: " + node.getLabel()); 99 super.visitLabeledStatement(node, p); 100 LabeledStatementTree copy = make.setLabel(node, node.getLabel() + "0"); 101 changes.rewrite(node, copy); 102 return null; 103 } 104 105 public Void visitMemberSelect(MemberSelectTree node, Object p) { 106 System.err.println("visitMemberSelect: " + node.getIdentifier()); 107 super.visitMemberSelect(node, p); 108 MemberSelectTree copy = make.setLabel(node, node.getIdentifier() + "0"); 109 changes.rewrite(node, copy); 110 return null; 111 } 112 113 public Void visitIdentifier(IdentifierTree node, Object p) { 114 System.err.println("visitIdentifier: " + node.getName()); 115 super.visitIdentifier(node, p); 116 System.err.println("I: " + node); 117 IdentifierTree copy = make.setLabel(node, node.getName() + "0"); 118 changes.rewrite(node, copy); 119 return null; 120 } 121 122 public Void visitTypeParameter(TypeParameterTree node, Object p) { 123 System.err.println("visitTypeParameter: " + node.getName()); 124 super.visitTypeParameter(node, p); 125 TypeParameterTree copy = make.setLabel(node, node.getName() + "0"); 126 changes.rewrite(node, copy); 127 return null; 128 } 129 130 public Void visitVariable(VariableTree node, Object p) { 131 System.err.println("visitVariable: " + node.getName()); 132 super.visitVariable(node, p); 133 VariableTree copy = make.setLabel(node, node.getName() + "0"); 134 changes.rewrite(node, copy); 135 return null; 136 } 137 138 } 139 140 public static void main(String [] args) { 141 TestRunner.run(suite()); 142 } 143 144 String getGoldenPckg() { 145 return "org/netbeans/jmi/javamodel/codegen/LabelsTest/"; 146 } 147 148 String getSourcePckg() { 149 return "org/netbeans/test/codegen/labels/"; 150 } 151 152 } 153 | Popular Tags |