KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > core > dom > BooleanLiteral


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.jdt.core.dom;
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.List JavaDoc;
16
17 /**
18  * Boolean literal node.
19  *
20  * <pre>
21  * BooleanLiteral:
22  * <b>true</b>
23  * <b>false</b>
24  * </pre>
25  *
26  * @since 2.0
27  */

28 public class BooleanLiteral extends Expression {
29     
30     /**
31      * The "booleanValue" structural property of this node type.
32      * @since 3.0
33      */

34     public static final SimplePropertyDescriptor BOOLEAN_VALUE_PROPERTY =
35         new SimplePropertyDescriptor(BooleanLiteral.class, "booleanValue", boolean.class, MANDATORY); //$NON-NLS-1$
36

37     /**
38      * A list of property descriptors (element type:
39      * {@link StructuralPropertyDescriptor}),
40      * or null if uninitialized.
41      */

42     private static final List JavaDoc PROPERTY_DESCRIPTORS;
43     
44     static {
45         List JavaDoc properyList = new ArrayList JavaDoc(2);
46         createPropertyList(BooleanLiteral.class, properyList);
47         addProperty(BOOLEAN_VALUE_PROPERTY, properyList);
48         PROPERTY_DESCRIPTORS = reapPropertyList(properyList);
49     }
50
51     /**
52      * Returns a list of structural property descriptors for this node type.
53      * Clients must not modify the result.
54      *
55      * @param apiLevel the API level; one of the
56      * <code>AST.JLS*</code> constants
57
58      * @return a list of property descriptors (element type:
59      * {@link StructuralPropertyDescriptor})
60      * @since 3.0
61      */

62     public static List JavaDoc propertyDescriptors(int apiLevel) {
63         return PROPERTY_DESCRIPTORS;
64     }
65             
66     /**
67      * The boolean; defaults to the literal for <code>false</code>.
68      */

69     private boolean value = false;
70
71     /**
72      * Creates a new unparented boolean literal node owned by the given AST.
73      * <p>
74      * N.B. This constructor is package-private.
75      * </p>
76      *
77      * @param ast the AST that is to own this node
78      */

79     BooleanLiteral(AST ast) {
80         super(ast);
81     }
82
83     /* (omit javadoc for this method)
84      * Method declared on ASTNode.
85      */

86     final List JavaDoc internalStructuralPropertiesForType(int apiLevel) {
87         return propertyDescriptors(apiLevel);
88     }
89     
90     /* (omit javadoc for this method)
91      * Method declared on ASTNode.
92      */

93     final boolean internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean newValue) {
94         if (property == BOOLEAN_VALUE_PROPERTY) {
95             if (get) {
96                 return booleanValue();
97             } else {
98                 setBooleanValue(newValue);
99                 return false;
100             }
101         }
102         // allow default implementation to flag the error
103
return super.internalGetSetBooleanProperty(property, get, newValue);
104     }
105     
106     /* (omit javadoc for this method)
107      * Method declared on ASTNode.
108      */

109     final int getNodeType0() {
110         return BOOLEAN_LITERAL;
111     }
112
113     /* (omit javadoc for this method)
114      * Method declared on ASTNode.
115      */

116     ASTNode clone0(AST target) {
117         BooleanLiteral result = new BooleanLiteral(target);
118         result.setSourceRange(this.getStartPosition(), this.getLength());
119         result.setBooleanValue(booleanValue());
120         return result;
121     }
122
123     /* (omit javadoc for this method)
124      * Method declared on ASTNode.
125      */

126     final boolean subtreeMatch0(ASTMatcher matcher, Object JavaDoc other) {
127         // dispatch to correct overloaded match method
128
return matcher.match(this, other);
129     }
130
131     /* (omit javadoc for this method)
132      * Method declared on ASTNode.
133      */

134     void accept0(ASTVisitor visitor) {
135         visitor.visit(this);
136         visitor.endVisit(this);
137     }
138     
139     /**
140      * Returns the boolean value of this boolean literal node.
141      *
142      * @return <code>true</code> for the boolean literal spelled
143      * <code>"true"</code>, and <code>false</code> for the boolean literal
144      * spelled <code>"false"</code>.
145      */

146     public boolean booleanValue() {
147         return this.value;
148     }
149         
150     /**
151      * Sets the boolean value of this boolean literal node.
152      *
153      * @param value <code>true</code> for the boolean literal spelled
154      * <code>"true"</code>, and <code>false</code> for the boolean literal
155      * spelled <code>"false"</code>.
156      */

157     public void setBooleanValue(boolean value) {
158         preValueChange(BOOLEAN_VALUE_PROPERTY);
159         this.value = value;
160         postValueChange(BOOLEAN_VALUE_PROPERTY);
161     }
162
163     /* (omit javadoc for this method)
164      * Method declared on ASTNode.
165      */

166     int memSize() {
167         return BASE_NODE_SIZE + 1 * 4;
168     }
169     
170     /* (omit javadoc for this method)
171      * Method declared on ASTNode.
172      */

173     int treeSize() {
174         return memSize();
175     }
176 }
177
178
Popular Tags