Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: eccf166d2d2c3e70ce2dc7685de5616072aff68a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*******************************************************************************
 * Copyright (c) 2000, 2019 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.jdt.core.dom;

/**
 * Abstract base class of AST nodes that represent expressions.
 * There are several kinds of expressions.
 * <p>
 * <pre>
 * Expression:
 *    {@link Annotation},
 *    {@link ArrayAccess},
 *    {@link ArrayCreation},
 *    {@link ArrayInitializer},
 *    {@link Assignment},
 *    {@link BooleanLiteral},
 *    {@link CastExpression},
 *    {@link CharacterLiteral},
 *    {@link ClassInstanceCreation},
 *    {@link ConditionalExpression},
 *    {@link CreationReference},
 *    {@link ExpressionMethodReference},
 *    {@link FieldAccess},
 *    {@link InfixExpression},
 *    {@link InstanceofExpression},
 *    {@link LambdaExpression},
 *    {@link MethodInvocation},
 *    {@link MethodReference},
 *    {@link Name},
 *    {@link NullLiteral},
 *    {@link NumberLiteral},
 *    {@link ParenthesizedExpression},
 *    {@link PostfixExpression},
 *    {@link PrefixExpression},
 *    {@link StringLiteral},
 *    {@link SuperFieldAccess},
 *    {@link SuperMethodInvocation},
 *    {@link SuperMethodReference},
 *    {@link SwitchExpression},
 *    {@link ThisExpression},
 *    {@link TypeLiteral},
 *    {@link TypeMethodReference},
 *    {@link VariableDeclarationExpression}
 * </pre>
 * </p>
 *
 * @since 2.0
 */
public abstract class Expression extends ASTNode {

	/**
	 * Creates a new AST node for an expression owned by the given AST.
	 * <p>
	 * N.B. This constructor is package-private.
	 * </p>
	 *
	 * @param ast the AST that is to own this node
	 */
	Expression(AST ast) {
		super(ast);
	}

	/**
	 * Resolves and returns the compile-time constant expression value as
	 * specified in JLS2 15.28, if this expression has one. Constant expression
	 * values are unavailable unless bindings are requested when the AST is
	 * being built. If the type of the value is a primitive type, the result
	 * is the boxed equivalent (i.e., int returned as an <code>Integer</code>);
	 * if the type of the value is <code>String</code>, the result is the string
	 * itself. If the expression does not have a compile-time constant expression
	 * value, the result is <code>null</code>.
	 * <p>
	 * Resolving constant expressions takes into account the value of simple
	 * and qualified names that refer to constant variables (JLS2 4.12.4).
	 * </p>
	 * <p>
	 * Note 1: enum constants are not considered constant expressions.
	 * The result is always <code>null</code> for these.
	 * </p>
	 * <p>
	 * Note 2: Compile-time constant expressions cannot denote <code>null</code>.
	 * So technically {@link NullLiteral} nodes are not constant expressions.
	 * The result is <code>null</code> for these nonetheless.
	 * </p>
	 *
	 * @return the constant expression value, or <code>null</code> if this
	 * expression has no constant expression value or if bindings were not
	 * requested when the AST was created
	 * @since 3.1
	 */
	public final Object resolveConstantExpressionValue() {
		return this.ast.getBindingResolver().resolveConstantExpressionValue(this);
	}

	/**
	 * Resolves and returns the binding for the type of this expression.
	 * <p>
	 * Note that bindings are generally unavailable unless requested when the
	 * AST is being built.
	 * </p>
	 *
	 * @return the binding for the type of this expression, or
	 *    <code>null</code> if the type cannot be resolved
	 */
	public final ITypeBinding resolveTypeBinding() {
		return this.ast.getBindingResolver().resolveExpressionType(this);
	}

	/**
	 * Returns whether this expression node is the site of a boxing
	 * conversion (JLS3 5.1.7). This information is available only
	 * when bindings are requested when the AST is being built.
	 *
	 * @return <code>true</code> if this expression is the site of a
	 * boxing conversion, or <code>false</code> if either no boxing conversion
	 * is involved or if bindings were not requested when the AST was created
	 * @since 3.1
	 */
	public final boolean resolveBoxing() {
		return this.ast.getBindingResolver().resolveBoxing(this);
	}

	/**
	 * Returns whether this expression node is the site of an unboxing
	 * conversion (JLS3 5.1.8). This information is available only
	 * when bindings are requested when the AST is being built.
	 *
	 * @return <code>true</code> if this expression is the site of an
	 * unboxing conversion, or <code>false</code> if either no unboxing
	 * conversion is involved or if bindings were not requested when the
	 * AST was created
	 * @since 3.1
	 */
	public final boolean resolveUnboxing() {
		return this.ast.getBindingResolver().resolveUnboxing(this);
	}
}

Back to the top