EclipseJDT Source Viewer

Home|eclipse_jdt/src/org/eclipse/jdt/core/dom/JavaDocRegion.java
1/*******************************************************************************
2 * Copyright (c) 2022 IBM Corporation and others.
3 *
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
8 *
9 * SPDX-License-Identifier: EPL-2.0
10 *
11 * Contributors:
12 *     IBM Corporation - initial API and implementation
13 *******************************************************************************/
14package org.eclipse.jdt.core.dom;
15
16import java.util.ArrayList;
17import java.util.List;
18
19import org.eclipse.jdt.internal.core.dom.util.DOMASTUtil;
20
21/**
22 * JavaDocRegion pattern AST node type.
23 *
24 * <pre>
25 * JavaDocRegion:
26 *     [ TagElement { <b>,</b> TagElement } ]
27 *     [ ASTNode { [TextElement] [JavaDocRegion] } ]
28 *     validSnippet
29 * </pre>
30 *
31 * @since 3.30
32 */
33
34@SuppressWarnings("rawtypes")
35public class JavaDocRegion extends AbstractTagElement{
36
37    JavaDocRegion(AST ast) {
38        super(ast);
39        unsupportedBelow18();
40    }
41
42    /**
43     * The "tagName" structural property of this node type (type: {@link String}).
44     */
45
46    public static final SimplePropertyDescriptor TAG_NAME_PROPERTY =
47            internalTagNamePropertyFactory(JavaDocRegion.class);
48    /**
49     * The "fragments" structural property of this node type (element type: {@link IDocElement}).
50     * These are the containers which will have texts and other JavaDoc regions
51     */
52    public static final ChildListPropertyDescriptor FRAGMENTS_PROPERTY =
53            internalFragmentsPropertyFactory(JavaDocRegion.class);
54
55    /**
56     * The "tags" structural property of this node type (child type: {@link TagElement}). (added in JEP 413).
57     * These are the decorators like link, highlight etc
58     */
59    public static final ChildListPropertyDescriptor TAGS_PROPERTY  =
60            new ChildListPropertyDescriptor(JavaDocRegion.class"tags"TagElement.classCYCLE_RISK); //$NON-NLS-1$);
61
62
63    /**
64     * The "dummy regions" structural property of this node type (added in JEP 413).
65     */
66    public static final SimplePropertyDescriptor DUMMY_REGION_PROPERTY  = new SimplePropertyDescriptor(JavaDocRegion.class"dummyRegion"boolean.classMANDATORY); //$NON-NLS-1$);
67
68    /**
69     * The "validSnippet" structural property of this node type (added in JEP 413).
70     */
71    public static final SimplePropertyDescriptor VALID_SNIPPET_PROPERTY  = new SimplePropertyDescriptor(JavaDocRegion.class"validSnippet"boolean.classMANDATORY); //$NON-NLS-1$);
72
73    static final String REGION_ENDED = "Region Ended"//$NON-NLS-1$
74    static final String REGION_TO_BE_ENDED = "Region To Be Ended"//$NON-NLS-1$
75
76    /**
77     * A list of property descriptors (element type:
78     * {@link StructuralPropertyDescriptor}),
79     * or null if uninitialized.
80     */
81    private static final List PROPERTY_DESCRIPTORS;
82
83    static {
84        List propertyList = new ArrayList(6);
85        createPropertyList(JavaDocRegion.classpropertyList);
86        addProperty(TAG_NAME_PROPERTYpropertyList);
87        addProperty(FRAGMENTS_PROPERTYpropertyList);
88        addProperty(TAGS_PROPERTYpropertyList);
89        addProperty(DUMMY_REGION_PROPERTYpropertyList);
90        addProperty(VALID_SNIPPET_PROPERTYpropertyList);
91        PROPERTY_DESCRIPTORS = reapPropertyList(propertyList);
92    }
93
94    /**
95     * The tags list; <code>empty</code> for none;
96     */
97    private ASTNode.NodeList tags = new ASTNode.NodeList(TAGS_PROPERTY);
98
99    /**
100     * The property dummyRegion
101     */
102    private boolean dummyRegion = Boolean.TRUE;
103
104    /**
105     * The property validSnippet
106     */
107    private boolean validSnippet = Boolean.TRUE;
108
109
110
111
112    @Override
113    List internalStructuralPropertiesForType(int apiLevel) {
114        return propertyDescriptors(apiLevel);
115    }
116
117    @Override
118    final boolean internalGetSetBooleanProperty(SimplePropertyDescriptor propertyboolean getboolean newValue) {
119        if (property == DUMMY_REGION_PROPERTY) {
120            if (get) {
121                return isDummyRegion();
122            } else {
123                setDummyRegion(newValue);
124                return false;
125            }
126        } else if (property == VALID_SNIPPET_PROPERTY) {
127            if (get) {
128                return isValidSnippet();
129            } else {
130                setValidSnippet(newValue);
131                return false;
132            }
133        }
134        // allow default implementation to flag the error
135        return super.internalGetSetBooleanProperty(propertygetnewValue);
136    }
137
138    @Override
139    final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
140        if (property == FRAGMENTS_PROPERTY) {
141            return fragments();
142        } else if (property == TAGS_PROPERTY) {
143            return tags();
144        }
145        // allow default implementation to flag the error
146        return super.internalGetChildListProperty(property);
147    }
148
149    @Override
150    int getNodeType0() {
151        return JAVADOC_REGION;
152    }
153
154    @Override
155    boolean subtreeMatch0(ASTMatcher matcherObject other) {
156        return matcher.match(this, other);
157    }
158
159    @SuppressWarnings("unchecked")
160    @Override
161    ASTNode clone0(AST target) {
162        JavaDocRegion result = new JavaDocRegion(target);
163        result.setSourceRange(getStartPosition(), getLength());
164        result.setTagName(getTagName());
165        result.setDummyRegion(isDummyRegion());
166        result.setValidSnippet(isValidSnippet());
167        result.tags().addAll(
168                ASTNode.copySubtrees(targettags()));
169        result.fragments().addAll(
170                ASTNode.copySubtrees(targetfragments()));
171        return result;
172    }
173
174    @Override
175    void accept0(ASTVisitor visitor) {
176        visitor.visit(this);
177        visitor.endVisit(this);
178
179    }
180
181    @Override
182    int memSize() {
183        return super.memSize() + 3*4 ;
184    }
185
186    @Override
187    int treeSize() {
188        return memSize() ;
189    }
190
191
192    /**
193     * Returns a list of structural property descriptors for this node type.
194     * Clients must not modify the result.
195     *
196     * @param apiLevel the API level; one of the
197     * <code>AST.JLS*</code> constants
198
199     * @return a list of property descriptors (element type:
200     * {@link StructuralPropertyDescriptor})
201     */
202    public static List propertyDescriptors(int apiLevel) {
203        if (DOMASTUtil.isJavaDocCodeSnippetSupported(apiLevel)) {
204            return PROPERTY_DESCRIPTORS;
205        }
206        return null;
207    }
208
209    /**
210     * Returns the list of tag elements in this region, or
211     * <code>empty</code> if there is none.
212     *
213     *  @return the list of tag element nodes
214     *    (element type: {@link TagElement})
215     * @exception UnsupportedOperationException if this operation is used below JLS18
216     */
217    public List tags() {
218        unsupportedBelow18();
219        return this.tags;
220    }
221
222    /**
223     * Returns <code>true</code> is region is dummy else <code>false</code>.
224     * @return the dummyRegion
225     * @exception UnsupportedOperationException if this operation is used below JLS18
226     */
227    public boolean isDummyRegion() {
228        unsupportedBelow18();
229        return this.dummyRegion;
230    }
231
232    /**
233     * Sets the value of dummyRegion property.
234     * @param dummyRegion
235     * @exception UnsupportedOperationException if this operation is used below JLS18
236     */
237    public void setDummyRegion(boolean dummyRegion) {
238        unsupportedBelow18();
239        preValueChange(DUMMY_REGION_PROPERTY);
240        this.dummyRegion = dummyRegion;
241        postValueChange(DUMMY_REGION_PROPERTY);
242    }
243
244    /**
245     * Returns <code>true</code> if region has valid snippet else <code>false</code>.
246     * @return the validSnippet
247     * @exception UnsupportedOperationException if this operation is used below JLS18
248     */
249    public boolean isValidSnippet() {
250        unsupportedBelow18();
251        return this.validSnippet;
252    }
253
254    /**
255     * Sets the value of validSnippet property.
256     * @param validSnippet
257     * @exception UnsupportedOperationException if this operation is used below JLS18
258     */
259    public void setValidSnippet(boolean validSnippet) {
260        unsupportedBelow18();
261        preValueChange(VALID_SNIPPET_PROPERTY);
262        this.validSnippet = validSnippet;
263        postValueChange(VALID_SNIPPET_PROPERTY);
264    }
265
266    @Override
267    ChildListPropertyDescriptor internalFragmentsPropertyFactory() {
268        return FRAGMENTS_PROPERTY;
269    }
270
271    @Override
272    SimplePropertyDescriptor internalTagNamePropertyFactory() {
273        return TAG_NAME_PROPERTY;
274    }
275
276}
277
MembersX
JavaDocRegion:memSize
JavaDocRegion:internalGetChildListProperty
JavaDocRegion:getNodeType0
JavaDocRegion:JavaDocRegion
JavaDocRegion:internalGetSetBooleanProperty
JavaDocRegion:setValidSnippet
JavaDocRegion:REGION_TO_BE_ENDED
JavaDocRegion:TAG_NAME_PROPERTY
JavaDocRegion:setDummyRegion
JavaDocRegion:FRAGMENTS_PROPERTY
JavaDocRegion:clone0
JavaDocRegion:accept0
JavaDocRegion:internalTagNamePropertyFactory
JavaDocRegion:clone0:Block:result
JavaDocRegion:TAGS_PROPERTY
JavaDocRegion:DUMMY_REGION_PROPERTY
JavaDocRegion:VALID_SNIPPET_PROPERTY
JavaDocRegion:treeSize
JavaDocRegion:tags
JavaDocRegion:validSnippet
JavaDocRegion:REGION_ENDED
JavaDocRegion:subtreeMatch0
JavaDocRegion:Block:propertyList
JavaDocRegion:dummyRegion
JavaDocRegion:internalStructuralPropertiesForType
JavaDocRegion:internalFragmentsPropertyFactory
JavaDocRegion:PROPERTY_DESCRIPTORS
JavaDocRegion:isDummyRegion
JavaDocRegion:propertyDescriptors
JavaDocRegion:isValidSnippet
Members
X