EclipseJDT Source Viewer

Home|eclipse_jdt/src/org/eclipse/jdt/core/dom/ExpressionMethodReference.java
1/*******************************************************************************
2 * Copyright (c) 2013, 2014 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
19/**
20 * Expression method reference AST node type (added in JLS8 API).
21 * <pre>
22 * ExpressionMethodReference:
23 *     Expression <b>::</b>
24 *         [ <b>&lt;</b> Type { <b>,</b> Type } <b>&gt;</b> ]
25 *         Identifier
26 * </pre>
27 *
28 * @since 3.10
29 * @noinstantiate This class is not intended to be instantiated by clients.
30 */
31@SuppressWarnings({"rawtypes""unchecked"})
32public class ExpressionMethodReference extends MethodReference {
33
34    /**
35     * The "expression" structural property of this node type (child type: {@link Expression}).
36     */
37    public static final ChildPropertyDescriptor EXPRESSION_PROPERTY =
38        new ChildPropertyDescriptor(ExpressionMethodReference.class"expression"Expression.classMANDATORYCYCLE_RISK); //$NON-NLS-1$
39
40    /**
41     * The "typeArguments" structural property of this node type (element type: {@link Type})
42     */
43    public static final ChildListPropertyDescriptor TYPE_ARGUMENTS_PROPERTY =
44        internalTypeArgumentsFactory(ExpressionMethodReference.class);
45
46    /**
47     * The "name" structural property of this node type (child type: {@link SimpleName}).
48     */
49    public static final ChildPropertyDescriptor NAME_PROPERTY =
50        new ChildPropertyDescriptor(ExpressionMethodReference.class"name"SimpleName.classMANDATORYNO_CYCLE_RISK); //$NON-NLS-1$
51
52    /**
53     * A list of property descriptors (element type:
54     * {@link StructuralPropertyDescriptor}),
55     * or null if uninitialized.
56     */
57    private static final List PROPERTY_DESCRIPTORS_8_0;
58
59    static {
60        List propertyList = new ArrayList(4);
61        createPropertyList(ExpressionMethodReference.classpropertyList);
62        addProperty(EXPRESSION_PROPERTYpropertyList);
63        addProperty(TYPE_ARGUMENTS_PROPERTYpropertyList);
64        addProperty(NAME_PROPERTYpropertyList);
65        PROPERTY_DESCRIPTORS_8_0 = reapPropertyList(propertyList);
66    }
67
68    /**
69     * Returns a list of structural property descriptors for this node type.
70     * Clients must not modify the result.
71     *
72     * @param apiLevel the API level; one of the AST.JLS* constants
73     * @return a list of property descriptors (element type:
74     * {@link StructuralPropertyDescriptor})
75     */
76    public static List propertyDescriptors(int apiLevel) {
77        return PROPERTY_DESCRIPTORS_8_0;
78    }
79
80    /**
81     * The expression; lazily initialized; defaults to an unspecified,
82     * legal expression.
83     */
84    private Expression expression = null;
85
86    /**
87     * The method name; lazily initialized; defaults to an unspecified,
88     * legal Java method name.
89     */
90    private SimpleName methodName = null;
91
92    /**
93     * Creates a new AST node for an ExpressionMethodReference declaration owned
94     * by the given AST.
95     * <p>
96     * N.B. This constructor is package-private; all subclasses must be
97     * declared in the same package; clients are unable to declare
98     * additional subclasses.
99     * </p>
100     *
101     * @param ast the AST that is to own this node
102     */
103    ExpressionMethodReference(AST ast) {
104        super(ast);
105        unsupportedIn2_3_4();
106    }
107
108    @Override
109    final ChildListPropertyDescriptor internalTypeArgumentsProperty() {
110        return TYPE_ARGUMENTS_PROPERTY;
111    }
112
113    @Override
114    final List internalStructuralPropertiesForType(int apiLevel) {
115        return propertyDescriptors(apiLevel);
116    }
117
118    @Override
119    final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor propertyboolean getASTNode child) {
120        if (property == NAME_PROPERTY) {
121            if (get) {
122                return getName();
123            } else {
124                setName((SimpleNamechild);
125                return null;
126            }
127        }
128        if (property == EXPRESSION_PROPERTY) {
129            if (get) {
130                return getExpression();
131            } else {
132                setExpression((Expressionchild);
133                return null;
134            }
135        }
136        // allow default implementation to flag the error
137        return super.internalGetSetChildProperty(propertygetchild);
138    }
139
140    @Override
141    final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
142        if (property == TYPE_ARGUMENTS_PROPERTY) {
143            return typeArguments();
144        }
145        // allow default implementation to flag the error
146        return super.internalGetChildListProperty(property);
147    }
148
149    @Override
150    final int getNodeType0() {
151        return EXPRESSION_METHOD_REFERENCE;
152    }
153
154    @Override
155    ASTNode clone0(AST target) {
156        ExpressionMethodReference result = new ExpressionMethodReference(target);
157        result.setSourceRange(getStartPosition(), getLength());
158        result.setExpression(
159            (ExpressionASTNode.copySubtree(targetgetExpression()));
160        result.typeArguments().addAll(ASTNode.copySubtrees(targettypeArguments()));
161        result.setName((SimpleNamegetName().clone(target));
162        return result;
163    }
164
165    @Override
166    final boolean subtreeMatch0(ASTMatcher matcherObject other) {
167        // dispatch to correct overloaded match method
168        return matcher.match(this, other);
169    }
170
171    @Override
172    void accept0(ASTVisitor visitor) {
173        boolean visitChildren = visitor.visit(this);
174        if (visitChildren) {
175            // visit children in normal left to right reading order
176            acceptChild(visitorgetExpression());
177            acceptChildren(visitor, this.typeArguments);
178            acceptChild(visitorgetName());
179        }
180        visitor.endVisit(this);
181    }
182
183    /**
184     * Returns the expression of this expression method reference expression
185     *
186     * @return the expression node
187     */
188    public Expression getExpression() {
189        if (this.expression == null) {
190            // lazy init must be thread-safe for readers
191            synchronized (this) {
192                if (this.expression == null) {
193                    preLazyInit();
194                    this.expression = new SimpleName(this.ast);
195                    postLazyInit(this.expressionEXPRESSION_PROPERTY);
196                }
197            }
198        }
199        return this.expression;
200    }
201
202    /**
203     * Sets the expression of this expression method reference.
204     *
205     * @param expression the expression node
206     * @exception IllegalArgumentException if:
207     * <ul>
208     * <li>the node belongs to a different AST</li>
209     * <li>the node already has a parent</li>
210     * <li>a cycle in would be created</li>
211     * </ul>
212     */
213    public void setExpression(Expression expression) {
214        if (expression == null) {
215            throw new IllegalArgumentException();
216        }
217        ASTNode oldChild = this.expression;
218        preReplaceChild(oldChildexpressionEXPRESSION_PROPERTY);
219        this.expression = expression;
220        postReplaceChild(oldChildexpressionEXPRESSION_PROPERTY);
221    }
222
223    /**
224     * Returns the live ordered list of type arguments of this expression method reference
225     *
226     * @return the live list of type arguments
227     *    (element type: {@link Type})
228     */
229    @Override
230    public List typeArguments() {
231        return this.typeArguments;
232    }
233
234    /**
235     * Returns the name of the method referenced in this expression.
236     *
237     * @return the method name node
238     */
239    public SimpleName getName() {
240        if (this.methodName == null) {
241            // lazy init must be thread-safe for readers
242            synchronized (this) {
243                if (this.methodName == null) {
244                    preLazyInit();
245                    this.methodName = new SimpleName(this.ast);
246                    postLazyInit(this.methodNameNAME_PROPERTY);
247                }
248            }
249        }
250        return this.methodName;
251    }
252
253    /**
254     * Sets the name of the method referenced in this expression to the
255     * given name.
256     *
257     * @param name the new method name
258     * @exception IllegalArgumentException if:
259     * <ul>
260     * <li>the node belongs to a different AST</li>
261     * <li>the node already has a parent</li>
262     * </ul>
263     */
264    public void setName(SimpleName name) {
265        if (name == null) {
266            throw new IllegalArgumentException();
267        }
268        ASTNode oldChild = this.methodName;
269        preReplaceChild(oldChildnameNAME_PROPERTY);
270        this.methodName = name;
271        postReplaceChild(oldChildnameNAME_PROPERTY);
272    }
273
274    @Override
275    int memSize() {
276        // treat Code as free
277        return BASE_NODE_SIZE + 3 * 4;
278    }
279
280    @Override
281    int treeSize() {
282        return
283            memSize()
284            + (this.expression == null ? 0 : getExpression().treeSize())
285            + (this.typeArguments == null ? 0 : this.typeArguments.listSize())
286            + (this.methodName == null ? 0 : getName().treeSize());
287    }
288}
289
MembersX
ExpressionMethodReference:internalGetChildListProperty
ExpressionMethodReference:internalStructuralPropertiesForType
ExpressionMethodReference:EXPRESSION_PROPERTY
ExpressionMethodReference:setExpression:Block:oldChild
ExpressionMethodReference:memSize
ExpressionMethodReference:clone0:Block:result
ExpressionMethodReference:Block:propertyList
ExpressionMethodReference:accept0
ExpressionMethodReference:accept0:Block:visitChildren
ExpressionMethodReference:subtreeMatch0
ExpressionMethodReference:setExpression
ExpressionMethodReference:NAME_PROPERTY
ExpressionMethodReference:methodName
ExpressionMethodReference:typeArguments
ExpressionMethodReference:PROPERTY_DESCRIPTORS_8_0
ExpressionMethodReference:setName:Block:oldChild
ExpressionMethodReference:treeSize
ExpressionMethodReference:internalTypeArgumentsProperty
ExpressionMethodReference:clone0
ExpressionMethodReference:propertyDescriptors
ExpressionMethodReference:ExpressionMethodReference
ExpressionMethodReference:getName
ExpressionMethodReference:getNodeType0
ExpressionMethodReference:expression
ExpressionMethodReference:internalGetSetChildProperty
ExpressionMethodReference:getExpression
ExpressionMethodReference:TYPE_ARGUMENTS_PROPERTY
ExpressionMethodReference:setName
Members
X