removed unused private methods.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / dom / TextElement.java
1 /*******************************************************************************
2  * Copyright (c) 2004, 2008 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 net.sourceforge.phpdt.core.dom;
13
14 import java.util.ArrayList;
15 import java.util.List;
16
17 import net.sourceforge.phpdt.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  * @noinstantiate This class is not intended to be instantiated by clients.
29  */
30 public final class TextElement extends ASTNode implements IDocElement {
31
32         /**
33          * The "text" structural property of this node type.
34          * 
35          * @since 3.0
36          */
37         public static final SimplePropertyDescriptor TEXT_PROPERTY = 
38                 new SimplePropertyDescriptor(TextElement.class, "text", String.class, MANDATORY); //$NON-NLS-1$
39         
40         /**
41          * A list of property descriptors (element type: 
42          * {@link StructuralPropertyDescriptor}),
43          * or null if uninitialized.
44          * @since 3.0
45          */
46         private static final List PROPERTY_DESCRIPTORS;
47         
48         static {
49                 List propertyList = new ArrayList(2);
50                 createPropertyList(TextElement.class, propertyList);
51                 addProperty(TEXT_PROPERTY, propertyList);
52                 PROPERTY_DESCRIPTORS = reapPropertyList(propertyList);
53         }
54         
55         /**
56          * Returns a list of structural property descriptors for this node type.
57          * Clients must not modify the result.
58          * 
59          * @param apiLevel the API level; one of the
60          * <code>AST.JLS*</code> constants
61          * @return a list of property descriptors (element type: 
62          * {@link StructuralPropertyDescriptor})
63          * @since 3.0
64          */
65         public static List propertyDescriptors(int apiLevel) {
66                 return PROPERTY_DESCRIPTORS;
67         }
68         
69         /**
70          * The text element; defaults to the empty string.
71          */
72         private String text = Util.EMPTY_STRING;
73         
74         /**
75          * Creates a new AST node for a text element owned by the given AST.
76          * The new node has an empty text string.
77          * <p>
78          * N.B. This constructor is package-private; all subclasses must be 
79          * declared in the same package; clients are unable to declare 
80          * additional subclasses.
81          * </p>
82          * 
83          * @param ast the AST that is to own this node
84          */
85         TextElement(AST ast) {
86                 super(ast);
87         }
88         
89         /* (omit javadoc for this method)
90          * Method declared on ASTNode.
91          */
92         final List internalStructuralPropertiesForType(int apiLevel) {
93                 return propertyDescriptors(apiLevel);
94         }
95         
96         /* (omit javadoc for this method)
97          * Method declared on ASTNode.
98          */
99         final Object internalGetSetObjectProperty(SimplePropertyDescriptor property, boolean get, Object value) {
100                 if (property == TEXT_PROPERTY) {
101                         if (get) {
102                                 return getText();
103                         } else {
104                                 setText((String) value);
105                                 return null;
106                         }
107                 }
108                 // allow default implementation to flag the error
109                 return super.internalGetSetObjectProperty(property, get, value);
110         }
111
112         /* (omit javadoc for this method)
113          * Method declared on ASTNode.
114          */
115         final int getNodeType0() {
116                 return TEXT_ELEMENT;
117         }
118
119         /* (omit javadoc for this method)
120          * Method declared on ASTNode.
121          */
122         ASTNode clone0(AST target) {
123                 TextElement result = new TextElement(target);
124                 result.setSourceRange(this.getStartPosition(), this.getLength());
125                 result.setText(getText());
126                 return result;
127         }
128         
129         /* (omit javadoc for this method)
130          * Method declared on ASTNode.
131          */
132         final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
133                 // dispatch to correct overloaded match method
134                 return matcher.match(this, other);
135         }
136
137         /* (omit javadoc for this method)
138          * Method declared on ASTNode.
139          */
140         void accept0(ASTVisitor visitor) {
141                 visitor.visit(this);
142                 visitor.endVisit(this);
143         }
144
145         /**
146          * Returns this node's text.
147          * 
148          * @return the text of this node
149          */ 
150         public String getText() {
151                 return this.text;
152         }
153         
154         /**
155          * Sets the text of this node to the given value.
156          * <p>
157          * The text element typically includes leading and trailing
158          * whitespace that separates it from the immediately preceding
159          * or following elements. The text element must not include
160          * a block comment closing delimiter "*"+"/".
161          * </p>
162          * 
163          * @param text the text of this node
164          * @exception IllegalArgumentException if the text is null
165          * or contains a block comment closing delimiter
166          */ 
167         public void setText(String text) {
168                 if (text == null) {
169                         throw new IllegalArgumentException();
170                 }
171                 if (text.indexOf("*/") > 0) { //$NON-NLS-1$
172                         throw new IllegalArgumentException();
173                 }
174                 preValueChange(TEXT_PROPERTY);
175                 this.text = text;
176                 postValueChange(TEXT_PROPERTY);
177         }
178                 
179         /* (omit javadoc for this method)
180          * Method declared on ASTNode.
181          */
182         int memSize() {
183                 int size = BASE_NODE_SIZE + 1 * 4;
184                 if (this.text != Util.EMPTY_STRING) {
185                         // everything but our empty string costs
186                         size += stringSize(this.text);
187                 }
188                 return size;
189         }
190         
191         /* (omit javadoc for this method)
192          * Method declared on ASTNode.
193          */
194         int treeSize() {
195                 return memSize();
196         }
197 }
198