KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > gulden > util > javasource > SourceObjectDeclaredVisible


1 /*
2  * Project: BeautyJ - Customizable Java Source Code Transformer
3  * Class: de.gulden.util.javasource.SourceObjectDeclaredVisible
4  * Version: 1.0
5  *
6  * Date: 2002-10-27
7  *
8  * Note: Contains auto-generated Javadoc comments created by BeautyJ.
9  *
10  * This is licensed under the GNU General Public License (GPL)
11  * and comes with NO WARRANTY. See file license.txt for details.
12  *
13  * Author: Jens Gulden
14  * Email: beautyj@jensgulden.de
15  */

16
17 package de.gulden.util.javasource;
18
19 import de.gulden.util.javasource.jjt.Node;
20 import de.gulden.util.javasource.jjt.*;
21 import de.gulden.util.xml.XMLToolbox;
22 import javax.xml.parsers.*;
23 import org.w3c.dom.*;
24 import java.io.*;
25 import java.util.*;
26
27 /**
28  * Class SourceObjectDeclaredVisible.
29  *
30  * @author Jens Gulden
31  * @version 1.0
32  */

33 public abstract class SourceObjectDeclaredVisible extends SourceObjectDeclared {
34
35     // ------------------------------------------------------------------------
36
// --- methods ---
37
// ------------------------------------------------------------------------
38
/**
39      * Output this object as XML.
40      *
41      * @return The XML tag.
42      * @see #initFromXML
43      */

44     public Element buildXML(Document d) {
45         Element e=super.buildXML(d);
46         
47         e.setAttribute("unqualifiedName",getUnqualifiedName());
48         
49         if (java.lang.reflect.Modifier.isStatic(modifier)) {
50             e.setAttribute("static","yes");
51         }
52         if (java.lang.reflect.Modifier.isAbstract(modifier)) {
53             e.setAttribute("abstract","yes");
54         }
55         if (java.lang.reflect.Modifier.isSynchronized(modifier)) {
56             e.setAttribute("synchronized","yes");
57         }
58         if (java.lang.reflect.Modifier.isTransient(modifier)) {
59             e.setAttribute("transient","yes");
60         }
61         if (java.lang.reflect.Modifier.isVolatile(modifier)) {
62             e.setAttribute("volatile","yes");
63         }
64         if (java.lang.reflect.Modifier.isNative(modifier)) {
65             e.setAttribute("native","yes");
66         }
67         
68         if (java.lang.reflect.Modifier.isPublic(modifier)) {
69             e.setAttribute("public","yes");
70         }
71         else if (java.lang.reflect.Modifier.isProtected(modifier)) {
72             e.setAttribute("protected","yes");
73         }
74         else if (java.lang.reflect.Modifier.isPrivate(modifier)) {
75             e.setAttribute("private","yes");
76         }
77         else {
78             e.setAttribute("packageprivate","yes"); // !(public|protected|private)
79
}
80         
81         return e;
82     }
83
84     /**
85      * Initialize this object from XML.
86      *
87      * @param element The XML tag.
88      * @throws IOException if an i/o error occurs
89      */

90     public void initFromXML(Element element) throws IOException {
91         // to be extended (not overwritten) by subclasses
92
super.initFromXML(element);
93         
94         if (XMLToolbox.isYesAttribute(element,"static")) {
95             this.modifier|=java.lang.reflect.Modifier.STATIC;
96         }
97         if (XMLToolbox.isYesAttribute(element,"abstract")) {
98             this.modifier|=java.lang.reflect.Modifier.ABSTRACT;
99         }
100         if (XMLToolbox.isYesAttribute(element,"synchronized")) {
101             this.modifier|=java.lang.reflect.Modifier.SYNCHRONIZED;
102         }
103         if (XMLToolbox.isYesAttribute(element,"transient")) {
104             this.modifier|=java.lang.reflect.Modifier.TRANSIENT;
105         }
106         if (XMLToolbox.isYesAttribute(element,"volatile")) {
107             this.modifier|=java.lang.reflect.Modifier.VOLATILE;
108         }
109         if (XMLToolbox.isYesAttribute(element,"native")) {
110             this.modifier|=java.lang.reflect.Modifier.NATIVE;
111         }
112         
113         if (XMLToolbox.isYesAttribute(element,"public")) {
114             this.modifier|=java.lang.reflect.Modifier.PUBLIC;
115         }
116         if (XMLToolbox.isYesAttribute(element,"protected")) {
117             this.modifier|=java.lang.reflect.Modifier.PROTECTED;
118         }
119         if (XMLToolbox.isYesAttribute(element,"private")) {
120             this.modifier|=java.lang.reflect.Modifier.PRIVATE;
121         }
122     }
123
124     /**
125      * Initialize this object with values from parsed Java code.
126      *
127      * @param rootnode The corresponding node in the abstract syntax tree (AST).
128      */

129     void initFromAST(Node rootnode) {
130         super.initFromAST(rootnode);
131         
132         // modifier
133
Node mod=rootnode.getChild(JJT_MODIFIER);
134         if (mod!=null) {
135             if (mod.hasChild(JJT_STATIC)) {
136                 this.modifier|=java.lang.reflect.Modifier.STATIC;
137             }
138             if (mod.hasChild(JJT_ABSTRACT)) {
139                 this.modifier|=java.lang.reflect.Modifier.ABSTRACT;
140             }
141             if (mod.hasChild(JJT_TRANSIENT)) {
142                 this.modifier|=java.lang.reflect.Modifier.TRANSIENT;
143             }
144             if (mod.hasChild(JJT_VOLATILE)) {
145                 this.modifier|=java.lang.reflect.Modifier.VOLATILE;
146             }
147             if (mod.hasChild(JJT_NATIVE)) {
148                 this.modifier|=java.lang.reflect.Modifier.NATIVE;
149             }
150             if (mod.hasChild(JJT_SYNCHRONIZED)) {
151                 this.modifier|=java.lang.reflect.Modifier.SYNCHRONIZED;
152             }
153             
154             if (mod.hasChild(JJT_PUBLIC)) {
155                 this.modifier|=java.lang.reflect.Modifier.PUBLIC;
156             }
157             else if (mod.hasChild(JJT_PROTECTED)) {
158                 this.modifier|=java.lang.reflect.Modifier.PROTECTED;
159             }
160             else if (mod.hasChild(JJT_PRIVATE)) {
161                 this.modifier|=java.lang.reflect.Modifier.PRIVATE;
162             }
163         }
164     }
165
166 } // end SourceObjectDeclaredVisible
167
Popular Tags