1 | /******************************************************************************* |
---|---|
2 | * Copyright (c) 2000, 2013 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 | |
15 | package org.eclipse.jdt.core.dom; |
16 | |
17 | import java.util.ArrayList; |
18 | import java.util.List; |
19 | |
20 | /** |
21 | * Boolean literal node. |
22 | * |
23 | * <pre> |
24 | * BooleanLiteral: |
25 | * <b>true</b> |
26 | * <b>false</b> |
27 | * </pre> |
28 | * |
29 | * @since 2.0 |
30 | * @noinstantiate This class is not intended to be instantiated by clients. |
31 | */ |
32 | @SuppressWarnings("rawtypes") |
33 | public class BooleanLiteral extends Expression { |
34 | |
35 | /** |
36 | * The "booleanValue" structural property of this node type (type: {@link Boolean}). |
37 | * @since 3.0 |
38 | */ |
39 | public static final SimplePropertyDescriptor BOOLEAN_VALUE_PROPERTY = |
40 | new SimplePropertyDescriptor(BooleanLiteral.class, "booleanValue", boolean.class, MANDATORY); //$NON-NLS-1$ |
41 | |
42 | /** |
43 | * A list of property descriptors (element type: |
44 | * {@link StructuralPropertyDescriptor}), |
45 | * or null if uninitialized. |
46 | */ |
47 | private static final List PROPERTY_DESCRIPTORS; |
48 | |
49 | static { |
50 | List properyList = new ArrayList(2); |
51 | createPropertyList(BooleanLiteral.class, properyList); |
52 | addProperty(BOOLEAN_VALUE_PROPERTY, properyList); |
53 | PROPERTY_DESCRIPTORS = reapPropertyList(properyList); |
54 | } |
55 | |
56 | /** |
57 | * Returns a list of structural property descriptors for this node type. |
58 | * Clients must not modify the result. |
59 | * |
60 | * @param apiLevel the API level; one of the |
61 | * <code>AST.JLS*</code> constants |
62 | |
63 | * @return a list of property descriptors (element type: |
64 | * {@link StructuralPropertyDescriptor}) |
65 | * @since 3.0 |
66 | */ |
67 | public static List propertyDescriptors(int apiLevel) { |
68 | return PROPERTY_DESCRIPTORS; |
69 | } |
70 | |
71 | /** |
72 | * The boolean; defaults to the literal for <code>false</code>. |
73 | */ |
74 | private boolean value = false; |
75 | |
76 | /** |
77 | * Creates a new unparented boolean literal node owned by the given AST. |
78 | * <p> |
79 | * N.B. This constructor is package-private. |
80 | * </p> |
81 | * |
82 | * @param ast the AST that is to own this node |
83 | */ |
84 | BooleanLiteral(AST ast) { |
85 | super(ast); |
86 | } |
87 | |
88 | @Override |
89 | final List internalStructuralPropertiesForType(int apiLevel) { |
90 | return propertyDescriptors(apiLevel); |
91 | } |
92 | |
93 | @Override |
94 | final boolean internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean newValue) { |
95 | if (property == BOOLEAN_VALUE_PROPERTY) { |
96 | if (get) { |
97 | return booleanValue(); |
98 | } else { |
99 | setBooleanValue(newValue); |
100 | return false; |
101 | } |
102 | } |
103 | // allow default implementation to flag the error |
104 | return super.internalGetSetBooleanProperty(property, get, newValue); |
105 | } |
106 | |
107 | @Override |
108 | final int getNodeType0() { |
109 | return BOOLEAN_LITERAL; |
110 | } |
111 | |
112 | @Override |
113 | ASTNode clone0(AST target) { |
114 | BooleanLiteral result = new BooleanLiteral(target); |
115 | result.setSourceRange(getStartPosition(), getLength()); |
116 | result.setBooleanValue(booleanValue()); |
117 | return result; |
118 | } |
119 | |
120 | @Override |
121 | final boolean subtreeMatch0(ASTMatcher matcher, Object other) { |
122 | // dispatch to correct overloaded match method |
123 | return matcher.match(this, other); |
124 | } |
125 | |
126 | @Override |
127 | void accept0(ASTVisitor visitor) { |
128 | visitor.visit(this); |
129 | visitor.endVisit(this); |
130 | } |
131 | |
132 | /** |
133 | * Returns the boolean value of this boolean literal node. |
134 | * |
135 | * @return <code>true</code> for the boolean literal spelled |
136 | * <code>"true"</code>, and <code>false</code> for the boolean literal |
137 | * spelled <code>"false"</code>. |
138 | */ |
139 | public boolean booleanValue() { |
140 | return this.value; |
141 | } |
142 | |
143 | /** |
144 | * Sets the boolean value of this boolean literal node. |
145 | * |
146 | * @param value <code>true</code> for the boolean literal spelled |
147 | * <code>"true"</code>, and <code>false</code> for the boolean literal |
148 | * spelled <code>"false"</code>. |
149 | */ |
150 | public void setBooleanValue(boolean value) { |
151 | preValueChange(BOOLEAN_VALUE_PROPERTY); |
152 | this.value = value; |
153 | postValueChange(BOOLEAN_VALUE_PROPERTY); |
154 | } |
155 | |
156 | @Override |
157 | int memSize() { |
158 | return BASE_NODE_SIZE + 1 * 4; |
159 | } |
160 | |
161 | @Override |
162 | int treeSize() { |
163 | return memSize(); |
164 | } |
165 | } |
166 | |
167 |
Members