KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 JavaDoc;
31 import org.netbeans.junit.NbTestSuite;
32 import junit.textui.TestRunner;
33 import org.netbeans.api.java.source.transform.Transformer;
34
35 /**
36  *
37  * @author Pavel Flaska
38  */

39 public class LabelsTest extends GeneratorTest {
40     
41     /** Creates a new instance of LabelsTest */
42     public LabelsTest(String JavaDoc 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 JavaDoc {
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 JavaDoc {
59         process(new LabelVisitor());
60         assertFiles("testIdentifiers.pass");
61     }
62     
63     class LabelVisitor<Void, Object> extends Transformer<Void JavaDoc, Object JavaDoc> {
64
65         public Void JavaDoc visitMethod(MethodTree node, Object JavaDoc 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 JavaDoc visitBreak(BreakTree node, Object JavaDoc 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 JavaDoc visitContinue(ContinueTree node, Object JavaDoc 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 JavaDoc visitClass(ClassTree node, Object JavaDoc 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 JavaDoc visitLabeledStatement(LabeledStatementTree node, Object JavaDoc 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 JavaDoc visitMemberSelect(MemberSelectTree node, Object JavaDoc 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 JavaDoc visitIdentifier(IdentifierTree node, Object JavaDoc 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 JavaDoc visitTypeParameter(TypeParameterTree node, Object JavaDoc 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 JavaDoc visitVariable(VariableTree node, Object JavaDoc 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 JavaDoc[] args) {
141         TestRunner.run(suite());
142     }
143     
144     String JavaDoc getGoldenPckg() {
145         return "org/netbeans/jmi/javamodel/codegen/LabelsTest/";
146     }
147
148     String JavaDoc getSourcePckg() {
149         return "org/netbeans/test/codegen/labels/";
150     }
151     
152 }
153
Popular Tags