001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.core.dom;
011:
012: import java.util.ArrayList;
013: import java.util.List;
014:
015: /**
016: * Boolean literal node.
017: *
018: * <pre>
019: * BooleanLiteral:
020: * <b>true</b>
021: * <b>false</b>
022: * </pre>
023: *
024: * @since 2.0
025: */
026: public class BooleanLiteral extends Expression {
027:
028: /**
029: * The "booleanValue" structural property of this node type.
030: * @since 3.0
031: */
032: public static final SimplePropertyDescriptor BOOLEAN_VALUE_PROPERTY = new SimplePropertyDescriptor(
033: BooleanLiteral.class,
034: "booleanValue", boolean.class, MANDATORY); //$NON-NLS-1$
035:
036: /**
037: * A list of property descriptors (element type:
038: * {@link StructuralPropertyDescriptor}),
039: * or null if uninitialized.
040: */
041: private static final List PROPERTY_DESCRIPTORS;
042:
043: static {
044: List properyList = new ArrayList(2);
045: createPropertyList(BooleanLiteral.class, properyList);
046: addProperty(BOOLEAN_VALUE_PROPERTY, properyList);
047: PROPERTY_DESCRIPTORS = reapPropertyList(properyList);
048: }
049:
050: /**
051: * Returns a list of structural property descriptors for this node type.
052: * Clients must not modify the result.
053: *
054: * @param apiLevel the API level; one of the
055: * <code>AST.JLS*</code> constants
056:
057: * @return a list of property descriptors (element type:
058: * {@link StructuralPropertyDescriptor})
059: * @since 3.0
060: */
061: public static List propertyDescriptors(int apiLevel) {
062: return PROPERTY_DESCRIPTORS;
063: }
064:
065: /**
066: * The boolean; defaults to the literal for <code>false</code>.
067: */
068: private boolean value = false;
069:
070: /**
071: * Creates a new unparented boolean literal node owned by the given AST.
072: * <p>
073: * N.B. This constructor is package-private.
074: * </p>
075: *
076: * @param ast the AST that is to own this node
077: */
078: BooleanLiteral(AST ast) {
079: super (ast);
080: }
081:
082: /* (omit javadoc for this method)
083: * Method declared on ASTNode.
084: */
085: final List internalStructuralPropertiesForType(int apiLevel) {
086: return propertyDescriptors(apiLevel);
087: }
088:
089: /* (omit javadoc for this method)
090: * Method declared on ASTNode.
091: */
092: final boolean internalGetSetBooleanProperty(
093: SimplePropertyDescriptor property, boolean get,
094: boolean newValue) {
095: if (property == BOOLEAN_VALUE_PROPERTY) {
096: if (get) {
097: return booleanValue();
098: } else {
099: setBooleanValue(newValue);
100: return false;
101: }
102: }
103: // allow default implementation to flag the error
104: return super .internalGetSetBooleanProperty(property, get,
105: newValue);
106: }
107:
108: /* (omit javadoc for this method)
109: * Method declared on ASTNode.
110: */
111: final int getNodeType0() {
112: return BOOLEAN_LITERAL;
113: }
114:
115: /* (omit javadoc for this method)
116: * Method declared on ASTNode.
117: */
118: ASTNode clone0(AST target) {
119: BooleanLiteral result = new BooleanLiteral(target);
120: result
121: .setSourceRange(this .getStartPosition(), this
122: .getLength());
123: result.setBooleanValue(booleanValue());
124: return result;
125: }
126:
127: /* (omit javadoc for this method)
128: * Method declared on ASTNode.
129: */
130: final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
131: // dispatch to correct overloaded match method
132: return matcher.match(this , other);
133: }
134:
135: /* (omit javadoc for this method)
136: * Method declared on ASTNode.
137: */
138: void accept0(ASTVisitor visitor) {
139: visitor.visit(this );
140: visitor.endVisit(this );
141: }
142:
143: /**
144: * Returns the boolean value of this boolean literal node.
145: *
146: * @return <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 boolean booleanValue() {
151: return this .value;
152: }
153:
154: /**
155: * Sets the boolean value of this boolean literal node.
156: *
157: * @param value <code>true</code> for the boolean literal spelled
158: * <code>"true"</code>, and <code>false</code> for the boolean literal
159: * spelled <code>"false"</code>.
160: */
161: public void setBooleanValue(boolean value) {
162: preValueChange(BOOLEAN_VALUE_PROPERTY);
163: this .value = value;
164: postValueChange(BOOLEAN_VALUE_PROPERTY);
165: }
166:
167: /* (omit javadoc for this method)
168: * Method declared on ASTNode.
169: */
170: int memSize() {
171: return BASE_NODE_SIZE + 1 * 4;
172: }
173:
174: /* (omit javadoc for this method)
175: * Method declared on ASTNode.
176: */
177: int treeSize() {
178: return memSize();
179: }
180: }
|