KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > java > parsing > Remover


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
20 /*
21  * Remover.java
22  *
23  * Created on June 26, 2000, 9:29 AM
24  */

25
26 package org.netbeans.test.java.parsing.Remover;
27
28 //import org.openide.src.FieldElement;
29
//import org.openide.src.Identifier;
30
import org.netbeans.test.java.Common;
31
32 /** <B>Java Module General API Test: Remover</B>
33  * <BR><BR><I>What it tests:</I><BR>
34  * Removing and modifying existing Elements.
35  * This tests takes complex class and tries to modify it's Elements (FieldElement, MethodElement, ClassElement, InitializerElement, ConstructorElement).
36  * Modification is made using setters on this Elements.
37  * Parser must have correct information about all Elements, otherwise removing is incorrect.
38  * Test is focused on checking of correctness of generated code.
39  * <BR><BR><I>How it works:</I><BR>
40  * Existing class (javam.testsources.EtalonForRemover) is copy()ed using DataObject.copy() into different package (in order to preserve changes).
41  * There are lots of modifications(using setters) made on this ClassElement's Elements. These are also romoved.
42  * These actions cause generating of .java code. This code is compared with supposed one.
43  * <BR><BR><I>Output:</I><BR>
44  * Generated Java code.
45  * <BR><BR><I>Possible reasons of failure:</I><BR>
46  * <BR><BR><U>Exception occured:</U><BR>
47  * This is the most probable case. See .out file for StackTrace it will be very usefull.
48  * <BR><BR><U>Some Elements missing/are left over</U><BR>
49  * See .diff file to get which ones
50  * <BR><BR><U>Bad indentation</U><BR>
51  * This is probably not a bug of Java Module. (Editor Bug)
52  * In .diff file could be some whitespaces.
53  *
54  * @author Jan Becicka <Jan.Becicka@sun.com>
55  */

56
57
58 public class Remover extends org.netbeans.test.java.XRunner {
59     
60     public static void main(java.lang.String JavaDoc[] args) {
61         junit.textui.TestRunner.run(suite());
62     }
63     
64     public Remover() {
65         super("");
66     }
67     
68     public Remover(java.lang.String JavaDoc testName) {
69         super(testName);
70     }
71     
72     public static org.netbeans.junit.NbTest suite() {
73         return new org.netbeans.junit.NbTestSuite(Remover.class);
74     }
75     
76     /** "body" of this TestCase
77      * @param o SourceElement - target for generating
78      * @param log log is used for logging StackTraces
79      * @throws Exception
80      * @return true if test passed
81      * false if failed
82      */

83     public boolean go(Object JavaDoc o, java.io.PrintWriter JavaDoc log) throws Exception JavaDoc {
84 // org.openide.src.ClassElement clazz = ((org.openide.src.SourceElement) o).getClasses()[0];
85
//
86
// FieldElement[] fieldsToRemove1 = new FieldElement[4];
87
// fieldsToRemove1[0] = clazz.getField(Identifier.create("a"));
88
// fieldsToRemove1[1] = clazz.getField(Identifier.create("f"));
89
// fieldsToRemove1[2] = clazz.getField(Identifier.create("fa"));
90
// fieldsToRemove1[3] = clazz.getField(Identifier.create("fe"));
91
//
92
// clazz.removeFields(fieldsToRemove1);
93
//
94
// clazz.getField(Identifier.create("b")).setType(org.openide.src.Type.FLOAT);
95
// clazz.getField(Identifier.create("d")).setType(org.openide.src.Type.FLOAT);
96
//
97
//
98
// FieldElement[] fieldsToRemove2 = new FieldElement[2];
99
// fieldsToRemove2[0] = clazz.getField(Identifier.create("c"));
100
// fieldsToRemove2[1] = clazz.getField(Identifier.create("e"));
101
//
102
// //!!!bug
103
// clazz.removeFields(fieldsToRemove2);
104
//
105
// clazz.removeMethod(clazz.getMethod(Identifier.create("doNothing"),null));
106
// clazz.removeMethod(clazz.getMethod(Identifier.create("doImportant"),null));
107
//
108
// org.openide.src.MethodElement[] methodsToRemove1 = new org.openide.src.MethodElement[3];
109
// methodsToRemove1[0] = clazz.getMethod(Identifier.create("method1"),Common.TPARS1);
110
// methodsToRemove1[1] = clazz.getMethod(Identifier.create("method2"),Common.TPARS1);
111
// methodsToRemove1[2] = clazz.getMethod(Identifier.create("method2"),Common.TPARS3);
112
// clazz.removeMethods(methodsToRemove1);
113
//
114
// clazz.removeClasses(clazz.getClasses());
115
//
116
// clazz.getField(Identifier.create("fb")).setInitValue("0.3");
117
//
118
// //???bug???
119
// clazz.getField(Identifier.create("fd")).setInitValue("0.4");
120
//
121
// org.openide.src.MethodElement me = clazz.getMethod(Identifier.create("method2"),Common.TPARS2);
122
// me.setName(Identifier.create("renamedMethod2"));
123
// me.setParameters(Common.PARS3);
124
// me.setReturn(org.openide.src.Type.FLOAT);
125
// me.setModifiers(java.lang.reflect.Modifier.SYNCHRONIZED | java.lang.reflect.Modifier.PRIVATE);
126
return true;
127     }
128     
129     /**
130      */

131     protected void setUp() {
132         super.setUp();
133         name = "Remover";
134         packageName = "org.netbeans.test.java.testsources";
135     }
136     
137 }
138
Popular Tags