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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 package net.sourceforge.phpdt.core.dom;
14 import java.util.ArrayList;
15 import java.util.List;
17 import net.sourceforge.phpdt.internal.compiler.util.Util;
20 * AST node for a text element within a doc comment.
23 * Sequence of characters not including a close comment delimiter <b>*</b><b>/</b>
28 * @noinstantiate This class is not intended to be instantiated by clients.
30 public final class TextElement extends ASTNode implements IDocElement {
33 * The "text" structural property of this node type.
37 public static final SimplePropertyDescriptor TEXT_PROPERTY =
38 new SimplePropertyDescriptor(TextElement.class, "text", String.class, MANDATORY); //$NON-NLS-1$
41 * A list of property descriptors (element type:
42 * {@link StructuralPropertyDescriptor}),
43 * or null if uninitialized.
46 private static final List PROPERTY_DESCRIPTORS;
49 List propertyList = new ArrayList(2);
50 createPropertyList(TextElement.class, propertyList);
51 addProperty(TEXT_PROPERTY, propertyList);
52 PROPERTY_DESCRIPTORS = reapPropertyList(propertyList);
56 * Returns a list of structural property descriptors for this node type.
57 * Clients must not modify the result.
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})
65 public static List propertyDescriptors(int apiLevel) {
66 return PROPERTY_DESCRIPTORS;
70 * The text element; defaults to the empty string.
72 private String text = Util.EMPTY_STRING;
75 * Creates a new AST node for a text element owned by the given AST.
76 * The new node has an empty text string.
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.
83 * @param ast the AST that is to own this node
85 TextElement(AST ast) {
89 /* (omit javadoc for this method)
90 * Method declared on ASTNode.
92 final List internalStructuralPropertiesForType(int apiLevel) {
93 return propertyDescriptors(apiLevel);
96 /* (omit javadoc for this method)
97 * Method declared on ASTNode.
99 final Object internalGetSetObjectProperty(SimplePropertyDescriptor property, boolean get, Object value) {
100 if (property == TEXT_PROPERTY) {
104 setText((String) value);
108 // allow default implementation to flag the error
109 return super.internalGetSetObjectProperty(property, get, value);
112 /* (omit javadoc for this method)
113 * Method declared on ASTNode.
115 final int getNodeType0() {
119 /* (omit javadoc for this method)
120 * Method declared on ASTNode.
122 ASTNode clone0(AST target) {
123 TextElement result = new TextElement(target);
124 result.setSourceRange(this.getStartPosition(), this.getLength());
125 result.setText(getText());
129 /* (omit javadoc for this method)
130 * Method declared on ASTNode.
132 final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
133 // dispatch to correct overloaded match method
134 return matcher.match(this, other);
137 /* (omit javadoc for this method)
138 * Method declared on ASTNode.
140 void accept0(ASTVisitor visitor) {
142 visitor.endVisit(this);
146 * Returns this node's text.
148 * @return the text of this node
150 public String getText() {
155 * Sets the text of this node to the given value.
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 "*"+"/".
163 * @param text the text of this node
164 * @exception IllegalArgumentException if the text is null
165 * or contains a block comment closing delimiter
167 public void setText(String text) {
169 throw new IllegalArgumentException();
171 if (text.indexOf("*/") > 0) { //$NON-NLS-1$
172 throw new IllegalArgumentException();
174 preValueChange(TEXT_PROPERTY);
176 postValueChange(TEXT_PROPERTY);
179 /* (omit javadoc for this method)
180 * Method declared on ASTNode.
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);
191 /* (omit javadoc for this method)
192 * Method declared on ASTNode.