View | Details | Raw Unified | Return to bug 36144 | Differences between
and this patch

Collapse All | Expand All

(-)dom/org/eclipse/jdt/core/dom/AST.java (-3 / +37 lines)
Lines 812-818 Link Here
812
	
812
	
813
	/**
813
	/**
814
	 * Creates an unparented import declaration node owned by this AST.
814
	 * Creates an unparented import declaration node owned by this AST.
815
	 * The import declaration initially contains a single-type import
815
	 * The import declaration initially contains a regular single-type import
816
	 * of a type with an unspecified name.
816
	 * of a type with an unspecified name.
817
	 * 
817
	 * 
818
	 * @return the new unparented import declaration node
818
	 * @return the new unparented import declaration node
Lines 834-840 Link Here
834
	 * and an empty class body.
834
	 * and an empty class body.
835
	 * <p>
835
	 * <p>
836
	 * To create an interface, use this method and then call
836
	 * To create an interface, use this method and then call
837
	 * <code>TypeDeclaration.setInterface(true)</code> and
837
	 * <code>TypeDeclaration.setInterface(true)</code>.
838
	 * </p>
839
	 * <p>
840
	 * To create an enum declaration, use this method and then call
841
	 * <code>TypeDeclaration.setEnumeration(true)</code>.
838
	 * </p>
842
	 * </p>
839
	 * 
843
	 * 
840
	 * @return a new unparented type declaration node
844
	 * @return a new unparented type declaration node
Lines 903-908 Link Here
903
	}
907
	}
904
908
905
	/**
909
	/**
910
	 * Creates an unparented enum constant declaration node owned by this AST.
911
	 * The name of the constant is an unspecified, but legal, name; 
912
	 * no Javadoc comment; an empty list of arguments; and an empty class body.
913
	 * 
914
	 * @return a new unparented edeclaration node
915
	 */
916
	public EnumConstantDeclaration newEnumConstantDeclaration() {
917
		EnumConstantDeclaration result = new EnumConstantDeclaration(this);
918
		return result;
919
	}
920
	
921
	/**
906
	 * Creates and returns a new Javadoc comment node.
922
	 * Creates and returns a new Javadoc comment node.
907
	 * Initially the new node has an unspecified, but legal, Javadoc comment.
923
	 * Initially the new node has an unspecified, but legal, Javadoc comment.
908
	 * 
924
	 * 
Lines 1169-1178 Link Here
1169
	 * By default, there are no initializers, no condition expression, 
1185
	 * By default, there are no initializers, no condition expression, 
1170
	 * no updaters, and the body is an empty block.
1186
	 * no updaters, and the body is an empty block.
1171
	 * 
1187
	 * 
1172
	 * @return a new unparented throw statement node
1188
	 * @return a new unparented for statement node
1173
	 */
1189
	 */
1174
	public ForStatement newForStatement() {
1190
	public ForStatement newForStatement() {
1175
		return new ForStatement(this);
1191
		return new ForStatement(this);
1192
	}
1193
1194
	/**
1195
	 * Creates a new unparented enhanced for statement node owned by this AST.
1196
	 * By default, the type, name, and expression are unspecified
1197
	 * but legal subtrees, and the body is an empty block.
1198
	 * <p>
1199
	 * Note: Enhanced for statements are an experimental language feature 
1200
	 * under discussion in JSR-201 and under consideration for inclusion
1201
	 * in the 1.5 release of J2SE. The support here is therefore tentative
1202
	 * and subject to change.
1203
	 * </p>
1204
	 * 
1205
	 * @return a new unparented throw statement node
1206
	 * @since 2.2
1207
	 */
1208
	public EnhancedForStatement newEnhancedForStatement() {
1209
		return new EnhancedForStatement(this);
1176
	}
1210
	}
1177
1211
1178
	//=============================== EXPRESSIONS ===========================
1212
	//=============================== EXPRESSIONS ===========================
(-)dom/org/eclipse/jdt/core/dom/ASTMatcher.java (-1 / +71 lines)
Lines 608-613 Link Here
608
	 * other object is a node of the same type with structurally isomorphic
608
	 * other object is a node of the same type with structurally isomorphic
609
	 * child subtrees. Subclasses may override this method as needed.
609
	 * child subtrees. Subclasses may override this method as needed.
610
	 * </p>
610
	 * </p>
611
	 * <p>
612
	 * Note: Enhanced for statements are an experimental language feature 
613
	 * under discussion in JSR-201 and under consideration for inclusion
614
	 * in the 1.5 release of J2SE. The support here is therefore tentative
615
	 * and subject to change.
616
	 * </p>
617
	 * 
618
	 * @param node the node
619
	 * @param other the other object, or <code>null</code>
620
	 * @return <code>true</code> if the subtree matches, or 
621
	 *   <code>false</code> if they do not match or the other object has a
622
	 *   different node type or is <code>null</code>
623
	 * @since 2.2
624
	 */
625
	public boolean match(EnhancedForStatement node, Object other) {
626
		if (!(other instanceof EnhancedForStatement)) {
627
			return false;
628
		}
629
		EnhancedForStatement o = (EnhancedForStatement) other;
630
		return (
631
			safeSubtreeMatch(node.getType(), o.getType())
632
				&& safeSubtreeMatch(node.getName(), o.getName())
633
				&& safeSubtreeMatch(node.getExpression(), o.getExpression())
634
				&& safeSubtreeMatch(node.getBody(), o.getBody()));
635
	}
636
637
	/**
638
	 * Returns whether the given node and the other object match.
639
	 * <p>
640
	 * The default implementation provided by this class tests whether the
641
	 * other object is a node of the same type with structurally isomorphic
642
	 * child subtrees. Subclasses may override this method as needed.
643
	 * </p>
644
	 * <p>
645
	 * Note: Enum declarations are an experimental language feature 
646
	 * under discussion in JSR-201 and under consideration for inclusion
647
	 * in the 1.5 release of J2SE. The support here is therefore tentative
648
	 * and subject to change.
649
	 * </p>
650
	 * 
651
	 * @param node the node
652
	 * @param other the other object, or <code>null</code>
653
	 * @return <code>true</code> if the subtree matches, or 
654
	 *   <code>false</code> if they do not match or the other object has a
655
	 *   different node type or is <code>null</code>
656
	 * @since 2.2
657
	 */
658
	public boolean match(EnumConstantDeclaration node, Object other) {
659
		if (!(other instanceof EnumConstantDeclaration)) {
660
			return false;
661
		}
662
		EnumConstantDeclaration o = (EnumConstantDeclaration) other;
663
		return (
664
			safeSubtreeMatch(node.getJavadoc(), o.getJavadoc())
665
				&& safeSubtreeMatch(node.getName(), o.getName())
666
				&& safeSubtreeListMatch(node.arguments(), o.arguments())
667
				&& safeSubtreeListMatch(
668
					node.bodyDeclarations(),
669
					o.bodyDeclarations()));
670
	}
671
	
672
	/**
673
	 * Returns whether the given node and the other object match.
674
	 * <p>
675
	 * The default implementation provided by this class tests whether the
676
	 * other object is a node of the same type with structurally isomorphic
677
	 * child subtrees. Subclasses may override this method as needed.
678
	 * </p>
611
	 * 
679
	 * 
612
	 * @param node the node
680
	 * @param node the node
613
	 * @param other the other object, or <code>null</code>
681
	 * @param other the other object, or <code>null</code>
Lines 744-750 Link Here
744
		ImportDeclaration o = (ImportDeclaration) other;
812
		ImportDeclaration o = (ImportDeclaration) other;
745
		return (
813
		return (
746
			safeSubtreeMatch(node.getName(), o.getName())
814
			safeSubtreeMatch(node.getName(), o.getName())
747
				&& node.isOnDemand() == o.isOnDemand());
815
				&& node.isOnDemand() == o.isOnDemand()
816
				&& node.isStatic() == o.isStatic());
748
	}
817
	}
749
818
750
	/**
819
	/**
Lines 1475-1480 Link Here
1475
		return (
1544
		return (
1476
			(node.getModifiers() == o.getModifiers())
1545
			(node.getModifiers() == o.getModifiers())
1477
				&& (node.isInterface() == o.isInterface())
1546
				&& (node.isInterface() == o.isInterface())
1547
				&& (node.isEnumeration() == o.isEnumeration())
1478
				&& safeSubtreeMatch(node.getJavadoc(), o.getJavadoc())
1548
				&& safeSubtreeMatch(node.getJavadoc(), o.getJavadoc())
1479
				&& safeSubtreeMatch(node.getName(), o.getName())
1549
				&& safeSubtreeMatch(node.getName(), o.getName())
1480
				&& safeSubtreeMatch(node.getSuperclass(), o.getSuperclass())
1550
				&& safeSubtreeMatch(node.getSuperclass(), o.getSuperclass())
(-)dom/org/eclipse/jdt/core/dom/ASTNode.java (+28 lines)
Lines 549-554 Link Here
549
	public static final int INSTANCEOF_EXPRESSION = 62;
549
	public static final int INSTANCEOF_EXPRESSION = 62;
550
550
551
	/**
551
	/**
552
	 * Node type constant indicating a node of type 
553
	 * <code>EnhancedForStatement</code>.
554
	 * <p>
555
	 * Note: Enhanced for statements are an experimental language feature 
556
	 * under discussion in JSR-201 and under consideration for inclusion
557
	 * in the 1.5 release of J2SE. The support here is therefore tentative
558
	 * and subject to change.
559
	 * </p>
560
	 * @see EnhancedForStatement
561
	 * @since 2.2
562
	 */
563
	public static final int ENHANCED_FOR_STATEMENT = 63;
564
565
	/**
566
	 * Node type constant indicating a node of type 
567
	 * <code>EnumConstantDeclaration</code>.
568
	 * <p>
569
	 * Note: Enum declarations are an experimental language feature 
570
	 * under discussion in JSR-201 and under consideration for inclusion
571
	 * in the 1.5 release of J2SE. The support here is therefore tentative
572
	 * and subject to change.
573
	 * </p>
574
	 * @see EnumConstantDeclaration
575
	 * @since 2.2
576
	 */
577
	public static final int ENUM_CONSTANT_DECLARATION = 64;
578
579
	/**
552
	 * Owning AST.
580
	 * Owning AST.
553
	 */
581
	 */
554
	private final AST owner;
582
	private final AST owner;
(-)dom/org/eclipse/jdt/core/dom/ASTVisitor.java (+50 lines)
Lines 181-186 Link Here
181
	public boolean visit(EmptyStatement node) {
181
	public boolean visit(EmptyStatement node) {
182
		return true;
182
		return true;
183
	}
183
	}
184
	/** Visits the given node.
185
	 * <p>
186
	 * Note: Enhanced for statements are an experimental language feature 
187
	 * under discussion in JSR-201 and under consideration for inclusion
188
	 * in the 1.5 release of J2SE. The support here is therefore tentative
189
	 * and subject to change.
190
	 * </p>
191
	 * 
192
	 * @since 2.2
193
	 */
194
	public boolean visit(EnhancedForStatement node) {
195
		return true;
196
	}
197
	/** Visits the given node.
198
	 * <p>
199
	 * Note: Enum declarations are an experimental language feature 
200
	 * under discussion in JSR-201 and under consideration for inclusion
201
	 * in the 1.5 release of J2SE. The support here is therefore tentative
202
	 * and subject to change.
203
	 * </p>
204
	 * 
205
	 * @since 2.2
206
	 */
207
	public boolean visit(EnumConstantDeclaration node) {
208
		return true;
209
	}
184
	public boolean visit(ExpressionStatement node) {
210
	public boolean visit(ExpressionStatement node) {
185
		return true;
211
		return true;
186
	}
212
	}
Lines 347-352 Link Here
347
	public void endVisit(DoStatement node) {
373
	public void endVisit(DoStatement node) {
348
	}
374
	}
349
	public void endVisit(EmptyStatement node) {
375
	public void endVisit(EmptyStatement node) {
376
	}
377
	/** End of visit of the given node.
378
	 * <p>
379
	 * Note: Enhanced for statements are an experimental language feature 
380
	 * under discussion in JSR-201 and under consideration for inclusion
381
	 * in the 1.5 release of J2SE. The support here is therefore tentative
382
	 * and subject to change.
383
	 * </p>
384
	 * 
385
	 * @since 2.2
386
	 */
387
	public void endVisit(EnhancedForStatement node) {
388
	}
389
	/** End of visit of the given node.
390
	 * <p>
391
	 * Note: Enum declarations are an experimental language feature 
392
	 * under discussion in JSR-201 and under consideration for inclusion
393
	 * in the 1.5 release of J2SE. The support here is therefore tentative
394
	 * and subject to change.
395
	 * </p>
396
	 * 
397
	 * @since 2.2
398
	 */
399
	public void endVisit(EnumConstantDeclaration node) {
350
	}
400
	}
351
	public void endVisit(ExpressionStatement node) {
401
	public void endVisit(ExpressionStatement node) {
352
	}
402
	}
(-)dom/org/eclipse/jdt/core/dom/BindingResolver.java (+50 lines)
Lines 246-251 Link Here
246
	IVariableBinding resolveVariable(VariableDeclaration variable) {
246
	IVariableBinding resolveVariable(VariableDeclaration variable) {
247
		return null;
247
		return null;
248
	}
248
	}
249
	
250
	/**
251
	 * Resolves the loop variable of the given enhanced for statement and 
252
	 * returns the binding for it.
253
	 * <p>
254
	 * The default implementation of this method returns <code>null</code>.
255
	 * Subclasses may reimplement.
256
	 * </p>
257
	 * <p>
258
	 * Note: Enhanced for statements are an experimental language feature 
259
	 * under discussion in JSR-201 and under consideration for inclusion
260
	 * in the 1.5 release of J2SE. The support here is therefore tentative
261
	 * and subject to change.
262
	 * </p>
263
	 * 
264
	 * @param statement the enhanced for statement of interest
265
	 * @return the binding for the loop variable for the given enhanced for
266
	 *    statement, or <code>null</code> if no binding is available
267
	 * @since 2.2
268
	 */
269
	IVariableBinding resolveVariable(EnhancedForStatement statement) {
270
		return null;
271
	}
249
272
250
	/**
273
	/**
251
	 * Resolves the given field declaration and returns the binding for it.
274
	 * Resolves the given field declaration and returns the binding for it.
Lines 265-270 Link Here
265
	 *    <code>null</code> if no binding is available
288
	 *    <code>null</code> if no binding is available
266
	 */
289
	 */
267
	IVariableBinding resolveVariable(FieldDeclaration variable) {
290
	IVariableBinding resolveVariable(FieldDeclaration variable) {
291
		return null;
292
	}
293
		
294
	/**
295
	 * Resolves the given enum constant declaration and returns the binding for
296
	 * the field.
297
	 * <p>
298
	 * The implementation of <code>EnumConstantDeclaration.resolveVariable</code>
299
	 * forwards to this method.
300
	 * </p>
301
	 * <p>
302
	 * The default implementation of this method returns <code>null</code>.
303
	 * Subclasses may reimplement.
304
	 * </p>
305
	 * <p>
306
	 * Note: Enum declarations are an experimental language feature 
307
	 * under discussion in JSR-201 and under consideration for inclusion
308
	 * in the 1.5 release of J2SE. The support here is therefore tentative
309
	 * and subject to change.
310
	 * </p>
311
	 * 
312
	 * @param enumConstant the enum constant declaration of interest
313
	 * @return the field binding for the given enum constant declaration, or 
314
	 *    <code>null</code> if no binding is available
315
	 * @since 2.2
316
	 */
317
	IVariableBinding resolveVariable(EnumConstantDeclaration enumConstant) {
268
		return null;
318
		return null;
269
	}
319
	}
270
		
320
		
(-)dom/org/eclipse/jdt/core/dom/BodyDeclaration.java (-7 / +7 lines)
Lines 13-33 Link Here
13
13
14
/**
14
/**
15
 * Abstract base class of all AST nodes that represent body declarations 
15
 * Abstract base class of all AST nodes that represent body declarations 
16
 * that may appear in the body of a class or interface declaration.
16
 * that may appear in the body of some kind of class or interface declaration,
17
 * including anonymous class declarations, enumeration declarations, and
18
 * enumeration constant declarations.
19
 * 
17
 * <p>
20
 * <p>
18
 * <pre>
21
 * <pre>
19
 * ClassBodyDeclaration:
22
 * BodyDeclaration:
20
 *		ClassDeclaration
23
 *		ClassDeclaration
21
 *		InterfaceDeclaration
24
 *		InterfaceDeclaration
25
 *		EnumDeclaration
22
 *		MethodDeclaration
26
 *		MethodDeclaration
23
 * 		ConstructorDeclaration
27
 * 		ConstructorDeclaration
24
 * 		FieldDeclaration
28
 * 		FieldDeclaration
25
 * 		Initializer
29
 * 		Initializer
26
 * InterfaceBodyDeclaration:
30
 *		EnumConstantDeclaration
27
 *		ClassDeclaration
28
 *		InterfaceDeclaration
29
 *		MethodDeclaration
30
 * 		FieldDeclaration
31
 * </pre>
31
 * </pre>
32
 * </p>
32
 * </p>
33
 * <p>
33
 * <p>
(-)dom/org/eclipse/jdt/core/dom/EnhancedForStatement.java (+285 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.jdt.core.dom;
13
14
/**
15
 * Enhanced For statement AST node type.
16
 *
17
 * <pre>
18
 * EnhancedForStatement:
19
 *    <b>for</b> <b>(</b> Type Identifier<b>:</b> Expression <b>)</b>
20
 * 			Statement
21
 * </pre>
22
 * 
23
 * <p>
24
 * Note: Enhanced for statements are an experimental language feature 
25
 * under discussion in JSR-201 and under consideration for inclusion
26
 * in the 1.5 release of J2SE. The support here is therefore tentative
27
 * and subject to change.
28
 * </p>
29
 * @since 2.2
30
 */
31
public class EnhancedForStatement extends Statement {
32
	
33
	/**
34
	 * The type; lazily initialized; defaults to a unspecified,
35
	 * legal type.
36
	 */
37
	private Type type = null;
38
39
	/**
40
	 * The variable name; lazily initialized; defaults to an unspecified,
41
	 * legal Java identifier.
42
	 */
43
	private SimpleName variableName = null;
44
45
	/**
46
	 * The expression; lazily initialized; defaults to a unspecified, but legal,
47
	 * expression.
48
	 */
49
	private Expression expression = null;
50
51
	/**
52
	 * The body statement; lazily initialized; defaults to an empty block
53
	 * statement.
54
	 */
55
	private Statement body = null;
56
			
57
	/**
58
	 * Creates a new AST node for an enchanced for statement owned by the
59
	 * given AST. By default, the type, name, and expression are unspecified
60
	 * but legal subtrees, and the body is an empty block.
61
	 * 
62
	 * @param ast the AST that is to own this node
63
	 */
64
	EnhancedForStatement(AST ast) {
65
		super(ast);
66
	}
67
68
	/* (omit javadoc for this method)
69
	 * Method declared on ASTNode.
70
	 */
71
	public int getNodeType() {
72
		return ENHANCED_FOR_STATEMENT;
73
	}
74
75
	/* (omit javadoc for this method)
76
	 * Method declared on ASTNode.
77
	 */
78
	ASTNode clone(AST target) {
79
		EnhancedForStatement result = new EnhancedForStatement(target);
80
		result.setSourceRange(this.getStartPosition(), this.getLength());
81
		result.copyLeadingComment(this);
82
		result.setType((Type) getType().clone(target));
83
		result.setName((SimpleName) getName().clone(target));
84
		result.setExpression((Expression) getExpression().clone(target));
85
		result.setBody(
86
			(Statement) ASTNode.copySubtree(target, getBody()));
87
		return result;
88
	}
89
90
	/* (omit javadoc for this method)
91
	 * Method declared on ASTNode.
92
	 */
93
	public boolean subtreeMatch(ASTMatcher matcher, Object other) {
94
		// dispatch to correct overloaded match method
95
		return matcher.match(this, other);
96
	}
97
98
	/* (omit javadoc for this method)
99
	 * Method declared on ASTNode.
100
	 */
101
	void accept0(ASTVisitor visitor) {
102
		boolean visitChildren = visitor.visit(this);
103
		if (visitChildren) {
104
			// visit children in normal left to right reading order
105
			acceptChild(visitor, getType());
106
			acceptChild(visitor, getName());
107
			acceptChild(visitor, getExpression());
108
			acceptChild(visitor, getBody());
109
		}
110
		visitor.endVisit(this);
111
	}
112
	
113
	/**
114
	 * Returns the type in this enhanced for statement.
115
	 * 
116
	 * @return the type
117
	 */ 
118
	public Type getType() {
119
		if (type == null) {
120
			// lazy initialize - use setter to ensure parent link set too
121
			long count = getAST().modificationCount();
122
			setType(getAST().newPrimitiveType(PrimitiveType.INT));
123
			getAST().setModificationCount(count);
124
		}
125
		return type;
126
	}
127
128
	/**
129
	 * Sets the type in this enhanced for statement to the given type.
130
	 * 
131
	 * @param type the new type
132
	 * @exception IllegalArgumentException if:
133
	 * <ul>
134
	 * <li>the node belongs to a different AST</li>
135
	 * <li>the node already has a parent</li>
136
	 * </ul>
137
	 */ 
138
	public void setType(Type type) {
139
		if (type == null) {
140
			throw new IllegalArgumentException();
141
		}
142
		// an EnchacedForStatement cannot occur inside a Type - cycles not possible
143
		replaceChild(this.type, type, false);
144
		this.type = type;
145
	}
146
	
147
	/**
148
	 * Returns the name of the variable in this enhanced for statement.
149
	 * 
150
	 * @return the variable name node
151
	 */ 
152
	public SimpleName getName() {
153
		if (variableName == null) {
154
			// lazy initialize - use setter to ensure parent link set too
155
			long count = getAST().modificationCount();
156
			setName(new SimpleName(getAST()));
157
			getAST().setModificationCount(count);
158
		}
159
		return variableName;
160
	}
161
		
162
	/**
163
	 * Sets the name of the variable in this enhanced for statement
164
	 * to the given name.
165
	 * 
166
	 * @param variableName the new variable name
167
	 * @exception IllegalArgumentException if:
168
	 * <ul>
169
	 * <li>the node belongs to a different AST</li>
170
	 * <li>the node already has a parent</li>
171
	 * </ul>
172
	 */ 
173
	public void setName(SimpleName variableName) {
174
		if (variableName == null) {
175
			throw new IllegalArgumentException();
176
		}
177
		replaceChild(this.variableName, variableName, false);
178
		this.variableName = variableName;
179
	}
180
181
	/**
182
	 * Returns the expression of this enhanced for statement.
183
	 * 
184
	 * @return the expression node
185
	 */ 
186
	public Expression getExpression() {
187
		if (expression == null) {
188
			// lazy initialize - use setter to ensure parent link set too
189
			long count = getAST().modificationCount();
190
			setExpression(new SimpleName(getAST()));
191
			getAST().setModificationCount(count);
192
		}
193
		return expression;
194
	}
195
		
196
	/**
197
	 * Sets the expression of this enhanced for statement.
198
	 * 
199
	 * @param expression the new expression node
200
	 * @exception IllegalArgumentException if:
201
	 * <ul>
202
	 * <li>the node belongs to a different AST</li>
203
	 * <li>the node already has a parent</li>
204
	 * <li>a cycle in would be created</li>
205
	 * </ul>
206
	 */ 
207
	public void setExpression(Expression expression) {
208
		if (expression == null) {
209
			throw new IllegalArgumentException();
210
		}
211
		// an EnhancedForStatement may occur inside an Expression 
212
		// must check cycles
213
		replaceChild(this.expression, expression, true);
214
		this.expression = expression;
215
	}
216
217
	/**
218
	 * Returns the body of this enchanced for statement.
219
	 * 
220
	 * @return the body statement node
221
	 */ 
222
	public Statement getBody() {
223
		if (body == null) {
224
			// lazy initialize - use setter to ensure parent link set too
225
			long count = getAST().modificationCount();
226
			setBody(new Block(getAST()));
227
			getAST().setModificationCount(count);
228
		}
229
		return body;
230
	}
231
	
232
	/**
233
	 * Sets the body of this enhanced for statement.
234
	 * 
235
	 * @param statement the body statement node
236
	 * @exception IllegalArgumentException if:
237
	 * <ul>
238
	 * <li>the node belongs to a different AST</li>
239
	 * <li>the node already has a parent</li>
240
	 * <li>a cycle in would be created</li>
241
	 * </ul>
242
	 */ 
243
	public void setBody(Statement statement) {
244
		if (statement == null) {
245
			throw new IllegalArgumentException();
246
		}
247
		// an EnhancedForStatement may occur inside a Statement - must check cycles
248
		replaceChild(this.body, statement, true);
249
		this.body = statement;
250
	}
251
	
252
	/**
253
	 * Resolves and returns the binding for the loop variable of this
254
	 * enhanced for statement.
255
	 * <p>
256
	 * Note that bindings are generally unavailable unless requested when the
257
	 * AST is being built.
258
	 * </p>
259
	 * 
260
	 * @return the binding, or <code>null</code> if the binding cannot be 
261
	 *    resolved
262
	 */	
263
	public IVariableBinding resolveBinding() {
264
		return getAST().getBindingResolver().resolveVariable(this);
265
	}
266
267
	/* (omit javadoc for this method)
268
	 * Method declared on ASTNode.
269
	 */
270
	int memSize() {
271
		return super.memSize() + 4 * 4;
272
	}
273
	
274
	/* (omit javadoc for this method)
275
	 * Method declared on ASTNode.
276
	 */
277
	int treeSize() {
278
		return
279
			memSize()
280
			+ (type == null ? 0 : getType().treeSize())
281
			+ (variableName == null ? 0 : getName().treeSize())
282
			+ (expression == null ? 0 : getExpression().treeSize())
283
			+ (body == null ? 0 : getBody().treeSize());
284
	}
285
}
(-)dom/org/eclipse/jdt/core/dom/EnumConstantDeclaration.java (+254 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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.Iterator;
15
import java.util.List;
16
17
/**
18
 * Enumeration constant declaration AST node type.
19
 *
20
 * <pre>
21
 * EnumConstantDeclaration:
22
 *      [ Javadoc ] Identifier
23
 *            [ <b>(</b> [ Expression { <b>,</b> Expression } ] <b>)</b> ]
24
 *			  [ <b>{</b> { ClassBodyDeclaration | <b>;</b> } <b>}</b> ]
25
 * </pre>
26
 * <p>
27
 * When a Javadoc comment is present, the source
28
 * range begins with the first character of the "/**" comment delimiter.
29
 * When there is no Javadoc comment, the source range begins with the first
30
 * character of the identifier. If there are class body declarations, the
31
 * source range extends through the last character of the last character of
32
 * the "}" token following the body declarations. If there are arguments but
33
 * no class body declarations, the source range extends through the last
34
 * character of the ")" token following the arguments. If there are no 
35
 * arguments and no class body declarations, the source range extends through
36
 * the last character of the identifier.
37
 * </p>
38
 * <p>
39
 * Note: Enum declarations are an experimental language feature 
40
 * under discussion in JSR-201 and under consideration for inclusion
41
 * in the 1.5 release of J2SE. The support here is therefore tentative
42
 * and subject to change.
43
 * </p>
44
 * 
45
 * @since 2.2
46
 */
47
public class EnumConstantDeclaration extends BodyDeclaration {
48
	
49
	/**
50
	 * The constant name; lazily initialized; defaults to a unspecified,
51
	 * legal Java class identifier.
52
	 */
53
	private SimpleName constantName = null;
54
55
	/**
56
	 * The list of argument expressions (element type: 
57
	 * <code>Expression</code>). Defaults to an empty list.
58
	 */
59
	private ASTNode.NodeList arguments =
60
		new ASTNode.NodeList(true, Expression.class);
61
			
62
	/**
63
	 * The body declarations (element type: <code>BodyDeclaration</code>).
64
	 * Defaults to an empty list.
65
	 */
66
	private ASTNode.NodeList bodyDeclarations = 
67
		new ASTNode.NodeList(true, BodyDeclaration.class);
68
69
	/**
70
	 * Creates a new AST node for an enumeration constants declaration owned by
71
	 * the given AST. By default, the enumeration constant has an unspecified,
72
	 * but legal, name; no javadoc; an empty list of arguments; and an empty
73
	 * list of body declarations.
74
	 * <p>
75
	 * N.B. This constructor is package-private; all subclasses must be 
76
	 * declared in the same package; clients are unable to declare 
77
	 * additional subclasses.
78
	 * </p>
79
	 * 
80
	 * @param ast the AST that is to own this node
81
	 */
82
	EnumConstantDeclaration(AST ast) {
83
		super(ast);
84
	}
85
86
	/* (omit javadoc for this method)
87
	 * Method declared on ASTNode.
88
	 */
89
	public int getNodeType() {
90
		return ENUM_CONSTANT_DECLARATION;
91
	}
92
93
	/* (omit javadoc for this method)
94
	 * Method declared on ASTNode.
95
	 */
96
	ASTNode clone(AST target) {
97
		EnumConstantDeclaration result = new EnumConstantDeclaration(target);
98
		result.setSourceRange(this.getStartPosition(), this.getLength());
99
		result.setJavadoc(
100
			(Javadoc) ASTNode.copySubtree(target,(ASTNode) getJavadoc()));
101
		result.setName((SimpleName) getName().clone(target));
102
		result.arguments().addAll(ASTNode.copySubtrees(target, arguments()));
103
		result.bodyDeclarations().addAll(
104
			ASTNode.copySubtrees(target, bodyDeclarations()));
105
		return result;
106
	}
107
108
	/* (omit javadoc for this method)
109
	 * Method declared on ASTNode.
110
	 */
111
	public boolean subtreeMatch(ASTMatcher matcher, Object other) {
112
		// dispatch to correct overloaded match method
113
		return matcher.match(this, other);
114
	}
115
	
116
	/* (omit javadoc for this method)
117
	 * Method declared on ASTNode.
118
	 */
119
	void accept0(ASTVisitor visitor) {
120
		boolean visitChildren = visitor.visit(this);
121
		if (visitChildren) {
122
			// visit children in normal left to right reading order
123
			acceptChild(visitor, getJavadoc());
124
			acceptChild(visitor, getName());
125
			acceptChildren(visitor, arguments);
126
			acceptChildren(visitor, bodyDeclarations);
127
		}
128
		visitor.endVisit(this);
129
	}
130
	
131
	/**
132
	 * Returns the name of the constant declared in this enum declaration.
133
	 * 
134
	 * @return the constant name node
135
	 */ 
136
	public SimpleName getName() {
137
		if (constantName == null) {
138
			// lazy initialize - use setter to ensure parent link set too
139
			long count = getAST().modificationCount();
140
			setName(new SimpleName(getAST()));
141
			getAST().setModificationCount(count);
142
		}
143
		return constantName;
144
	}
145
		
146
	/**
147
	 * Sets the name of the constant declared in this enum declaration to the
148
	 * given name.
149
	 * 
150
	 * @param constantName the new constant name
151
	 * @exception IllegalArgumentException if:
152
	 * <ul>
153
	 * <li>the node belongs to a different AST</li>
154
	 * <li>the node already has a parent</li>
155
	 * </ul>
156
	 */ 
157
	public void setName(SimpleName constantName) {
158
		if (constantName == null) {
159
			throw new IllegalArgumentException();
160
		}
161
		replaceChild(this.constantName, constantName, false);
162
		this.constantName = constantName;
163
	}
164
165
	/**
166
	 * Returns the live ordered list of argument expressions in this enumeration
167
	 * constant declaration. Note that an empty list of arguments is equivalent
168
	 * to not explicitly specifying arguments.
169
	 * 
170
	 * @return the live list of argument expressions 
171
	 *    (element type: <code>Expression</code>)
172
	 */ 
173
	public List arguments() {
174
		return arguments;
175
	}
176
177
	/**
178
	 * Returns the live ordered list of body declarations of this enumeration
179
	 * constant declaration. Note that an empty list is equivalent to not
180
	 * explicitly specifying any body declarations.
181
	 * 
182
	 * @return the live list of body declarations
183
	 *    (element type: <code>BodyDeclaration</code>)
184
	 */ 
185
	public List bodyDeclarations() {
186
		return bodyDeclarations;
187
	}
188
	
189
	/**
190
	 * Resolves and returns the field binding for this enum constant.
191
	 * <p>
192
	 * Note that bindings are generally unavailable unless requested when the
193
	 * AST is being built.
194
	 * </p>
195
	 * 
196
	 * @return the binding, or <code>null</code> if the binding cannot be 
197
	 *    resolved
198
	 */	
199
	public IVariableBinding resolveVariable() {
200
		return getAST().getBindingResolver().resolveVariable(this);
201
	}
202
	
203
	/* (omit javadoc for this method)
204
	 * Method declared on ASTNode.
205
	 */
206
	void appendDebugString(StringBuffer buffer) {
207
		buffer.append("EnumConstantDeclaration[");//$NON-NLS-1$
208
		buffer.append(getName().getIdentifier());
209
		buffer.append(" ");//$NON-NLS-1$
210
		if (!arguments().isEmpty()) {
211
			buffer.append("(");//$NON-NLS-1$
212
			for (Iterator it = arguments().iterator(); it.hasNext(); ) {
213
				Expression e = (Expression) it.next();
214
				e.appendDebugString(buffer);
215
				if (it.hasNext()) {
216
					buffer.append(",");//$NON-NLS-1$
217
				}
218
			}
219
			buffer.append(")");//$NON-NLS-1$
220
		}
221
		if (!bodyDeclarations().isEmpty()) {
222
			buffer.append(" {");//$NON-NLS-1$
223
			for (Iterator it = bodyDeclarations().iterator(); it.hasNext(); ) {
224
				BodyDeclaration d = (BodyDeclaration) it.next();
225
				d.appendDebugString(buffer);
226
				if (it.hasNext()) {
227
					buffer.append(";");//$NON-NLS-1$
228
				}
229
			}
230
			buffer.append("}");//$NON-NLS-1$
231
		}
232
		buffer.append("]");//$NON-NLS-1$
233
	}
234
		
235
	/* (omit javadoc for this method)
236
	 * Method declared on ASTNode.
237
	 */
238
	int memSize() {
239
		return super.memSize() + 3 * 4;
240
	}
241
	
242
	/* (omit javadoc for this method)
243
	 * Method declared on ASTNode.
244
	 */
245
	int treeSize() {
246
		return
247
			memSize()
248
			+ (getJavadoc() == null ? 0 : getJavadoc().treeSize())
249
			+ (constantName == null ? 0 : getName().treeSize())
250
			+ arguments.listSize()
251
			+ bodyDeclarations.listSize();
252
	}
253
}
254
(-)dom/org/eclipse/jdt/core/dom/ImportDeclaration.java (-8 / +69 lines)
Lines 16-24 Link Here
16
 *
16
 *
17
 * <pre>
17
 * <pre>
18
 * ImportDeclaration:
18
 * ImportDeclaration:
19
 *    <b>import</b> Name [ <b>.</b> <b>*</b> ] <b>;</b>
19
 *    <b>import</b> [ <b>static</b> ] Name [ <b>.</b> <b>*</b> ] <b>;</b>
20
 * </pre>
20
 * </pre>
21
 * 
21
 * 
22
 * <p>
23
 * Note: Static imports are an experimental language feature 
24
 * under discussion in JSR-201 and under consideration for inclusion
25
 * in the 1.5 release of J2SE. The support here is therefore tentative
26
 * and subject to change.
27
 * </p>
22
 * @since 2.0
28
 * @since 2.0
23
 */
29
 */
24
public class ImportDeclaration extends ASTNode {
30
public class ImportDeclaration extends ASTNode {
Lines 34-42 Link Here
34
	private boolean onDemand = false;
40
	private boolean onDemand = false;
35
41
36
	/**
42
	/**
43
	 * Static versus regular; defaults to regular import.
44
	 * <p>
45
	 * Note: Static imports are an experimental language feature 
46
	 * under discussion in JSR-201 and under consideration for inclusion
47
	 * in the 1.5 release of J2SE. The support here is therefore tentative
48
	 * and subject to change.
49
	 * </p>
50
	 * 
51
	 * @since 2.2
52
	 */
53
	private boolean isStatic = false;
54
55
	/**
37
	 * Creates a new AST node for an import declaration owned by the
56
	 * Creates a new AST node for an import declaration owned by the
38
	 * given AST. The import declaration initially is a single type
57
	 * given AST. The import declaration initially is a regular (non-static)
39
	 * import for an unspecified, but legal, Java type name.
58
	 * single type import for an unspecified, but legal, Java type name.
40
	 * <p>
59
	 * <p>
41
	 * N.B. This constructor is package-private; all subclasses must be 
60
	 * N.B. This constructor is package-private; all subclasses must be 
42
	 * declared in the same package; clients are unable to declare 
61
	 * declared in the same package; clients are unable to declare 
Lines 63-68 Link Here
63
		ImportDeclaration result = new ImportDeclaration(target);
82
		ImportDeclaration result = new ImportDeclaration(target);
64
		result.setSourceRange(this.getStartPosition(), this.getLength());
83
		result.setSourceRange(this.getStartPosition(), this.getLength());
65
		result.setOnDemand(isOnDemand());
84
		result.setOnDemand(isOnDemand());
85
		result.setStatic(isStatic());
66
		result.setName((Name) getName().clone(target));
86
		result.setName((Name) getName().clone(target));
67
		return result;
87
		return result;
68
	}
88
	}
Lines 89-96 Link Here
89
	/**
109
	/**
90
	 * Returns the name imported by this declaration.
110
	 * Returns the name imported by this declaration.
91
	 * <p>
111
	 * <p>
92
	 * For an on-demand import, this is the name of a package. For a 
112
	 * For a regular on-demand import, this is the name of a package. 
93
	 * single-type import, this is the qualified name of a type.
113
	 * For a static on-demand import, this is the qualified name of
114
	 * a type. For a regular single-type import, this is the qualified name
115
	 * of a type. For a static single-type import, this is the qualified name
116
	 * of a static member of a type.
94
	 * </p>
117
	 * </p>
95
	 * 
118
	 * 
96
	 * @return the imported name node
119
	 * @return the imported name node
Lines 109-116 Link Here
109
	/**
132
	/**
110
	 * Sets the name of this import declaration to the given name.
133
	 * Sets the name of this import declaration to the given name.
111
	 * <p>
134
	 * <p>
112
	 * For an on-demand import, this is the name of a package. For a 
135
	 * For a regular on-demand import, this is the name of a package. 
113
	 * single-type import, this is the qualified name of a type.
136
	 * For a static on-demand import, this is the qualified name of
137
	 * a type. For a regular single-type import, this is the qualified name
138
	 * of a type. For a static single-type import, this is the qualified name
139
	 * of a static member of a type.
114
	 * </p>
140
	 * </p>
115
	 * 
141
	 * 
116
	 * @param name the new import name
142
	 * @param name the new import name
Lines 152-157 Link Here
152
	}
178
	}
153
	
179
	
154
	/**
180
	/**
181
	 * Returns whether this import declaration is a static import.
182
	 * <p>
183
	 * Note: Static imports are an experimental language feature 
184
	 * under discussion in JSR-201 and under consideration for inclusion
185
	 * in the 1.5 release of J2SE. The support here is therefore tentative
186
	 * and subject to change.
187
	 * </p>
188
	 * 
189
	 * @return <code>true</code> if this is a static import,
190
	 *    and <code>false</code> if this is a regular import
191
	 * @since 2.2
192
	 */ 
193
	public boolean isStatic() {
194
		return isStatic;
195
	}
196
		
197
	/**
198
	 * Sets whether this import declaration is a static import.
199
	 * <p>
200
	 * Note: Static imports are an experimental language feature 
201
	 * under discussion in JSR-201 and under consideration for inclusion
202
	 * in the 1.5 release of J2SE. The support here is therefore tentative
203
	 * and subject to change.
204
	 * </p>
205
	 * 
206
	 * @param isStatic <code>true</code> if this is a static import,
207
	 *    and <code>false</code> if this is a regular import
208
	 * @since 2.2
209
	 */ 
210
	public void setStatic(boolean isStatic) {
211
		modifying();
212
		this.isStatic = isStatic;
213
	}
214
	
215
	/**
155
	 * Resolves and returns the binding for the package or type imported by
216
	 * Resolves and returns the binding for the package or type imported by
156
	 * this import declaration.
217
	 * this import declaration.
157
	 * <p>
218
	 * <p>
Lines 171-177 Link Here
171
	 * Method declared on ASTNode.
232
	 * Method declared on ASTNode.
172
	 */
233
	 */
173
	int memSize() {
234
	int memSize() {
174
		return BASE_NODE_SIZE + 2 * 4;
235
		return BASE_NODE_SIZE + 3 * 4;
175
	}
236
	}
176
	
237
	
177
	/* (omit javadoc for this method)
238
	/* (omit javadoc for this method)
(-)dom/org/eclipse/jdt/core/dom/NaiveASTFlattener.java (+59 lines)
Lines 376-381 Link Here
376
	}
376
	}
377
377
378
	/*
378
	/*
379
	 * @see ASTVisitor#visit(EnhancedForStatement)
380
	 * @since 2.2
381
	 */
382
	public boolean visit(EnhancedForStatement node) {
383
		buffer.append("for (");//$NON-NLS-1$
384
		node.getType().accept(this);
385
		buffer.append(" ");//$NON-NLS-1$
386
		node.getName().accept(this);
387
		buffer.append(" : ");//$NON-NLS-1$
388
		node.getExpression().accept(this);
389
		buffer.append(") ");//$NON-NLS-1$
390
		node.getBody().accept(this);
391
		return false;
392
	}
393
394
	/*
395
	 * @see ASTVisitor#visit(EnumConstantDeclaration)
396
	 * @since 2.2
397
	 */
398
	public boolean visit(EnumConstantDeclaration node) {
399
		node.getName().accept(this);
400
		if (!node.arguments().isEmpty()) {
401
			buffer.append("(");//$NON-NLS-1$
402
			for (Iterator it = node.arguments().iterator(); it.hasNext(); ) {
403
				Expression e = (Expression) it.next();
404
				e.accept(this);
405
				if (it.hasNext()) {
406
					buffer.append(",");//$NON-NLS-1$
407
				}
408
			}
409
			buffer.append(")");//$NON-NLS-1$
410
		}
411
		if (!node.bodyDeclarations().isEmpty()) {
412
			buffer.append("{");//$NON-NLS-1$
413
			for (Iterator it = node.bodyDeclarations().iterator(); it.hasNext(); ) {
414
				BodyDeclaration d = (BodyDeclaration) it.next();
415
				d.accept(this);
416
			}
417
			buffer.append("}");//$NON-NLS-1$
418
		}
419
		return false;
420
	}
421
422
	/*
379
	 * @see ASTVisitor#visit(ExpressionStatement)
423
	 * @see ASTVisitor#visit(ExpressionStatement)
380
	 */
424
	 */
381
	public boolean visit(ExpressionStatement node) {
425
	public boolean visit(ExpressionStatement node) {
Lines 458-463 Link Here
458
	 */
502
	 */
459
	public boolean visit(ImportDeclaration node) {
503
	public boolean visit(ImportDeclaration node) {
460
		buffer.append("import ");//$NON-NLS-1$
504
		buffer.append("import ");//$NON-NLS-1$
505
		if (node.isStatic()) {
506
			buffer.append("static ");//$NON-NLS-1$
507
		}
461
		node.getName().accept(this);
508
		node.getName().accept(this);
462
		if (node.isOnDemand()) {
509
		if (node.isOnDemand()) {
463
			buffer.append(".*");//$NON-NLS-1$
510
			buffer.append(".*");//$NON-NLS-1$
Lines 869-876 Link Here
869
			buffer.append(" ");//$NON-NLS-1$
916
			buffer.append(" ");//$NON-NLS-1$
870
		}
917
		}
871
		buffer.append("{");//$NON-NLS-1$
918
		buffer.append("{");//$NON-NLS-1$
919
		BodyDeclaration prev = null;
872
		for (Iterator it = node.bodyDeclarations().iterator(); it.hasNext(); ) {
920
		for (Iterator it = node.bodyDeclarations().iterator(); it.hasNext(); ) {
873
			BodyDeclaration d = (BodyDeclaration) it.next();
921
			BodyDeclaration d = (BodyDeclaration) it.next();
922
			if (prev instanceof EnumConstantDeclaration) {
923
				// enum constant declarations do not include punctuation
924
				if (d instanceof EnumConstantDeclaration) {
925
					// enum constant declarations are separated by commas
926
					buffer.append(", ");//$NON-NLS-1$
927
				} else {
928
					// semicolon separates last enum constant declaration from 
929
					// first class body declarations
930
					buffer.append("; ");//$NON-NLS-1$
931
				}
932
			}
874
			d.accept(this);
933
			d.accept(this);
875
		}
934
		}
876
		buffer.append("}");//$NON-NLS-1$
935
		buffer.append("}");//$NON-NLS-1$
(-)dom/org/eclipse/jdt/core/dom/SimpleName.java (+13 lines)
Lines 140-145 Link Here
140
	 * providing <code>isConstructor</code> is <code>false</code>.</li>
140
	 * providing <code>isConstructor</code> is <code>false</code>.</li>
141
	 * <li>The variable name in any type of <code>VariableDeclaration</code>
141
	 * <li>The variable name in any type of <code>VariableDeclaration</code>
142
	 * node.</li>
142
	 * node.</li>
143
	 * <li>The enum constant name in an <code>EnumConstantDeclaration</code>
144
	 * node.</li>
145
	 * <li>The variable name in an <code>EnhancedForStatement</code>
146
	 * node.</li>
143
	 * </ul>
147
	 * </ul>
144
	 * <p>
148
	 * <p>
145
	 * Note that this is a convenience method that simply checks whether
149
	 * Note that this is a convenience method that simply checks whether
Lines 173-178 Link Here
173
		if (parent instanceof VariableDeclarationFragment) {
177
		if (parent instanceof VariableDeclarationFragment) {
174
			VariableDeclarationFragment p = (VariableDeclarationFragment) parent;
178
			VariableDeclarationFragment p = (VariableDeclarationFragment) parent;
175
			// make sure its the name of the variable (not the initializer)
179
			// make sure its the name of the variable (not the initializer)
180
			return (p.getName() == this);
181
		}
182
		if (parent instanceof EnumConstantDeclaration) {
183
			// could only be the name of the enum constant
184
			return true;
185
		}
186
		if (parent instanceof EnhancedForStatement) {
187
			EnhancedForStatement p = (EnhancedForStatement) parent;
188
			// make sure its the name of the loop variable (not the initializer)
176
			return (p.getName() == this);
189
			return (p.getName() == this);
177
		}
190
		}
178
		return false;
191
		return false;
(-)dom/org/eclipse/jdt/core/dom/Statement.java (+1 lines)
Lines 25-30 Link Here
25
 *    Block
25
 *    Block
26
 *    IfStatement
26
 *    IfStatement
27
 *    ForStatement
27
 *    ForStatement
28
 *    EnhancedForStatement
28
 *    WhileStatement
29
 *    WhileStatement
29
 *    DoStatement
30
 *    DoStatement
30
 *    TryStatement
31
 *    TryStatement
(-)dom/org/eclipse/jdt/core/dom/TypeDeclaration.java (-28 / +144 lines)
Lines 22-27 Link Here
22
 * TypeDeclaration:
22
 * TypeDeclaration:
23
 * 		ClassDeclaration
23
 * 		ClassDeclaration
24
 * 		InterfaceDeclaration
24
 * 		InterfaceDeclaration
25
 * 		EnumDeclaration
25
 * ClassDeclaration:
26
 * ClassDeclaration:
26
 *      [ Javadoc ] { Modifier } <b>class</b> Identifier
27
 *      [ Javadoc ] { Modifier } <b>class</b> Identifier
27
 *			[ <b>extends</b> Type]
28
 *			[ <b>extends</b> Type]
Lines 31-46 Link Here
31
 *      [ Javadoc ] { Modifier } <b>interface</b> Identifier
32
 *      [ Javadoc ] { Modifier } <b>interface</b> Identifier
32
 *			[ <b>extends</b> Type { <b>,</b> Type } ]
33
 *			[ <b>extends</b> Type { <b>,</b> Type } ]
33
 * 			<b>{</b> { InterfaceBodyDeclaration | <b>;</b> } <b>}</b>
34
 * 			<b>{</b> { InterfaceBodyDeclaration | <b>;</b> } <b>}</b>
35
 * EnumDeclaration:
36
 *      [ Javadoc ] { Modifier } <b>enum</b> Identifier
37
 *			[ <b>implements</b> Type { <b>,</b> Type } ]
38
 *			<b>{</b>
39
 *               [ EnumConstantDeclaration [ <b>,</b> EnumConstantDeclaration ] ]
40
 *               [ <b>;</b> { ClassBodyDeclaration | <b>;</b> } ]
41
 *          <b>}</b>
34
 * </pre>
42
 * </pre>
35
 * <p>
43
 * <p>
36
 * When a Javadoc comment is present, the source
44
 * When a Javadoc comment is present, the source
37
 * range begins with the first character of the "/**" comment delimiter.
45
 * range begins with the first character of the "/**" comment delimiter.
38
 * When there is no Javadoc comment, the source range begins with the first
46
 * When there is no Javadoc comment, the source range begins with the first
39
 * character of the first modifier keyword (if modifiers), or the
47
 * character of the first modifier keyword (if modifiers), or the
40
 * first character of the "class" or "interface": keyword (if no modifiers).
48
 * first character of the "class", "interface", or "enum" keyword (if no
41
 * The source range extends through the last character of the ";" token (if
49
 * modifiers). The source range extends through the last character of the "}"
42
 * no body), or the last character of the "}" token following the body
50
 * token following the body declarations.
43
 * declarations.
51
 * </p>
52
 * <p>
53
 * Note: Enum declarations are an experimental language feature 
54
 * under discussion in JSR-201 and under consideration for inclusion
55
 * in the 1.5 release of J2SE. The support here is therefore tentative
56
 * and subject to change.
44
 * </p>
57
 * </p>
45
 * 
58
 * 
46
 * @since 2.0
59
 * @since 2.0
Lines 62-67 Link Here
62
	private boolean isInterface = false;
75
	private boolean isInterface = false;
63
	
76
	
64
	/**
77
	/**
78
	 * <code>true</code> for an enumeration, <code>false</code> for a class.
79
	 * Defaults to class. This field is ignored for interfaces.
80
	 * <p>
81
	 * Note: Enum declarations are an experimental language feature 
82
	 * under discussion in JSR-201 and under consideration for inclusion
83
	 * in the 1.5 release of J2SE. The support here is therefore tentative
84
	 * and subject to change.
85
	 * </p>
86
	 * 
87
	 * @since 2.2
88
	 */
89
	private boolean isEnumeration = false;
90
	
91
	/**
65
	 * The modifiers; bit-wise or of Modifier flags.
92
	 * The modifiers; bit-wise or of Modifier flags.
66
	 * Defaults to none.
93
	 * Defaults to none.
67
	 */
94
	 */
Lines 129-134 Link Here
129
		result.setJavadoc(
156
		result.setJavadoc(
130
			(Javadoc) ASTNode.copySubtree(target,(ASTNode) getJavadoc()));
157
			(Javadoc) ASTNode.copySubtree(target,(ASTNode) getJavadoc()));
131
		result.setInterface(isInterface());
158
		result.setInterface(isInterface());
159
		result.setEnumeration(isEnumeration());
132
		result.setName((SimpleName) getName().clone(target));
160
		result.setName((SimpleName) getName().clone(target));
133
		result.setSuperclass(
161
		result.setSuperclass(
134
			(Name) ASTNode.copySubtree(target,(ASTNode) getSuperclass()));
162
			(Name) ASTNode.copySubtree(target,(ASTNode) getSuperclass()));
Lines 168-174 Link Here
168
	 * interface.
196
	 * interface.
169
	 * 
197
	 * 
170
	 * @return <code>true</code> if this is an interface declaration,
198
	 * @return <code>true</code> if this is an interface declaration,
171
	 *    and <code>false</code> if this is a class declaration
199
	 *    and <code>false</code> if this is a class or enumeration declaration
172
	 */ 
200
	 */ 
173
	public boolean isInterface() {
201
	public boolean isInterface() {
174
		return isInterface;
202
		return isInterface;
Lines 179-185 Link Here
179
	 * interface.
207
	 * interface.
180
	 * 
208
	 * 
181
	 * @param isInterface <code>true</code> if this is an interface
209
	 * @param isInterface <code>true</code> if this is an interface
182
	 *    declaration, and <code>false</code> if this is a class
210
	 *    declaration, and <code>false</code> if this is a class or enumeration
183
	 * 	  declaration
211
	 * 	  declaration
184
	 */ 
212
	 */ 
185
	public void setInterface(boolean isInterface) {
213
	public void setInterface(boolean isInterface) {
Lines 188-193 Link Here
188
	}
216
	}
189
217
190
	/**
218
	/**
219
	 * Returns whether this type declaration declares a class or an 
220
	 * enumeration. Note that this property is not relevant for interfaces.
221
	 * <p>
222
	 * Note: Enum declarations are an experimental language feature 
223
	 * under discussion in JSR-201 and under consideration for inclusion
224
	 * in the 1.5 release of J2SE. The support here is therefore tentative
225
	 * and subject to change.
226
	 * </p>
227
	 * 
228
	 * @return <code>true</code> if this is an enumeration declaration,
229
	 *    and <code>false</code> if this is a class declaration
230
	 * @since 2.2
231
	 */ 
232
	public boolean isEnumeration() {
233
		return isEnumeration;
234
	}
235
	
236
	/**
237
	 * Sets whether this type declaration declares a class or an 
238
	 * enumeration. Note that this property is not relevant for interfaces.
239
	 * <p>
240
	 * Note: Enum declarations are an experimental language feature 
241
	 * under discussion in JSR-201 and under consideration for inclusion
242
	 * in the 1.5 release of J2SE. The support here is therefore tentative
243
	 * and subject to change.
244
	 * </p>
245
	 * 
246
	 * @param isEnumeration <code>true</code> if this is an enumeration
247
	 *    declaration, and <code>false</code> if this is a class
248
	 * 	  declaration
249
	 * @since 2.2
250
	 */ 
251
	public void setEnumeration(boolean isEnumeration) {
252
		modifying();
253
		this.isEnumeration = isEnumeration;
254
	}
255
256
	/**
191
	 * Returns the modifiers explicitly specified on this declaration.
257
	 * Returns the modifiers explicitly specified on this declaration.
192
	 * <p>
258
	 * <p>
193
	 * Note that deprecated is not included.
259
	 * Note that deprecated is not included.
Lines 266-273 Link Here
266
	 * Returns the name of the superclass declared in this type
332
	 * Returns the name of the superclass declared in this type
267
	 * declaration, or <code>null</code> if there is none.
333
	 * declaration, or <code>null</code> if there is none.
268
	 * <p>
334
	 * <p>
269
	 * Note that this child is not relevant for interface declarations
335
	 * Note that this child is not relevant for interface and
270
	 * (although it does still figure in subtree equality comparisons).
336
	 * enumeration declarations (although it does still figure in subtree
337
	 * equality comparisons).
271
	 * </p>
338
	 * </p>
272
	 * 
339
	 * 
273
	 * @return the superclass name node, or <code>null</code> if 
340
	 * @return the superclass name node, or <code>null</code> if 
Lines 281-288 Link Here
281
	 * Sets or clears the name of the superclass declared in this type
348
	 * Sets or clears the name of the superclass declared in this type
282
	 * declaration.
349
	 * declaration.
283
	 * <p>
350
	 * <p>
284
	 * Note that this child is not relevant for interface declarations
351
	 * Note that this child is not relevant for interface and
285
	 * (although it does still figure in subtree equality comparisons).
352
	 * enumeration declarations (although it does still figure in subtree
353
	 * equality comparisons).
286
	 * </p>
354
	 * </p>
287
	 * 
355
	 * 
288
	 * @param superclassName the superclass name node, or <code>null</code> if 
356
	 * @param superclassName the superclass name node, or <code>null</code> if 
Lines 302-310 Link Here
302
370
303
	/**
371
	/**
304
	 * Returns the live ordered list of names of superinterfaces of this type 
372
	 * Returns the live ordered list of names of superinterfaces of this type 
305
	 * declaration. For a class declaration, these are the names of the
373
	 * declaration. For a class or enumeration declaration, these are the names
306
	 * interfaces that this class implements; for an interface declaration,
374
	 * of the interfaces that this class implements; for an interface
307
	 * these are the names of the interfaces that this interface extends.
375
	 * declaration, these are the names of the interfaces that this interface
376
	 * extends.
308
	 * 
377
	 * 
309
	 * @return the live list of interface names
378
	 * @return the live list of interface names
310
	 *    (element type: <code>Name</code>)
379
	 *    (element type: <code>Name</code>)
Lines 317-324 Link Here
317
	 * Returns the live ordered list of body declarations of this type 
386
	 * Returns the live ordered list of body declarations of this type 
318
	 * declaration. For a class declaration, these are the
387
	 * declaration. For a class declaration, these are the
319
	 * initializer, field, method, constructor, and member type
388
	 * initializer, field, method, constructor, and member type
320
	 * declarations; for an interface declaration, these are 
389
	 * declarations; for an interface declaration, these are the constant,
321
	 * the constant, method, and member type declarations.
390
	 * method, and member type declarations. For an enumeration declaration, 
391
	 * these are the enum constant declarations, which are always at the 
392
	 * front of the list, followed by any initializer, field, method,
393
	 * constructor, and member type declarations.
322
	 * 
394
	 * 
323
	 * @return the live list of body declarations
395
	 * @return the live list of body declarations
324
	 *    (element type: <code>BodyDeclaration</code>)
396
	 *    (element type: <code>BodyDeclaration</code>)
Lines 331-337 Link Here
331
	 * Returns the ordered list of field declarations of this type 
403
	 * Returns the ordered list of field declarations of this type 
332
	 * declaration. For a class declaration, these are the
404
	 * declaration. For a class declaration, these are the
333
	 * field declarations; for an interface declaration, these are
405
	 * field declarations; for an interface declaration, these are
334
	 * the constant declarations.
406
	 * the constant declarations; for an enum declaration, these are
407
	 * the explicitly declared field declarations (excludes enum
408
	 * constant declarations).
335
	 * <p>
409
	 * <p>
336
	 * This convenience method returns this node's body declarations
410
	 * This convenience method returns this node's body declarations
337
	 * with non-fields filtered out. Unlike <code>bodyDeclarations</code>,
411
	 * with non-fields filtered out. Unlike <code>bodyDeclarations</code>,
Lines 421-426 Link Here
421
	}
495
	}
422
496
423
	/**
497
	/**
498
	 * Returns the ordered list of enum constant declarations of this enum
499
	 * declaration. This method is not relevant for class and interface 
500
	 * declarations, for which enum constant declarations are meaningless.
501
	 * <p>
502
	 * This convenience method returns this node's enum constant declarations
503
	 * with non-enum constants filtered out. Unlike <code>bodyDeclarations</code>,
504
	 * this method does not return a live result.
505
	 * </p>
506
	 * <p>
507
	 * Note: Enum declarations are an experimental language feature 
508
	 * under discussion in JSR-201 and under consideration for inclusion
509
	 * in the 1.5 release of J2SE. The support here is therefore tentative
510
	 * and subject to change.
511
	 * </p>
512
	 * 
513
	 * @return the (possibly empty) list of enum constant declarations
514
	 * @since 2.2
515
	 */ 
516
	public EnumConstantDeclaration[] getEnumConstants() {
517
		List bd = bodyDeclarations();
518
		int enumCount = 0;
519
		for (Iterator it = bd.listIterator(); it.hasNext(); ) {
520
			if (it.next() instanceof EnumConstantDeclaration) {
521
				enumCount++;
522
			}
523
		}
524
		EnumConstantDeclaration[] enumConstants = new EnumConstantDeclaration[enumCount];
525
		int next = 0;
526
		for (Iterator it = bd.listIterator(); it.hasNext(); ) {
527
			Object decl = it.next();
528
			if (decl instanceof EnumConstantDeclaration) {
529
				enumConstants[next++] = (EnumConstantDeclaration) decl;
530
			}
531
		}
532
		return enumConstants;
533
	}
534
535
	/**
424
	 * Returns whether this type declaration is a package member (that is,
536
	 * Returns whether this type declaration is a package member (that is,
425
	 * a top-level type).
537
	 * a top-level type).
426
	 * <p>
538
	 * <p>
Lines 440-457 Link Here
440
	 * Returns whether this type declaration is a type member.
552
	 * Returns whether this type declaration is a type member.
441
	 * <p>
553
	 * <p>
442
	 * Note that this is a convenience method that simply checks whether
554
	 * Note that this is a convenience method that simply checks whether
443
	 * this node's parent is a type declaration node or an anonymous 
555
	 * this node's parent is a type declaration node, an anonymous 
444
	 * class declaration.
556
	 * class declaration, or an enumeration constant declaration.
445
	 * </p>
557
	 * </p>
446
	 * 
558
	 * 
447
	 * @return <code>true</code> if this type declaration is a child of
559
	 * @return <code>true</code> if this type declaration is a child of
448
	 *   a type declaration node or a class instance creation node, and 
560
	 *   a type declaration node, a class instance creation node, or an
449
	 *   <code>false</code> otherwise
561
	 *   enum constant declaration, and <code>false</code> otherwise
450
	 */ 
562
	 */ 
451
	public boolean isMemberTypeDeclaration() {
563
	public boolean isMemberTypeDeclaration() {
452
		ASTNode parent = getParent();
564
		ASTNode parent = getParent();
453
		return (parent instanceof TypeDeclaration)
565
		return (parent instanceof TypeDeclaration)
454
			|| (parent instanceof AnonymousClassDeclaration);
566
			|| (parent instanceof AnonymousClassDeclaration)
567
			|| (parent instanceof EnumConstantDeclaration);
455
	}
568
	}
456
569
457
	/**
570
	/**
Lines 488-512 Link Here
488
	 * Method declared on ASTNode.
601
	 * Method declared on ASTNode.
489
	 */
602
	 */
490
	void appendDebugString(StringBuffer buffer) {
603
	void appendDebugString(StringBuffer buffer) {
491
		buffer.append("TypeDeclaration[");//$NON-NLS-1$
604
		buffer.append("TypeDeclaration["); //$NON-NLS-1$
492
		buffer.append(isInterface() ? "interface " : "class ");//$NON-NLS-2$//$NON-NLS-1$
605
		buffer.append(isInterface()
606
		   ? "interface " //$NON-NLS-1$
607
		   : (isEnumeration()
608
		        ? "enum " : "class ")); //$NON-NLS-2$//$NON-NLS-1$
493
		buffer.append(getName().getIdentifier());
609
		buffer.append(getName().getIdentifier());
494
		buffer.append(" ");//$NON-NLS-1$
610
		buffer.append(" "); //$NON-NLS-1$
495
		for (Iterator it = bodyDeclarations().iterator(); it.hasNext(); ) {
611
		for (Iterator it = bodyDeclarations().iterator(); it.hasNext();) {
496
			BodyDeclaration d = (BodyDeclaration) it.next();
612
			BodyDeclaration d = (BodyDeclaration) it.next();
497
			d.appendDebugString(buffer);
613
			d.appendDebugString(buffer);
498
			if (it.hasNext()) {
614
			if (it.hasNext()) {
499
				buffer.append(";");//$NON-NLS-1$
615
				buffer.append(";"); //$NON-NLS-1$
500
			}
616
			}
501
		}
617
		}
502
		buffer.append("]");//$NON-NLS-1$
618
		buffer.append("]"); //$NON-NLS-1$
503
	}
619
	}
504
		
620
		
505
	/* (omit javadoc for this method)
621
	/* (omit javadoc for this method)
506
	 * Method declared on ASTNode.
622
	 * Method declared on ASTNode.
507
	 */
623
	 */
508
	int memSize() {
624
	int memSize() {
509
		return super.memSize() + 6 * 4;
625
		return super.memSize() + 7 * 4;
510
	}
626
	}
511
	
627
	
512
	/* (omit javadoc for this method)
628
	/* (omit javadoc for this method)

Return to bug 36144