EclipseJDT Source Viewer

Home|eclipse_jdt/src/org/eclipse/jdt/core/dom/Expression.java
1/*******************************************************************************
2 * Copyright (c) 2000, 2019 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 * Contributors:
11 *     IBM Corporation - initial API and implementation
12 *******************************************************************************/
13
14package org.eclipse.jdt.core.dom;
15
16/**
17 * Abstract base class of AST nodes that represent expressions.
18 * There are several kinds of expressions.
19 * <pre>
20 * Expression:
21 *    {@link Annotation},
22 *    {@link ArrayAccess},
23 *    {@link ArrayCreation},
24 *    {@link ArrayInitializer},
25 *    {@link Assignment},
26 *    {@link BooleanLiteral},
27 *    {@link CaseDefaultExpression},
28 *    {@link CastExpression},
29 *    {@link CharacterLiteral},
30 *    {@link ClassInstanceCreation},
31 *    {@link ConditionalExpression},
32 *    {@link CreationReference},
33 *    {@link ExpressionMethodReference},
34 *    {@link FieldAccess},
35 *    {@link InfixExpression},
36 *    {@link InstanceofExpression},
37 *    {@link LambdaExpression},
38 *    {@link MethodInvocation},
39 *    {@link MethodReference},
40 *    {@link Name},
41 *    {@link NullLiteral},
42 *    {@link NumberLiteral},
43 *    {@link Pattern},
44 *    {@link ParenthesizedExpression},
45 *    {@link PostfixExpression},
46 *    {@link PrefixExpression},
47 *    {@link StringLiteral},
48 *    {@link SuperFieldAccess},
49 *    {@link SuperMethodInvocation},
50 *    {@link SuperMethodReference},
51 *    {@link SwitchExpression},
52 *    {@link ThisExpression},
53 *    {@link TypeLiteral},
54 *    {@link TypeMethodReference},
55 *    {@link VariableDeclarationExpression}
56 * </pre>
57 *
58 * @since 2.0
59 */
60public abstract class Expression extends ASTNode {
61
62    /**
63     * Creates a new AST node for an expression owned by the given AST.
64     * <p>
65     * N.B. This constructor is package-private.
66     * </p>
67     *
68     * @param ast the AST that is to own this node
69     */
70    Expression(AST ast) {
71        super(ast);
72    }
73
74    /**
75     * Resolves and returns the compile-time constant expression value as
76     * specified in JLS2 15.28, if this expression has one. Constant expression
77     * values are unavailable unless bindings are requested when the AST is
78     * being built. If the type of the value is a primitive type, the result
79     * is the boxed equivalent (i.e., int returned as an <code>Integer</code>);
80     * if the type of the value is <code>String</code>, the result is the string
81     * itself. If the expression does not have a compile-time constant expression
82     * value, the result is <code>null</code>.
83     * <p>
84     * Resolving constant expressions takes into account the value of simple
85     * and qualified names that refer to constant variables (JLS2 4.12.4).
86     * </p>
87     * <p>
88     * Note 1: enum constants are not considered constant expressions.
89     * The result is always <code>null</code> for these.
90     * </p>
91     * <p>
92     * Note 2: Compile-time constant expressions cannot denote <code>null</code>.
93     * So technically {@link NullLiteral} nodes are not constant expressions.
94     * The result is <code>null</code> for these nonetheless.
95     * </p>
96     *
97     * @return the constant expression value, or <code>null</code> if this
98     * expression has no constant expression value or if bindings were not
99     * requested when the AST was created
100     * @since 3.1
101     */
102    public final Object resolveConstantExpressionValue() {
103        return this.ast.getBindingResolver().resolveConstantExpressionValue(this);
104    }
105
106    /**
107     * Resolves and returns the binding for the type of this expression.
108     * <p>
109     * Note that bindings are generally unavailable unless requested when the
110     * AST is being built.
111     * </p>
112     *
113     * @return the binding for the type of this expression, or
114     *    <code>null</code> if the type cannot be resolved
115     */
116    public final ITypeBinding resolveTypeBinding() {
117        return this.ast.getBindingResolver().resolveExpressionType(this);
118    }
119
120    /**
121     * Returns whether this expression node is the site of a boxing
122     * conversion (JLS3 5.1.7). This information is available only
123     * when bindings are requested when the AST is being built.
124     *
125     * @return <code>true</code> if this expression is the site of a
126     * boxing conversion, or <code>false</code> if either no boxing conversion
127     * is involved or if bindings were not requested when the AST was created
128     * @since 3.1
129     */
130    public final boolean resolveBoxing() {
131        return this.ast.getBindingResolver().resolveBoxing(this);
132    }
133
134    /**
135     * Returns whether this expression node is the site of an unboxing
136     * conversion (JLS3 5.1.8). This information is available only
137     * when bindings are requested when the AST is being built.
138     *
139     * @return <code>true</code> if this expression is the site of an
140     * unboxing conversion, or <code>false</code> if either no unboxing
141     * conversion is involved or if bindings were not requested when the
142     * AST was created
143     * @since 3.1
144     */
145    public final boolean resolveUnboxing() {
146        return this.ast.getBindingResolver().resolveUnboxing(this);
147    }
148}
149
150
MembersX
Expression:resolveUnboxing
Expression:resolveTypeBinding
Expression:Expression
Expression:resolveConstantExpressionValue
Expression:resolveBoxing
Members
X