KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > bridge > JavaDocImpl


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 package org.netbeans.modules.java.bridge;
21
22 import java.util.StringTokenizer JavaDoc;
23
24 import org.openide.src.*;
25
26 /** Implementation of JavaDoc comment blocks in Java loader.
27 *
28 * @author Petr Hamernik, Petr Hrebejk
29 */

30 class JavaDocImpl extends Object JavaDoc implements JavaDoc, java.io.Serializable JavaDoc {
31
32     /** Holds the memory implementation of JavaDoc */
33     JavaDoc javaDoc;
34
35     /** The element which this javadoc belongs to.
36     * It is called when javadoc changed and should be regenerated
37     */

38     ElementImpl impl;
39
40     private static final long serialVersionUID = -4007873715598624939L;
41     
42     /** Flag for the empty javadoc (element has NO javadoc
43     * in the source code)
44     */

45     //boolean empty;
46

47
48     JavaDocImpl( ElementImpl impl ) {
49         this.impl = impl;
50     }
51
52     /** Creates new JavaDoc
53     * @param rawText the pre-parsed text of the javadoc comment
54     * provided by the JavaParser
55     * @param impl The implementation
56     */

57     JavaDocImpl(String JavaDoc rawText, ElementImpl impl) {
58         javaDoc = JavaDocSupport.createJavaDoc( rawText );
59         this.impl = impl;
60     }
61
62     public void clearJavaDoc() throws SourceException {
63         javaDoc.clearJavaDoc();
64         impl.setJavaDocText (null, true);
65     }
66
67     public boolean isEmpty() {
68         return javaDoc.isEmpty();
69     }
70
71     /** Get the entire text of the comment.
72     * @return the whole text
73     */

74     public String JavaDoc getRawText () {
75         return javaDoc.getRawText();
76     }
77
78
79     /** Set the raw text of the comment.
80     * @param s the whole text to set
81     * @exception SourceException if the modification cannot be performed
82     */

83     public void setRawText (String JavaDoc s) throws SourceException {
84         impl.setJavaDocText(s, true);
85     }
86
87     /** Updates internal structures holding the tags... */
88     private void updateTags() {
89         //PENDING
90
}
91
92     /** Get the actual text, cleared of all (non-inline) tags.
93     * @return the plain text
94     */

95     public String JavaDoc getText () {
96         return javaDoc.getText();
97     }
98
99
100     /** Set the actual text.
101     * @param s the actual text, without any (non-inline) tags
102     * @exception SourceException if the modification cannot be performed
103     */

104     public void setText (String JavaDoc s) throws SourceException {
105         impl.setJavaDocText(s, false);
106         /*
107         String oldText = getText();
108         try {
109             javaDoc.setText( s );
110         } catch (SourceException ex) {
111             // something went wrong.
112             javaDoc.setText(oldText);
113             throw ex;
114         }
115          */

116     }
117
118     protected void changeJavaDocText(String JavaDoc s, boolean raw) throws SourceException {
119         if (raw) {
120             javaDoc.setRawText(s);
121         } else {
122             javaDoc.setText(s);
123         }
124     }
125     
126     /** Gets all tags from comment.
127      */

128     public JavaDocTag[] getTags() {
129         return javaDoc.getTags();
130     }
131
132     /** Gets all tags of given name
133      */

134     public JavaDocTag[] getTags(String JavaDoc name) {
135         return javaDoc.getTags( name );
136     }
137
138     /** Adds removes or sets tags used in this comment
139      * @param elems the new initializers
140      * @param action {@link #ADD}, {@link #REMOVE}, or {@link #SET}
141      * @exception SourceException if impossible
142      */

143     public void changeTags(JavaDocTag[] tags, int action) throws SourceException {
144         impl.changeJavaDocTags(tags, action);
145     }
146     
147     protected void changeJavaDocTags(JavaDocTag[] tags, int action)
148         throws SourceException {
149         javaDoc.changeTags(tags, action);
150     }
151
152     /** Gets all @see tags
153      */

154     public JavaDocTag.See[] getSeeTags() {
155         return javaDoc.getSeeTags();
156     }
157
158     /** Regenerates the text in the element.
159     * @exception SourceException if the modification cannot be performed
160     public void regenerateSource() throws SourceException {
161         impl.javaDocChanged();
162     }
163     */

164
165     /** The JavaDoc of a class.
166     * Class javadoc adds no special tags.
167     */

168     static class Class extends JavaDocImpl implements JavaDoc.Class {
169         
170         private static final long serialVersionUID = 5651952150233392489L;
171         
172         public Class(String JavaDoc rawText, ElementImpl impl) {
173             super( impl );
174             javaDoc = JavaDocSupport.createClassJavaDoc( rawText );
175         }
176     }
177
178     /** The JavaDoc of a field.
179     * <p>Currently adds special @SerialField tag
180     */

181     static class Field extends JavaDocImpl implements JavaDoc.Field {
182
183         private static final long serialVersionUID = -7737074261842273983L;
184         
185         public Field(String JavaDoc rawText, ElementImpl impl) {
186             super( impl );
187             javaDoc = JavaDocSupport.createFieldJavaDoc( rawText );
188         }
189
190         /** Gets SerialField tags.
191         */

192         public JavaDocTag.SerialField[] getSerialFieldTags() {
193             return ((JavaDoc.Field)javaDoc).getSerialFieldTags();
194         }
195
196     }
197
198     /** The JavaDoc of a method. Adds two special tags: @param tag and @throws tag.
199     */

200     static class Method extends JavaDocImpl implements JavaDoc.Method {
201
202         private static final long serialVersionUID = 6902210486353445027L;
203         
204         public Method(String JavaDoc rawText, CallableImpl impl) {
205             super( impl );
206             javaDoc = JavaDocSupport.createMethodJavaDoc( rawText );
207         }
208
209         /** Gets param tags.
210         */

211         public JavaDocTag.Param[] getParamTags() {
212             return ((JavaDoc.Method)javaDoc).getParamTags();
213         }
214
215         /** Gets throws tags.
216         */

217         public JavaDocTag.Throws[] getThrowsTags() {
218             return ((JavaDoc.Method)javaDoc).getThrowsTags();
219         }
220     }
221 }
222
Popular Tags