KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > core > dom > TextElement


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.jdt.core.dom;
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.jdt.internal.compiler.util.Util;
18
19 /**
20  * AST node for a text element within a doc comment.
21  * <pre>
22  * TextElement:
23  * Sequence of characters not including a close comment delimiter <b>*</b><b>/</b>
24  * </pre>
25  *
26  * @see Javadoc
27  * @since 3.0
28  */

29 public final class TextElement extends ASTNode implements IDocElement {
30
31     /**
32      * The "test" structural property of this node type.
33      *
34      * @since 3.0
35      */

36     public static final SimplePropertyDescriptor TEXT_PROPERTY =
37         new SimplePropertyDescriptor(TextElement.class, "text", String JavaDoc.class, MANDATORY); //$NON-NLS-1$
38

39     /**
40      * A list of property descriptors (element type:
41      * {@link StructuralPropertyDescriptor}),
42      * or null if uninitialized.
43      * @since 3.0
44      */

45     private static final List JavaDoc PROPERTY_DESCRIPTORS;
46     
47     static {
48         List JavaDoc propertyList = new ArrayList JavaDoc(2);
49         createPropertyList(TextElement.class, propertyList);
50         addProperty(TEXT_PROPERTY, propertyList);
51         PROPERTY_DESCRIPTORS = reapPropertyList(propertyList);
52     }
53     
54     /**
55      * Returns a list of structural property descriptors for this node type.
56      * Clients must not modify the result.
57      *
58      * @param apiLevel the API level; one of the
59      * <code>AST.JLS*</code> constants
60      * @return a list of property descriptors (element type:
61      * {@link StructuralPropertyDescriptor})
62      * @since 3.0
63      */

64     public static List JavaDoc propertyDescriptors(int apiLevel) {
65         return PROPERTY_DESCRIPTORS;
66     }
67     
68     /**
69      * The text element; defaults to the empty string.
70      */

71     private String JavaDoc text = Util.EMPTY_STRING;
72     
73     /**
74      * Creates a new AST node for a text element owned by the given AST.
75      * The new node has an empty text string.
76      * <p>
77      * N.B. This constructor is package-private; all subclasses must be
78      * declared in the same package; clients are unable to declare
79      * additional subclasses.
80      * </p>
81      *
82      * @param ast the AST that is to own this node
83      */

84     TextElement(AST ast) {
85         super(ast);
86     }
87     
88     /* (omit javadoc for this method)
89      * Method declared on ASTNode.
90      */

91     final List JavaDoc internalStructuralPropertiesForType(int apiLevel) {
92         return propertyDescriptors(apiLevel);
93     }
94     
95     /* (omit javadoc for this method)
96      * Method declared on ASTNode.
97      */

98     final Object JavaDoc internalGetSetObjectProperty(SimplePropertyDescriptor property, boolean get, Object JavaDoc value) {
99         if (property == TEXT_PROPERTY) {
100             if (get) {
101                 return getText();
102             } else {
103                 setText((String JavaDoc) value);
104                 return null;
105             }
106         }
107         // allow default implementation to flag the error
108
return super.internalGetSetObjectProperty(property, get, value);
109     }
110
111     /* (omit javadoc for this method)
112      * Method declared on ASTNode.
113      */

114     final int getNodeType0() {
115         return TEXT_ELEMENT;
116     }
117
118     /* (omit javadoc for this method)
119      * Method declared on ASTNode.
120      */

121     ASTNode clone0(AST target) {
122         TextElement result = new TextElement(target);
123         result.setSourceRange(this.getStartPosition(), this.getLength());
124         result.setText(getText());
125         return result;
126     }
127     
128     /* (omit javadoc for this method)
129      * Method declared on ASTNode.
130      */

131     final boolean subtreeMatch0(ASTMatcher matcher, Object JavaDoc other) {
132         // dispatch to correct overloaded match method
133
return matcher.match(this, other);
134     }
135
136     /* (omit javadoc for this method)
137      * Method declared on ASTNode.
138      */

139     void accept0(ASTVisitor visitor) {
140         visitor.visit(this);
141         visitor.endVisit(this);
142     }
143
144     /**
145      * Returns this node's text.
146      *
147      * @return the text of this node
148      */

149     public String JavaDoc getText() {
150         return this.text;
151     }
152     
153     /**
154      * Sets the text of this node to the given value.
155      * <p>
156      * The text element typically includes leading and trailing
157      * whitespace that separates it from the immediately preceding
158      * or following elements. The text element must not include
159      * a block comment closing delimiter "*"+"/".
160      * </p>
161      *
162      * @param text the text of this node
163      * @exception IllegalArgumentException if the text is null
164      * or contains a block comment closing delimiter
165      */

166     public void setText(String JavaDoc text) {
167         if (text == null) {
168             throw new IllegalArgumentException JavaDoc();
169         }
170         if (text.indexOf("*/") > 0) { //$NON-NLS-1$
171
throw new IllegalArgumentException JavaDoc();
172         }
173         preValueChange(TEXT_PROPERTY);
174         this.text = text;
175         postValueChange(TEXT_PROPERTY);
176     }
177         
178     /* (omit javadoc for this method)
179      * Method declared on ASTNode.
180      */

181     int memSize() {
182         int size = BASE_NODE_SIZE + 1 * 4;
183         if (this.text != Util.EMPTY_STRING) {
184             // everything but our empty string costs
185
size += stringSize(this.text);
186         }
187         return size;
188     }
189     
190     /* (omit javadoc for this method)
191      * Method declared on ASTNode.
192      */

193     int treeSize() {
194         return memSize();
195     }
196 }
197
198
Popular Tags