KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Project: BeautyJ - Customizable Java Source Code Transformer
3  * Class: de.gulden.util.javasource.Parameter
4  * Version: 1.1
5  *
6  * Date: 2004-09-29
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 javax.xml.parsers.*;
22 import org.w3c.dom.*;
23 import java.io.*;
24 import java.util.*;
25
26 /**
27  * Represents a parameter declaration.
28  *
29  * @author Jens Gulden
30  * @version 1.1
31  */

32 public class Parameter extends SourceObjectDeclared implements Typed, ParserTreeConstants {
33
34     // ------------------------------------------------------------------------
35
// --- fields ---
36
// ------------------------------------------------------------------------
37

38     /**
39      * The executable member to which this parameter belongs.
40      */

41     public MemberExecutable myMemberExecutable;
42
43     /**
44      * The name.
45      */

46     protected String JavaDoc name;
47
48     /**
49      * The type.
50      */

51     protected Type type;
52
53
54     // ------------------------------------------------------------------------
55
// --- constructor ---
56
// ------------------------------------------------------------------------
57

58     /**
59      * Creates a new instance of Parameter.
60      */

61     public Parameter(MemberExecutable parent) {
62         myMemberExecutable=parent;
63     }
64
65
66     // ------------------------------------------------------------------------
67
// --- methods ---
68
// ------------------------------------------------------------------------
69

70     /**
71      * Returns the name.
72      */

73     public String JavaDoc getName() {
74         return name;
75     }
76
77     /**
78      * Sets the name.
79      */

80     public void setName(String JavaDoc n) {
81         name=n;
82     }
83
84     /**
85      * Returns the type.
86      */

87     public Type getType() {
88         return type;
89     }
90
91     /**
92      * Sets the type.
93      */

94     public void setType(Type t) {
95         type=t;
96     }
97
98     /**
99      * Output this object as XML.
100      *
101      * @return The XML tag.
102      * @see #initFromXML
103      */

104     public Element buildXML(Document d) {
105         Element e=super.buildXML(d);
106         e.appendChild(getType().buildXML(d));
107         return e;
108     }
109
110     /**
111      * Initialize this object from XML.
112      *
113      * @param element The XML tag.
114      * @throws IOException if an i/o error occurs
115      */

116     public void initFromXML(Element element) throws IOException {
117         // to be extended (not overwritten) by subclasses
118
super.initFromXML(element);
119         name=element.getAttribute("name"); // adjust name
120
addDocumentationToMember((DocumentationDeclared)getDocumentation(),myMemberExecutable);
121     }
122
123     /**
124      * Returns the documentation.
125      */

126     public Documentation getDocumentation() {
127         // overwrites SourceObjectDeclared.getDocumentation().
128
DocumentationDeclared dd=(DocumentationDeclared)myMemberExecutable.getDocumentation();
129         if (dd!=null) {
130             return dd.findTag("@param",this.getName());
131         }
132         else {
133             return null;
134         }
135     }
136
137     /**
138      * Returns the executable member to which this parameter belongs.
139      */

140     public MemberExecutable getMemberExecutable() {
141         return myMemberExecutable;
142     }
143
144     /**
145      * Initialize this object from parsed Java code.
146      *
147      * @param rootnode The corresponding node in the abstract syntax tree (AST).
148      */

149     void initFromAST(Node rootnode) {
150         // get modifier 'final'
151
this.modifier=0;
152         if (rootnode.hasChild(JJT_FINAL)) {
153             this.modifier|=java.lang.reflect.Modifier.FINAL;
154         }
155
156         name=rootnode.getName();
157         type=new Type(myMemberExecutable);
158         type.initFromAST(rootnode); // special way of invoking (using rootnode)
159
}
160
161
162     // ------------------------------------------------------------------------
163
// --- static method ---
164
// ------------------------------------------------------------------------
165

166     /**
167      * Adds a documentation to member.
168      */

169     static void addDocumentationToMember(DocumentationDeclared d, MemberExecutable mex) {
170         if (d!=null) {
171             DocumentationDeclared dd;
172             if (mex.getDocumentation()==null) {
173                 dd=new DocumentationDeclared();
174                 dd.setText("");
175                 mex.setDocumentation(dd);
176             }
177             else {
178                 dd=(DocumentationDeclared)mex.getDocumentation();
179             }
180             for (Enumeration e=d.getTags();e.hasMoreElements();) {
181                 DocumentationTagged dt=(DocumentationTagged)e.nextElement();
182                 dd.addTag(dt);
183             }
184         }
185     }
186
187 } // end Parameter
188
Popular Tags