EclipseJDT Source Viewer

Home|eclipse_jdt/src/org/eclipse/jdt/core/dom/YieldStatement.java
1/*******************************************************************************
2 * Copyright (c) 2019, 2020 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 *******************************************************************************/
14
15package org.eclipse.jdt.core.dom;
16
17import java.util.ArrayList;
18import java.util.List;
19
20/**
21 * Yield statement AST node type.
22 *
23 * <pre>
24 * YieldStatement:
25 *        <b>Yield</b> <b>{ Identifier/Expression }</b>
26 * </pre>
27 *
28 * @since 3.22
29 */
30@SuppressWarnings("rawtypes")
31public class YieldStatement extends Statement {
32
33    /**
34     * The "expression" structural property of this node type (child type: {@link Expression}). (added in JEP 354).
35     */
36    public static final ChildPropertyDescriptor EXPRESSION_PROPERTY =
37            new ChildPropertyDescriptor(YieldStatement.class"expression"Expression.classMANDATORYNO_CYCLE_RISK); //$NON-NLS-1$);
38
39    /**
40     * A list of property descriptors (element type:
41     * {@link StructuralPropertyDescriptor}),
42     * or null if uninitialized.
43     */
44    private static final List PROPERTY_DESCRIPTORS;
45
46    /**
47     * <code>true</code> indicates implicit and <code>false</code> indicates not implicit.
48     */
49    private boolean isImplicit = false;
50
51    static {
52        List properyList = new ArrayList(2);
53        createPropertyList(YieldStatement.classproperyList);
54        addProperty(EXPRESSION_PROPERTYproperyList);
55        PROPERTY_DESCRIPTORS = reapPropertyList(properyList);
56    }
57
58    /**
59     * Returns a list of structural property descriptors for this node type.
60     * Clients must not modify the result.
61     *
62     * @param apiLevel the API level; one of the
63     * <code>AST.JLS*</code> constants
64
65     * @return a list of property descriptors (element type:
66     * {@link StructuralPropertyDescriptor})
67     * @since 3.22
68     */
69    public static List propertyDescriptors(int apiLevel) {
70        return PROPERTY_DESCRIPTORS;
71    }
72
73    /**
74     * The expression
75     */
76    private Expression expression = null;
77
78    /**
79     * Creates a new unparented Yield statement node owned by the given
80     * AST. By default, the Yield statement has identifier/expression.
81     * <p>
82     * N.B. This constructor is package-private.
83     * </p>
84     *
85     * @param ast the AST that is to own this node
86     * @exception UnsupportedOperationException if this operation is used below JLS14
87     */
88    YieldStatement(AST ast) {
89        super(ast);
90        unsupportedBelow14();
91    }
92
93    @Override
94    final List internalStructuralPropertiesForType(int apiLevel) {
95        return propertyDescriptors(apiLevel);
96    }
97
98    @Override
99    final List internalStructuralPropertiesForType(int apiLevelboolean previewEnabled) {
100        return propertyDescriptors(apiLevel);
101    }
102
103    @Override
104    final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor propertyboolean getASTNode child) {
105        if (property == EXPRESSION_PROPERTY) {
106            if (get) {
107                return getExpression();
108            } else {
109                setExpression((Expressionchild);
110                return null;
111            }
112        }
113        // allow default implementation to flag the error
114        return super.internalGetSetChildProperty(propertygetchild);
115    }
116
117    @Override
118    final int getNodeType0() {
119        return YIELD_STATEMENT;
120    }
121
122    @Override
123    ASTNode clone0(AST target) {
124        YieldStatement result = new YieldStatement(target);
125        result.setSourceRange(getStartPosition(), getLength());
126        result.copyLeadingComment(this);
127        if (this.ast.apiLevel >= AST.JLS12_INTERNAL) {
128            result.setExpression((ExpressionASTNode.copySubtree(targetgetExpression()));
129        }
130        return result;
131    }
132
133    @Override
134    final boolean subtreeMatch0(ASTMatcher matcherObject other) {
135        // dispatch to correct overloaded match method
136        return matcher.match(this, other);
137    }
138
139    @Override
140    void accept0(ASTVisitor visitor) {
141        boolean visitChildren = visitor.visit(this);
142        if (visitChildren) {
143            if (this.ast.apiLevel >= AST.JLS13_INTERNAL) {
144                acceptChild(visitorgetExpression());
145            }
146        }
147        visitor.endVisit(this);
148    }
149
150    /**
151     * Returns the expression of this Yield statement, or <code>null</code> if
152     * there is none.
153     *
154     * @return the expression, or <code>null</code> if there is none
155     * @exception UnsupportedOperationException if this operation is used below JLS14
156     * @since 3.22
157     */
158    public Expression getExpression() {
159        unsupportedBelow14();
160        return this.expression;
161    }
162
163    /**
164     * Sets or clears the expression of this Yield statement.
165     *
166     * @param expression the expression
167     * @exception IllegalArgumentException if:
168     * <ul>
169     * <li>the node belongs to a different AST</li>
170     * <li>the node already has a parent</li>
171     * </ul>
172     * @exception UnsupportedOperationException if this operation is used below JLS14
173     * @since 3.22
174     */
175    public void setExpression(Expression expression) {
176        unsupportedBelow14();
177        ASTNode oldChild = this.expression;
178        preReplaceChild(oldChildexpressionEXPRESSION_PROPERTY);
179        this.expression = expression;
180        postReplaceChild(oldChildexpressionEXPRESSION_PROPERTY);
181    }
182
183    /**
184     * Gets the isImplicit of this break statement as <code>true</code> or <code>false</code>.
185     *<code>true</code> indicates implicit and <code>false</code> indicates not implicit.
186     *
187     * @return isImplicit <code>true</code> or <code>false</code>
188     * @exception UnsupportedOperationException if this operation is used below JLS14
189     * @since 3.22
190     */
191    public boolean isImplicit() {
192        unsupportedBelow14();
193        return this.isImplicit;
194    }
195
196    /**
197     * Sets the isImplicit of this break statement as <code>true</code> or <code>false</code>.
198     * <code>true</code> indicates implicit and <code>false</code> indicates not implicit. This flag is
199     * generated by compiler and is not expected to be set by client.
200
201     * @param isImplicit <code>true</code> or <code>false</code>
202     * @exception UnsupportedOperationException if this operation is used below JLS14
203     */
204    void setImplicit(boolean isImplicit) {
205        unsupportedBelow14();
206        this.isImplicit = isImplicit;
207    }
208
209
210    @Override
211    int memSize() {
212        return super.memSize() + 2 * 4;
213    }
214
215    @Override
216    int treeSize() {
217        return
218            memSize()
219            + (this.expression == null ? 0 : getExpression().treeSize());
220    }
221}
222
223
MembersX
YieldStatement:accept0:Block:visitChildren
YieldStatement:EXPRESSION_PROPERTY
YieldStatement:isImplicit
YieldStatement:internalGetSetChildProperty
YieldStatement:treeSize
YieldStatement:internalStructuralPropertiesForType
YieldStatement:subtreeMatch0
YieldStatement:expression
YieldStatement:setExpression:Block:oldChild
YieldStatement:getNodeType0
YieldStatement:clone0
YieldStatement:propertyDescriptors
YieldStatement:clone0:Block:result
YieldStatement:setExpression
YieldStatement:Block:properyList
YieldStatement:YieldStatement
YieldStatement:accept0
YieldStatement:memSize
YieldStatement:PROPERTY_DESCRIPTORS
YieldStatement:getExpression
YieldStatement:setImplicit
Members
X