001: /*
002: * Project: BeautyJ - Customizable Java Source Code Transformer
003: * Class: de.gulden.util.javasource.Parameter
004: * Version: 1.1
005: *
006: * Date: 2004-09-29
007: *
008: * Note: Contains auto-generated Javadoc comments created by BeautyJ.
009: *
010: * This is licensed under the GNU General Public License (GPL)
011: * and comes with NO WARRANTY. See file license.txt for details.
012: *
013: * Author: Jens Gulden
014: * Email: beautyj@jensgulden.de
015: */
016:
017: package de.gulden.util.javasource;
018:
019: import de.gulden.util.javasource.jjt.Node;
020: import de.gulden.util.javasource.jjt.*;
021: import javax.xml.parsers.*;
022: import org.w3c.dom.*;
023: import java.io.*;
024: import java.util.*;
025:
026: /**
027: * Represents a parameter declaration.
028: *
029: * @author Jens Gulden
030: * @version 1.1
031: */
032: public class Parameter extends SourceObjectDeclared implements Typed,
033: ParserTreeConstants {
034:
035: // ------------------------------------------------------------------------
036: // --- fields ---
037: // ------------------------------------------------------------------------
038:
039: /**
040: * The executable member to which this parameter belongs.
041: */
042: public MemberExecutable myMemberExecutable;
043:
044: /**
045: * The name.
046: */
047: protected String name;
048:
049: /**
050: * The type.
051: */
052: protected Type type;
053:
054: // ------------------------------------------------------------------------
055: // --- constructor ---
056: // ------------------------------------------------------------------------
057:
058: /**
059: * Creates a new instance of Parameter.
060: */
061: public Parameter(MemberExecutable parent) {
062: myMemberExecutable = parent;
063: }
064:
065: // ------------------------------------------------------------------------
066: // --- methods ---
067: // ------------------------------------------------------------------------
068:
069: /**
070: * Returns the name.
071: */
072: public String getName() {
073: return name;
074: }
075:
076: /**
077: * Sets the name.
078: */
079: public void setName(String n) {
080: name = n;
081: }
082:
083: /**
084: * Returns the type.
085: */
086: public Type getType() {
087: return type;
088: }
089:
090: /**
091: * Sets the type.
092: */
093: public void setType(Type t) {
094: type = t;
095: }
096:
097: /**
098: * Output this object as XML.
099: *
100: * @return The XML tag.
101: * @see #initFromXML
102: */
103: public Element buildXML(Document d) {
104: Element e = super .buildXML(d);
105: e.appendChild(getType().buildXML(d));
106: return e;
107: }
108:
109: /**
110: * Initialize this object from XML.
111: *
112: * @param element The XML tag.
113: * @throws IOException if an i/o error occurs
114: */
115: public void initFromXML(Element element) throws IOException {
116: // to be extended (not overwritten) by subclasses
117: super .initFromXML(element);
118: name = element.getAttribute("name"); // adjust name
119: addDocumentationToMember(
120: (DocumentationDeclared) getDocumentation(),
121: myMemberExecutable);
122: }
123:
124: /**
125: * Returns the documentation.
126: */
127: public Documentation getDocumentation() {
128: // overwrites SourceObjectDeclared.getDocumentation().
129: DocumentationDeclared dd = (DocumentationDeclared) myMemberExecutable
130: .getDocumentation();
131: if (dd != null) {
132: return dd.findTag("@param", this .getName());
133: } else {
134: return null;
135: }
136: }
137:
138: /**
139: * Returns the executable member to which this parameter belongs.
140: */
141: public MemberExecutable getMemberExecutable() {
142: return myMemberExecutable;
143: }
144:
145: /**
146: * Initialize this object from parsed Java code.
147: *
148: * @param rootnode The corresponding node in the abstract syntax tree (AST).
149: */
150: void initFromAST(Node rootnode) {
151: // get modifier 'final'
152: this .modifier = 0;
153: if (rootnode.hasChild(JJT_FINAL)) {
154: this .modifier |= java.lang.reflect.Modifier.FINAL;
155: }
156:
157: name = rootnode.getName();
158: type = new Type(myMemberExecutable);
159: type.initFromAST(rootnode); // special way of invoking (using rootnode)
160: }
161:
162: // ------------------------------------------------------------------------
163: // --- static method ---
164: // ------------------------------------------------------------------------
165:
166: /**
167: * Adds a documentation to member.
168: */
169: static void addDocumentationToMember(DocumentationDeclared d,
170: MemberExecutable mex) {
171: if (d != null) {
172: DocumentationDeclared dd;
173: if (mex.getDocumentation() == null) {
174: dd = new DocumentationDeclared();
175: dd.setText("");
176: mex.setDocumentation(dd);
177: } else {
178: dd = (DocumentationDeclared) mex.getDocumentation();
179: }
180: for (Enumeration e = d.getTags(); e.hasMoreElements();) {
181: DocumentationTagged dt = (DocumentationTagged) e
182: .nextElement();
183: dd.addTag(dt);
184: }
185: }
186: }
187:
188: } // end Parameter
|