Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 4577 Details for
Bug 36144
[DOM/AST] DOM support for JSR-201 language changes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
DOM/AST API experimental support for JSR-201
ast-JSR-201-patch-20030408.txt (text/plain), 53.67 KB, created by
Jim des Rivieres
on 2003-04-14 13:21:00 EDT
(
hide
)
Description:
DOM/AST API experimental support for JSR-201
Filename:
MIME Type:
Creator:
Jim des Rivieres
Created:
2003-04-14 13:21:00 EDT
Size:
53.67 KB
patch
obsolete
>Index: dom/org/eclipse/jdt/core/dom/AST.java >=================================================================== >RCS file: /data/cvs/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/AST.java,v >retrieving revision 1.49 >diff -u -r1.49 AST.java >--- dom/org/eclipse/jdt/core/dom/AST.java 4 Apr 2003 19:58:13 -0000 1.49 >+++ dom/org/eclipse/jdt/core/dom/AST.java 8 Apr 2003 16:52:16 -0000 >@@ -812,7 +812,7 @@ > > /** > * Creates an unparented import declaration node owned by this AST. >- * The import declaration initially contains a single-type import >+ * The import declaration initially contains a regular single-type import > * of a type with an unspecified name. > * > * @return the new unparented import declaration node >@@ -834,7 +834,11 @@ > * and an empty class body. > * <p> > * To create an interface, use this method and then call >- * <code>TypeDeclaration.setInterface(true)</code> and >+ * <code>TypeDeclaration.setInterface(true)</code>. >+ * </p> >+ * <p> >+ * To create an enum declaration, use this method and then call >+ * <code>TypeDeclaration.setEnumeration(true)</code>. > * </p> > * > * @return a new unparented type declaration node >@@ -903,6 +907,18 @@ > } > > /** >+ * Creates an unparented enum constant declaration node owned by this AST. >+ * The name of the constant is an unspecified, but legal, name; >+ * no Javadoc comment; an empty list of arguments; and an empty class body. >+ * >+ * @return a new unparented edeclaration node >+ */ >+ public EnumConstantDeclaration newEnumConstantDeclaration() { >+ EnumConstantDeclaration result = new EnumConstantDeclaration(this); >+ return result; >+ } >+ >+ /** > * Creates and returns a new Javadoc comment node. > * Initially the new node has an unspecified, but legal, Javadoc comment. > * >@@ -1169,10 +1185,28 @@ > * By default, there are no initializers, no condition expression, > * no updaters, and the body is an empty block. > * >- * @return a new unparented throw statement node >+ * @return a new unparented for statement node > */ > public ForStatement newForStatement() { > return new ForStatement(this); >+ } >+ >+ /** >+ * Creates a new unparented enhanced for statement node owned by this AST. >+ * By default, the type, name, and expression are unspecified >+ * but legal subtrees, and the body is an empty block. >+ * <p> >+ * Note: Enhanced for statements are an experimental language feature >+ * under discussion in JSR-201 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * </p> >+ * >+ * @return a new unparented throw statement node >+ * @since 2.2 >+ */ >+ public EnhancedForStatement newEnhancedForStatement() { >+ return new EnhancedForStatement(this); > } > > //=============================== EXPRESSIONS =========================== >Index: dom/org/eclipse/jdt/core/dom/ASTMatcher.java >=================================================================== >RCS file: /data/cvs/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTMatcher.java,v >retrieving revision 1.13 >diff -u -r1.13 ASTMatcher.java >--- dom/org/eclipse/jdt/core/dom/ASTMatcher.java 11 Mar 2003 15:03:51 -0000 1.13 >+++ dom/org/eclipse/jdt/core/dom/ASTMatcher.java 8 Apr 2003 16:52:18 -0000 >@@ -608,6 +608,74 @@ > * other object is a node of the same type with structurally isomorphic > * child subtrees. Subclasses may override this method as needed. > * </p> >+ * <p> >+ * Note: Enhanced for statements are an experimental language feature >+ * under discussion in JSR-201 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * </p> >+ * >+ * @param node the node >+ * @param other the other object, or <code>null</code> >+ * @return <code>true</code> if the subtree matches, or >+ * <code>false</code> if they do not match or the other object has a >+ * different node type or is <code>null</code> >+ * @since 2.2 >+ */ >+ public boolean match(EnhancedForStatement node, Object other) { >+ if (!(other instanceof EnhancedForStatement)) { >+ return false; >+ } >+ EnhancedForStatement o = (EnhancedForStatement) other; >+ return ( >+ safeSubtreeMatch(node.getType(), o.getType()) >+ && safeSubtreeMatch(node.getName(), o.getName()) >+ && safeSubtreeMatch(node.getExpression(), o.getExpression()) >+ && safeSubtreeMatch(node.getBody(), o.getBody())); >+ } >+ >+ /** >+ * Returns whether the given node and the other object match. >+ * <p> >+ * The default implementation provided by this class tests whether the >+ * other object is a node of the same type with structurally isomorphic >+ * child subtrees. Subclasses may override this method as needed. >+ * </p> >+ * <p> >+ * Note: Enum declarations are an experimental language feature >+ * under discussion in JSR-201 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * </p> >+ * >+ * @param node the node >+ * @param other the other object, or <code>null</code> >+ * @return <code>true</code> if the subtree matches, or >+ * <code>false</code> if they do not match or the other object has a >+ * different node type or is <code>null</code> >+ * @since 2.2 >+ */ >+ public boolean match(EnumConstantDeclaration node, Object other) { >+ if (!(other instanceof EnumConstantDeclaration)) { >+ return false; >+ } >+ EnumConstantDeclaration o = (EnumConstantDeclaration) other; >+ return ( >+ safeSubtreeMatch(node.getJavadoc(), o.getJavadoc()) >+ && safeSubtreeMatch(node.getName(), o.getName()) >+ && safeSubtreeListMatch(node.arguments(), o.arguments()) >+ && safeSubtreeListMatch( >+ node.bodyDeclarations(), >+ o.bodyDeclarations())); >+ } >+ >+ /** >+ * Returns whether the given node and the other object match. >+ * <p> >+ * The default implementation provided by this class tests whether the >+ * other object is a node of the same type with structurally isomorphic >+ * child subtrees. Subclasses may override this method as needed. >+ * </p> > * > * @param node the node > * @param other the other object, or <code>null</code> >@@ -744,7 +812,8 @@ > ImportDeclaration o = (ImportDeclaration) other; > return ( > safeSubtreeMatch(node.getName(), o.getName()) >- && node.isOnDemand() == o.isOnDemand()); >+ && node.isOnDemand() == o.isOnDemand() >+ && node.isStatic() == o.isStatic()); > } > > /** >@@ -1475,6 +1544,7 @@ > return ( > (node.getModifiers() == o.getModifiers()) > && (node.isInterface() == o.isInterface()) >+ && (node.isEnumeration() == o.isEnumeration()) > && safeSubtreeMatch(node.getJavadoc(), o.getJavadoc()) > && safeSubtreeMatch(node.getName(), o.getName()) > && safeSubtreeMatch(node.getSuperclass(), o.getSuperclass()) >Index: dom/org/eclipse/jdt/core/dom/ASTNode.java >=================================================================== >RCS file: /data/cvs/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTNode.java,v >retrieving revision 1.28 >diff -u -r1.28 ASTNode.java >--- dom/org/eclipse/jdt/core/dom/ASTNode.java 11 Mar 2003 15:03:51 -0000 1.28 >+++ dom/org/eclipse/jdt/core/dom/ASTNode.java 8 Apr 2003 16:52:20 -0000 >@@ -549,6 +549,34 @@ > public static final int INSTANCEOF_EXPRESSION = 62; > > /** >+ * Node type constant indicating a node of type >+ * <code>EnhancedForStatement</code>. >+ * <p> >+ * Note: Enhanced for statements are an experimental language feature >+ * under discussion in JSR-201 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * </p> >+ * @see EnhancedForStatement >+ * @since 2.2 >+ */ >+ public static final int ENHANCED_FOR_STATEMENT = 63; >+ >+ /** >+ * Node type constant indicating a node of type >+ * <code>EnumConstantDeclaration</code>. >+ * <p> >+ * Note: Enum declarations are an experimental language feature >+ * under discussion in JSR-201 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * </p> >+ * @see EnumConstantDeclaration >+ * @since 2.2 >+ */ >+ public static final int ENUM_CONSTANT_DECLARATION = 64; >+ >+ /** > * Owning AST. > */ > private final AST owner; >Index: dom/org/eclipse/jdt/core/dom/ASTVisitor.java >=================================================================== >RCS file: /data/cvs/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTVisitor.java,v >retrieving revision 1.9 >diff -u -r1.9 ASTVisitor.java >--- dom/org/eclipse/jdt/core/dom/ASTVisitor.java 11 Mar 2003 15:03:51 -0000 1.9 >+++ dom/org/eclipse/jdt/core/dom/ASTVisitor.java 8 Apr 2003 16:52:21 -0000 >@@ -181,6 +181,32 @@ > public boolean visit(EmptyStatement node) { > return true; > } >+ /** Visits the given node. >+ * <p> >+ * Note: Enhanced for statements are an experimental language feature >+ * under discussion in JSR-201 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * </p> >+ * >+ * @since 2.2 >+ */ >+ public boolean visit(EnhancedForStatement node) { >+ return true; >+ } >+ /** Visits the given node. >+ * <p> >+ * Note: Enum declarations are an experimental language feature >+ * under discussion in JSR-201 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * </p> >+ * >+ * @since 2.2 >+ */ >+ public boolean visit(EnumConstantDeclaration node) { >+ return true; >+ } > public boolean visit(ExpressionStatement node) { > return true; > } >@@ -347,6 +373,30 @@ > public void endVisit(DoStatement node) { > } > public void endVisit(EmptyStatement node) { >+ } >+ /** End of visit of the given node. >+ * <p> >+ * Note: Enhanced for statements are an experimental language feature >+ * under discussion in JSR-201 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * </p> >+ * >+ * @since 2.2 >+ */ >+ public void endVisit(EnhancedForStatement node) { >+ } >+ /** End of visit of the given node. >+ * <p> >+ * Note: Enum declarations are an experimental language feature >+ * under discussion in JSR-201 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * </p> >+ * >+ * @since 2.2 >+ */ >+ public void endVisit(EnumConstantDeclaration node) { > } > public void endVisit(ExpressionStatement node) { > } >Index: dom/org/eclipse/jdt/core/dom/BindingResolver.java >=================================================================== >RCS file: /data/cvs/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/BindingResolver.java,v >retrieving revision 1.18 >diff -u -r1.18 BindingResolver.java >--- dom/org/eclipse/jdt/core/dom/BindingResolver.java 4 Apr 2003 22:10:19 -0000 1.18 >+++ dom/org/eclipse/jdt/core/dom/BindingResolver.java 8 Apr 2003 16:52:21 -0000 >@@ -246,6 +246,29 @@ > IVariableBinding resolveVariable(VariableDeclaration variable) { > return null; > } >+ >+ /** >+ * Resolves the loop variable of the given enhanced for statement and >+ * returns the binding for it. >+ * <p> >+ * The default implementation of this method returns <code>null</code>. >+ * Subclasses may reimplement. >+ * </p> >+ * <p> >+ * Note: Enhanced for statements are an experimental language feature >+ * under discussion in JSR-201 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * </p> >+ * >+ * @param statement the enhanced for statement of interest >+ * @return the binding for the loop variable for the given enhanced for >+ * statement, or <code>null</code> if no binding is available >+ * @since 2.2 >+ */ >+ IVariableBinding resolveVariable(EnhancedForStatement statement) { >+ return null; >+ } > > /** > * Resolves the given field declaration and returns the binding for it. >@@ -265,6 +288,33 @@ > * <code>null</code> if no binding is available > */ > IVariableBinding resolveVariable(FieldDeclaration variable) { >+ return null; >+ } >+ >+ /** >+ * Resolves the given enum constant declaration and returns the binding for >+ * the field. >+ * <p> >+ * The implementation of <code>EnumConstantDeclaration.resolveVariable</code> >+ * forwards to this method. >+ * </p> >+ * <p> >+ * The default implementation of this method returns <code>null</code>. >+ * Subclasses may reimplement. >+ * </p> >+ * <p> >+ * Note: Enum declarations are an experimental language feature >+ * under discussion in JSR-201 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * </p> >+ * >+ * @param enumConstant the enum constant declaration of interest >+ * @return the field binding for the given enum constant declaration, or >+ * <code>null</code> if no binding is available >+ * @since 2.2 >+ */ >+ IVariableBinding resolveVariable(EnumConstantDeclaration enumConstant) { > return null; > } > >Index: dom/org/eclipse/jdt/core/dom/BodyDeclaration.java >=================================================================== >RCS file: /data/cvs/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/BodyDeclaration.java,v >retrieving revision 1.5 >diff -u -r1.5 BodyDeclaration.java >--- dom/org/eclipse/jdt/core/dom/BodyDeclaration.java 11 Mar 2003 15:03:51 -0000 1.5 >+++ dom/org/eclipse/jdt/core/dom/BodyDeclaration.java 8 Apr 2003 16:52:21 -0000 >@@ -13,21 +13,21 @@ > > /** > * Abstract base class of all AST nodes that represent body declarations >- * that may appear in the body of a class or interface declaration. >+ * that may appear in the body of some kind of class or interface declaration, >+ * including anonymous class declarations, enumeration declarations, and >+ * enumeration constant declarations. >+ * > * <p> > * <pre> >- * ClassBodyDeclaration: >+ * BodyDeclaration: > * ClassDeclaration > * InterfaceDeclaration >+ * EnumDeclaration > * MethodDeclaration > * ConstructorDeclaration > * FieldDeclaration > * Initializer >- * InterfaceBodyDeclaration: >- * ClassDeclaration >- * InterfaceDeclaration >- * MethodDeclaration >- * FieldDeclaration >+ * EnumConstantDeclaration > * </pre> > * </p> > * <p> >Index: dom/org/eclipse/jdt/core/dom/EnhancedForStatement.java >=================================================================== >RCS file: dom/org/eclipse/jdt/core/dom/EnhancedForStatement.java >diff -N dom/org/eclipse/jdt/core/dom/EnhancedForStatement.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ dom/org/eclipse/jdt/core/dom/EnhancedForStatement.java 8 Apr 2003 16:52:22 -0000 >@@ -0,0 +1,285 @@ >+/******************************************************************************* >+ * Copyright (c) 2000, 2003 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Common Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/cpl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.jdt.core.dom; >+ >+/** >+ * Enhanced For statement AST node type. >+ * >+ * <pre> >+ * EnhancedForStatement: >+ * <b>for</b> <b>(</b> Type Identifier<b>:</b> Expression <b>)</b> >+ * Statement >+ * </pre> >+ * >+ * <p> >+ * Note: Enhanced for statements are an experimental language feature >+ * under discussion in JSR-201 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * </p> >+ * @since 2.2 >+ */ >+public class EnhancedForStatement extends Statement { >+ >+ /** >+ * The type; lazily initialized; defaults to a unspecified, >+ * legal type. >+ */ >+ private Type type = null; >+ >+ /** >+ * The variable name; lazily initialized; defaults to an unspecified, >+ * legal Java identifier. >+ */ >+ private SimpleName variableName = null; >+ >+ /** >+ * The expression; lazily initialized; defaults to a unspecified, but legal, >+ * expression. >+ */ >+ private Expression expression = null; >+ >+ /** >+ * The body statement; lazily initialized; defaults to an empty block >+ * statement. >+ */ >+ private Statement body = null; >+ >+ /** >+ * Creates a new AST node for an enchanced for statement owned by the >+ * given AST. By default, the type, name, and expression are unspecified >+ * but legal subtrees, and the body is an empty block. >+ * >+ * @param ast the AST that is to own this node >+ */ >+ EnhancedForStatement(AST ast) { >+ super(ast); >+ } >+ >+ /* (omit javadoc for this method) >+ * Method declared on ASTNode. >+ */ >+ public int getNodeType() { >+ return ENHANCED_FOR_STATEMENT; >+ } >+ >+ /* (omit javadoc for this method) >+ * Method declared on ASTNode. >+ */ >+ ASTNode clone(AST target) { >+ EnhancedForStatement result = new EnhancedForStatement(target); >+ result.setSourceRange(this.getStartPosition(), this.getLength()); >+ result.copyLeadingComment(this); >+ result.setType((Type) getType().clone(target)); >+ result.setName((SimpleName) getName().clone(target)); >+ result.setExpression((Expression) getExpression().clone(target)); >+ result.setBody( >+ (Statement) ASTNode.copySubtree(target, getBody())); >+ return result; >+ } >+ >+ /* (omit javadoc for this method) >+ * Method declared on ASTNode. >+ */ >+ public boolean subtreeMatch(ASTMatcher matcher, Object other) { >+ // dispatch to correct overloaded match method >+ return matcher.match(this, other); >+ } >+ >+ /* (omit javadoc for this method) >+ * Method declared on ASTNode. >+ */ >+ void accept0(ASTVisitor visitor) { >+ boolean visitChildren = visitor.visit(this); >+ if (visitChildren) { >+ // visit children in normal left to right reading order >+ acceptChild(visitor, getType()); >+ acceptChild(visitor, getName()); >+ acceptChild(visitor, getExpression()); >+ acceptChild(visitor, getBody()); >+ } >+ visitor.endVisit(this); >+ } >+ >+ /** >+ * Returns the type in this enhanced for statement. >+ * >+ * @return the type >+ */ >+ public Type getType() { >+ if (type == null) { >+ // lazy initialize - use setter to ensure parent link set too >+ long count = getAST().modificationCount(); >+ setType(getAST().newPrimitiveType(PrimitiveType.INT)); >+ getAST().setModificationCount(count); >+ } >+ return type; >+ } >+ >+ /** >+ * Sets the type in this enhanced for statement to the given type. >+ * >+ * @param type the new type >+ * @exception IllegalArgumentException if: >+ * <ul> >+ * <li>the node belongs to a different AST</li> >+ * <li>the node already has a parent</li> >+ * </ul> >+ */ >+ public void setType(Type type) { >+ if (type == null) { >+ throw new IllegalArgumentException(); >+ } >+ // an EnchacedForStatement cannot occur inside a Type - cycles not possible >+ replaceChild(this.type, type, false); >+ this.type = type; >+ } >+ >+ /** >+ * Returns the name of the variable in this enhanced for statement. >+ * >+ * @return the variable name node >+ */ >+ public SimpleName getName() { >+ if (variableName == null) { >+ // lazy initialize - use setter to ensure parent link set too >+ long count = getAST().modificationCount(); >+ setName(new SimpleName(getAST())); >+ getAST().setModificationCount(count); >+ } >+ return variableName; >+ } >+ >+ /** >+ * Sets the name of the variable in this enhanced for statement >+ * to the given name. >+ * >+ * @param variableName the new variable name >+ * @exception IllegalArgumentException if: >+ * <ul> >+ * <li>the node belongs to a different AST</li> >+ * <li>the node already has a parent</li> >+ * </ul> >+ */ >+ public void setName(SimpleName variableName) { >+ if (variableName == null) { >+ throw new IllegalArgumentException(); >+ } >+ replaceChild(this.variableName, variableName, false); >+ this.variableName = variableName; >+ } >+ >+ /** >+ * Returns the expression of this enhanced for statement. >+ * >+ * @return the expression node >+ */ >+ public Expression getExpression() { >+ if (expression == null) { >+ // lazy initialize - use setter to ensure parent link set too >+ long count = getAST().modificationCount(); >+ setExpression(new SimpleName(getAST())); >+ getAST().setModificationCount(count); >+ } >+ return expression; >+ } >+ >+ /** >+ * Sets the expression of this enhanced for statement. >+ * >+ * @param expression the new expression node >+ * @exception IllegalArgumentException if: >+ * <ul> >+ * <li>the node belongs to a different AST</li> >+ * <li>the node already has a parent</li> >+ * <li>a cycle in would be created</li> >+ * </ul> >+ */ >+ public void setExpression(Expression expression) { >+ if (expression == null) { >+ throw new IllegalArgumentException(); >+ } >+ // an EnhancedForStatement may occur inside an Expression >+ // must check cycles >+ replaceChild(this.expression, expression, true); >+ this.expression = expression; >+ } >+ >+ /** >+ * Returns the body of this enchanced for statement. >+ * >+ * @return the body statement node >+ */ >+ public Statement getBody() { >+ if (body == null) { >+ // lazy initialize - use setter to ensure parent link set too >+ long count = getAST().modificationCount(); >+ setBody(new Block(getAST())); >+ getAST().setModificationCount(count); >+ } >+ return body; >+ } >+ >+ /** >+ * Sets the body of this enhanced for statement. >+ * >+ * @param statement the body statement node >+ * @exception IllegalArgumentException if: >+ * <ul> >+ * <li>the node belongs to a different AST</li> >+ * <li>the node already has a parent</li> >+ * <li>a cycle in would be created</li> >+ * </ul> >+ */ >+ public void setBody(Statement statement) { >+ if (statement == null) { >+ throw new IllegalArgumentException(); >+ } >+ // an EnhancedForStatement may occur inside a Statement - must check cycles >+ replaceChild(this.body, statement, true); >+ this.body = statement; >+ } >+ >+ /** >+ * Resolves and returns the binding for the loop variable of this >+ * enhanced for statement. >+ * <p> >+ * Note that bindings are generally unavailable unless requested when the >+ * AST is being built. >+ * </p> >+ * >+ * @return the binding, or <code>null</code> if the binding cannot be >+ * resolved >+ */ >+ public IVariableBinding resolveBinding() { >+ return getAST().getBindingResolver().resolveVariable(this); >+ } >+ >+ /* (omit javadoc for this method) >+ * Method declared on ASTNode. >+ */ >+ int memSize() { >+ return super.memSize() + 4 * 4; >+ } >+ >+ /* (omit javadoc for this method) >+ * Method declared on ASTNode. >+ */ >+ int treeSize() { >+ return >+ memSize() >+ + (type == null ? 0 : getType().treeSize()) >+ + (variableName == null ? 0 : getName().treeSize()) >+ + (expression == null ? 0 : getExpression().treeSize()) >+ + (body == null ? 0 : getBody().treeSize()); >+ } >+} >Index: dom/org/eclipse/jdt/core/dom/EnumConstantDeclaration.java >=================================================================== >RCS file: dom/org/eclipse/jdt/core/dom/EnumConstantDeclaration.java >diff -N dom/org/eclipse/jdt/core/dom/EnumConstantDeclaration.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ dom/org/eclipse/jdt/core/dom/EnumConstantDeclaration.java 8 Apr 2003 16:52:22 -0000 >@@ -0,0 +1,254 @@ >+/******************************************************************************* >+ * Copyright (c) 2000, 2003 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Common Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/cpl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.jdt.core.dom; >+ >+import java.util.Iterator; >+import java.util.List; >+ >+/** >+ * Enumeration constant declaration AST node type. >+ * >+ * <pre> >+ * EnumConstantDeclaration: >+ * [ Javadoc ] Identifier >+ * [ <b>(</b> [ Expression { <b>,</b> Expression } ] <b>)</b> ] >+ * [ <b>{</b> { ClassBodyDeclaration | <b>;</b> } <b>}</b> ] >+ * </pre> >+ * <p> >+ * When a Javadoc comment is present, the source >+ * range begins with the first character of the "/**" comment delimiter. >+ * When there is no Javadoc comment, the source range begins with the first >+ * character of the identifier. If there are class body declarations, the >+ * source range extends through the last character of the last character of >+ * the "}" token following the body declarations. If there are arguments but >+ * no class body declarations, the source range extends through the last >+ * character of the ")" token following the arguments. If there are no >+ * arguments and no class body declarations, the source range extends through >+ * the last character of the identifier. >+ * </p> >+ * <p> >+ * Note: Enum declarations are an experimental language feature >+ * under discussion in JSR-201 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * </p> >+ * >+ * @since 2.2 >+ */ >+public class EnumConstantDeclaration extends BodyDeclaration { >+ >+ /** >+ * The constant name; lazily initialized; defaults to a unspecified, >+ * legal Java class identifier. >+ */ >+ private SimpleName constantName = null; >+ >+ /** >+ * The list of argument expressions (element type: >+ * <code>Expression</code>). Defaults to an empty list. >+ */ >+ private ASTNode.NodeList arguments = >+ new ASTNode.NodeList(true, Expression.class); >+ >+ /** >+ * The body declarations (element type: <code>BodyDeclaration</code>). >+ * Defaults to an empty list. >+ */ >+ private ASTNode.NodeList bodyDeclarations = >+ new ASTNode.NodeList(true, BodyDeclaration.class); >+ >+ /** >+ * Creates a new AST node for an enumeration constants declaration owned by >+ * the given AST. By default, the enumeration constant has an unspecified, >+ * but legal, name; no javadoc; an empty list of arguments; and an empty >+ * list of body declarations. >+ * <p> >+ * N.B. This constructor is package-private; all subclasses must be >+ * declared in the same package; clients are unable to declare >+ * additional subclasses. >+ * </p> >+ * >+ * @param ast the AST that is to own this node >+ */ >+ EnumConstantDeclaration(AST ast) { >+ super(ast); >+ } >+ >+ /* (omit javadoc for this method) >+ * Method declared on ASTNode. >+ */ >+ public int getNodeType() { >+ return ENUM_CONSTANT_DECLARATION; >+ } >+ >+ /* (omit javadoc for this method) >+ * Method declared on ASTNode. >+ */ >+ ASTNode clone(AST target) { >+ EnumConstantDeclaration result = new EnumConstantDeclaration(target); >+ result.setSourceRange(this.getStartPosition(), this.getLength()); >+ result.setJavadoc( >+ (Javadoc) ASTNode.copySubtree(target,(ASTNode) getJavadoc())); >+ result.setName((SimpleName) getName().clone(target)); >+ result.arguments().addAll(ASTNode.copySubtrees(target, arguments())); >+ result.bodyDeclarations().addAll( >+ ASTNode.copySubtrees(target, bodyDeclarations())); >+ return result; >+ } >+ >+ /* (omit javadoc for this method) >+ * Method declared on ASTNode. >+ */ >+ public boolean subtreeMatch(ASTMatcher matcher, Object other) { >+ // dispatch to correct overloaded match method >+ return matcher.match(this, other); >+ } >+ >+ /* (omit javadoc for this method) >+ * Method declared on ASTNode. >+ */ >+ void accept0(ASTVisitor visitor) { >+ boolean visitChildren = visitor.visit(this); >+ if (visitChildren) { >+ // visit children in normal left to right reading order >+ acceptChild(visitor, getJavadoc()); >+ acceptChild(visitor, getName()); >+ acceptChildren(visitor, arguments); >+ acceptChildren(visitor, bodyDeclarations); >+ } >+ visitor.endVisit(this); >+ } >+ >+ /** >+ * Returns the name of the constant declared in this enum declaration. >+ * >+ * @return the constant name node >+ */ >+ public SimpleName getName() { >+ if (constantName == null) { >+ // lazy initialize - use setter to ensure parent link set too >+ long count = getAST().modificationCount(); >+ setName(new SimpleName(getAST())); >+ getAST().setModificationCount(count); >+ } >+ return constantName; >+ } >+ >+ /** >+ * Sets the name of the constant declared in this enum declaration to the >+ * given name. >+ * >+ * @param constantName the new constant name >+ * @exception IllegalArgumentException if: >+ * <ul> >+ * <li>the node belongs to a different AST</li> >+ * <li>the node already has a parent</li> >+ * </ul> >+ */ >+ public void setName(SimpleName constantName) { >+ if (constantName == null) { >+ throw new IllegalArgumentException(); >+ } >+ replaceChild(this.constantName, constantName, false); >+ this.constantName = constantName; >+ } >+ >+ /** >+ * Returns the live ordered list of argument expressions in this enumeration >+ * constant declaration. Note that an empty list of arguments is equivalent >+ * to not explicitly specifying arguments. >+ * >+ * @return the live list of argument expressions >+ * (element type: <code>Expression</code>) >+ */ >+ public List arguments() { >+ return arguments; >+ } >+ >+ /** >+ * Returns the live ordered list of body declarations of this enumeration >+ * constant declaration. Note that an empty list is equivalent to not >+ * explicitly specifying any body declarations. >+ * >+ * @return the live list of body declarations >+ * (element type: <code>BodyDeclaration</code>) >+ */ >+ public List bodyDeclarations() { >+ return bodyDeclarations; >+ } >+ >+ /** >+ * Resolves and returns the field binding for this enum constant. >+ * <p> >+ * Note that bindings are generally unavailable unless requested when the >+ * AST is being built. >+ * </p> >+ * >+ * @return the binding, or <code>null</code> if the binding cannot be >+ * resolved >+ */ >+ public IVariableBinding resolveVariable() { >+ return getAST().getBindingResolver().resolveVariable(this); >+ } >+ >+ /* (omit javadoc for this method) >+ * Method declared on ASTNode. >+ */ >+ void appendDebugString(StringBuffer buffer) { >+ buffer.append("EnumConstantDeclaration[");//$NON-NLS-1$ >+ buffer.append(getName().getIdentifier()); >+ buffer.append(" ");//$NON-NLS-1$ >+ if (!arguments().isEmpty()) { >+ buffer.append("(");//$NON-NLS-1$ >+ for (Iterator it = arguments().iterator(); it.hasNext(); ) { >+ Expression e = (Expression) it.next(); >+ e.appendDebugString(buffer); >+ if (it.hasNext()) { >+ buffer.append(",");//$NON-NLS-1$ >+ } >+ } >+ buffer.append(")");//$NON-NLS-1$ >+ } >+ if (!bodyDeclarations().isEmpty()) { >+ buffer.append(" {");//$NON-NLS-1$ >+ for (Iterator it = bodyDeclarations().iterator(); it.hasNext(); ) { >+ BodyDeclaration d = (BodyDeclaration) it.next(); >+ d.appendDebugString(buffer); >+ if (it.hasNext()) { >+ buffer.append(";");//$NON-NLS-1$ >+ } >+ } >+ buffer.append("}");//$NON-NLS-1$ >+ } >+ buffer.append("]");//$NON-NLS-1$ >+ } >+ >+ /* (omit javadoc for this method) >+ * Method declared on ASTNode. >+ */ >+ int memSize() { >+ return super.memSize() + 3 * 4; >+ } >+ >+ /* (omit javadoc for this method) >+ * Method declared on ASTNode. >+ */ >+ int treeSize() { >+ return >+ memSize() >+ + (getJavadoc() == null ? 0 : getJavadoc().treeSize()) >+ + (constantName == null ? 0 : getName().treeSize()) >+ + arguments.listSize() >+ + bodyDeclarations.listSize(); >+ } >+} >+ >Index: dom/org/eclipse/jdt/core/dom/ImportDeclaration.java >=================================================================== >RCS file: /data/cvs/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ImportDeclaration.java,v >retrieving revision 1.11 >diff -u -r1.11 ImportDeclaration.java >--- dom/org/eclipse/jdt/core/dom/ImportDeclaration.java 11 Mar 2003 15:03:51 -0000 1.11 >+++ dom/org/eclipse/jdt/core/dom/ImportDeclaration.java 8 Apr 2003 16:52:22 -0000 >@@ -16,9 +16,15 @@ > * > * <pre> > * ImportDeclaration: >- * <b>import</b> Name [ <b>.</b> <b>*</b> ] <b>;</b> >+ * <b>import</b> [ <b>static</b> ] Name [ <b>.</b> <b>*</b> ] <b>;</b> > * </pre> > * >+ * <p> >+ * Note: Static imports are an experimental language feature >+ * under discussion in JSR-201 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * </p> > * @since 2.0 > */ > public class ImportDeclaration extends ASTNode { >@@ -34,9 +40,22 @@ > private boolean onDemand = false; > > /** >+ * Static versus regular; defaults to regular import. >+ * <p> >+ * Note: Static imports are an experimental language feature >+ * under discussion in JSR-201 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * </p> >+ * >+ * @since 2.2 >+ */ >+ private boolean isStatic = false; >+ >+ /** > * Creates a new AST node for an import declaration owned by the >- * given AST. The import declaration initially is a single type >- * import for an unspecified, but legal, Java type name. >+ * given AST. The import declaration initially is a regular (non-static) >+ * single type import for an unspecified, but legal, Java type name. > * <p> > * N.B. This constructor is package-private; all subclasses must be > * declared in the same package; clients are unable to declare >@@ -63,6 +82,7 @@ > ImportDeclaration result = new ImportDeclaration(target); > result.setSourceRange(this.getStartPosition(), this.getLength()); > result.setOnDemand(isOnDemand()); >+ result.setStatic(isStatic()); > result.setName((Name) getName().clone(target)); > return result; > } >@@ -89,8 +109,11 @@ > /** > * Returns the name imported by this declaration. > * <p> >- * For an on-demand import, this is the name of a package. For a >- * single-type import, this is the qualified name of a type. >+ * For a regular on-demand import, this is the name of a package. >+ * For a static on-demand import, this is the qualified name of >+ * a type. For a regular single-type import, this is the qualified name >+ * of a type. For a static single-type import, this is the qualified name >+ * of a static member of a type. > * </p> > * > * @return the imported name node >@@ -109,8 +132,11 @@ > /** > * Sets the name of this import declaration to the given name. > * <p> >- * For an on-demand import, this is the name of a package. For a >- * single-type import, this is the qualified name of a type. >+ * For a regular on-demand import, this is the name of a package. >+ * For a static on-demand import, this is the qualified name of >+ * a type. For a regular single-type import, this is the qualified name >+ * of a type. For a static single-type import, this is the qualified name >+ * of a static member of a type. > * </p> > * > * @param name the new import name >@@ -152,6 +178,41 @@ > } > > /** >+ * Returns whether this import declaration is a static import. >+ * <p> >+ * Note: Static imports are an experimental language feature >+ * under discussion in JSR-201 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * </p> >+ * >+ * @return <code>true</code> if this is a static import, >+ * and <code>false</code> if this is a regular import >+ * @since 2.2 >+ */ >+ public boolean isStatic() { >+ return isStatic; >+ } >+ >+ /** >+ * Sets whether this import declaration is a static import. >+ * <p> >+ * Note: Static imports are an experimental language feature >+ * under discussion in JSR-201 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * </p> >+ * >+ * @param isStatic <code>true</code> if this is a static import, >+ * and <code>false</code> if this is a regular import >+ * @since 2.2 >+ */ >+ public void setStatic(boolean isStatic) { >+ modifying(); >+ this.isStatic = isStatic; >+ } >+ >+ /** > * Resolves and returns the binding for the package or type imported by > * this import declaration. > * <p> >@@ -171,7 +232,7 @@ > * Method declared on ASTNode. > */ > int memSize() { >- return BASE_NODE_SIZE + 2 * 4; >+ return BASE_NODE_SIZE + 3 * 4; > } > > /* (omit javadoc for this method) >Index: dom/org/eclipse/jdt/core/dom/NaiveASTFlattener.java >=================================================================== >RCS file: /data/cvs/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/NaiveASTFlattener.java,v >retrieving revision 1.9 >diff -u -r1.9 NaiveASTFlattener.java >--- dom/org/eclipse/jdt/core/dom/NaiveASTFlattener.java 11 Mar 2003 15:03:51 -0000 1.9 >+++ dom/org/eclipse/jdt/core/dom/NaiveASTFlattener.java 8 Apr 2003 16:52:23 -0000 >@@ -376,6 +376,50 @@ > } > > /* >+ * @see ASTVisitor#visit(EnhancedForStatement) >+ * @since 2.2 >+ */ >+ public boolean visit(EnhancedForStatement node) { >+ buffer.append("for (");//$NON-NLS-1$ >+ node.getType().accept(this); >+ buffer.append(" ");//$NON-NLS-1$ >+ node.getName().accept(this); >+ buffer.append(" : ");//$NON-NLS-1$ >+ node.getExpression().accept(this); >+ buffer.append(") ");//$NON-NLS-1$ >+ node.getBody().accept(this); >+ return false; >+ } >+ >+ /* >+ * @see ASTVisitor#visit(EnumConstantDeclaration) >+ * @since 2.2 >+ */ >+ public boolean visit(EnumConstantDeclaration node) { >+ node.getName().accept(this); >+ if (!node.arguments().isEmpty()) { >+ buffer.append("(");//$NON-NLS-1$ >+ for (Iterator it = node.arguments().iterator(); it.hasNext(); ) { >+ Expression e = (Expression) it.next(); >+ e.accept(this); >+ if (it.hasNext()) { >+ buffer.append(",");//$NON-NLS-1$ >+ } >+ } >+ buffer.append(")");//$NON-NLS-1$ >+ } >+ if (!node.bodyDeclarations().isEmpty()) { >+ buffer.append("{");//$NON-NLS-1$ >+ for (Iterator it = node.bodyDeclarations().iterator(); it.hasNext(); ) { >+ BodyDeclaration d = (BodyDeclaration) it.next(); >+ d.accept(this); >+ } >+ buffer.append("}");//$NON-NLS-1$ >+ } >+ return false; >+ } >+ >+ /* > * @see ASTVisitor#visit(ExpressionStatement) > */ > public boolean visit(ExpressionStatement node) { >@@ -458,6 +502,9 @@ > */ > public boolean visit(ImportDeclaration node) { > buffer.append("import ");//$NON-NLS-1$ >+ if (node.isStatic()) { >+ buffer.append("static ");//$NON-NLS-1$ >+ } > node.getName().accept(this); > if (node.isOnDemand()) { > buffer.append(".*");//$NON-NLS-1$ >@@ -869,8 +916,20 @@ > buffer.append(" ");//$NON-NLS-1$ > } > buffer.append("{");//$NON-NLS-1$ >+ BodyDeclaration prev = null; > for (Iterator it = node.bodyDeclarations().iterator(); it.hasNext(); ) { > BodyDeclaration d = (BodyDeclaration) it.next(); >+ if (prev instanceof EnumConstantDeclaration) { >+ // enum constant declarations do not include punctuation >+ if (d instanceof EnumConstantDeclaration) { >+ // enum constant declarations are separated by commas >+ buffer.append(", ");//$NON-NLS-1$ >+ } else { >+ // semicolon separates last enum constant declaration from >+ // first class body declarations >+ buffer.append("; ");//$NON-NLS-1$ >+ } >+ } > d.accept(this); > } > buffer.append("}");//$NON-NLS-1$ >Index: dom/org/eclipse/jdt/core/dom/SimpleName.java >=================================================================== >RCS file: /data/cvs/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SimpleName.java,v >retrieving revision 1.25 >diff -u -r1.25 SimpleName.java >--- dom/org/eclipse/jdt/core/dom/SimpleName.java 11 Mar 2003 15:03:51 -0000 1.25 >+++ dom/org/eclipse/jdt/core/dom/SimpleName.java 8 Apr 2003 16:52:23 -0000 >@@ -140,6 +140,10 @@ > * providing <code>isConstructor</code> is <code>false</code>.</li> > * <li>The variable name in any type of <code>VariableDeclaration</code> > * node.</li> >+ * <li>The enum constant name in an <code>EnumConstantDeclaration</code> >+ * node.</li> >+ * <li>The variable name in an <code>EnhancedForStatement</code> >+ * node.</li> > * </ul> > * <p> > * Note that this is a convenience method that simply checks whether >@@ -173,6 +177,15 @@ > if (parent instanceof VariableDeclarationFragment) { > VariableDeclarationFragment p = (VariableDeclarationFragment) parent; > // make sure its the name of the variable (not the initializer) >+ return (p.getName() == this); >+ } >+ if (parent instanceof EnumConstantDeclaration) { >+ // could only be the name of the enum constant >+ return true; >+ } >+ if (parent instanceof EnhancedForStatement) { >+ EnhancedForStatement p = (EnhancedForStatement) parent; >+ // make sure its the name of the loop variable (not the initializer) > return (p.getName() == this); > } > return false; >Index: dom/org/eclipse/jdt/core/dom/Statement.java >=================================================================== >RCS file: /data/cvs/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/Statement.java,v >retrieving revision 1.19 >diff -u -r1.19 Statement.java >--- dom/org/eclipse/jdt/core/dom/Statement.java 11 Mar 2003 15:03:51 -0000 1.19 >+++ dom/org/eclipse/jdt/core/dom/Statement.java 8 Apr 2003 16:52:23 -0000 >@@ -25,6 +25,7 @@ > * Block > * IfStatement > * ForStatement >+ * EnhancedForStatement > * WhileStatement > * DoStatement > * TryStatement >Index: dom/org/eclipse/jdt/core/dom/TypeDeclaration.java >=================================================================== >RCS file: /data/cvs/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeDeclaration.java,v >retrieving revision 1.20 >diff -u -r1.20 TypeDeclaration.java >--- dom/org/eclipse/jdt/core/dom/TypeDeclaration.java 7 Apr 2003 18:28:42 -0000 1.20 >+++ dom/org/eclipse/jdt/core/dom/TypeDeclaration.java 8 Apr 2003 16:52:24 -0000 >@@ -22,6 +22,7 @@ > * TypeDeclaration: > * ClassDeclaration > * InterfaceDeclaration >+ * EnumDeclaration > * ClassDeclaration: > * [ Javadoc ] { Modifier } <b>class</b> Identifier > * [ <b>extends</b> Type] >@@ -31,16 +32,28 @@ > * [ Javadoc ] { Modifier } <b>interface</b> Identifier > * [ <b>extends</b> Type { <b>,</b> Type } ] > * <b>{</b> { InterfaceBodyDeclaration | <b>;</b> } <b>}</b> >+ * EnumDeclaration: >+ * [ Javadoc ] { Modifier } <b>enum</b> Identifier >+ * [ <b>implements</b> Type { <b>,</b> Type } ] >+ * <b>{</b> >+ * [ EnumConstantDeclaration [ <b>,</b> EnumConstantDeclaration ] ] >+ * [ <b>;</b> { ClassBodyDeclaration | <b>;</b> } ] >+ * <b>}</b> > * </pre> > * <p> > * When a Javadoc comment is present, the source > * range begins with the first character of the "/**" comment delimiter. > * When there is no Javadoc comment, the source range begins with the first > * character of the first modifier keyword (if modifiers), or the >- * first character of the "class" or "interface": keyword (if no modifiers). >- * The source range extends through the last character of the ";" token (if >- * no body), or the last character of the "}" token following the body >- * declarations. >+ * first character of the "class", "interface", or "enum" keyword (if no >+ * modifiers). The source range extends through the last character of the "}" >+ * token following the body declarations. >+ * </p> >+ * <p> >+ * Note: Enum declarations are an experimental language feature >+ * under discussion in JSR-201 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. > * </p> > * > * @since 2.0 >@@ -62,6 +75,20 @@ > private boolean isInterface = false; > > /** >+ * <code>true</code> for an enumeration, <code>false</code> for a class. >+ * Defaults to class. This field is ignored for interfaces. >+ * <p> >+ * Note: Enum declarations are an experimental language feature >+ * under discussion in JSR-201 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * </p> >+ * >+ * @since 2.2 >+ */ >+ private boolean isEnumeration = false; >+ >+ /** > * The modifiers; bit-wise or of Modifier flags. > * Defaults to none. > */ >@@ -129,6 +156,7 @@ > result.setJavadoc( > (Javadoc) ASTNode.copySubtree(target,(ASTNode) getJavadoc())); > result.setInterface(isInterface()); >+ result.setEnumeration(isEnumeration()); > result.setName((SimpleName) getName().clone(target)); > result.setSuperclass( > (Name) ASTNode.copySubtree(target,(ASTNode) getSuperclass())); >@@ -168,7 +196,7 @@ > * interface. > * > * @return <code>true</code> if this is an interface declaration, >- * and <code>false</code> if this is a class declaration >+ * and <code>false</code> if this is a class or enumeration declaration > */ > public boolean isInterface() { > return isInterface; >@@ -179,7 +207,7 @@ > * interface. > * > * @param isInterface <code>true</code> if this is an interface >- * declaration, and <code>false</code> if this is a class >+ * declaration, and <code>false</code> if this is a class or enumeration > * declaration > */ > public void setInterface(boolean isInterface) { >@@ -188,6 +216,44 @@ > } > > /** >+ * Returns whether this type declaration declares a class or an >+ * enumeration. Note that this property is not relevant for interfaces. >+ * <p> >+ * Note: Enum declarations are an experimental language feature >+ * under discussion in JSR-201 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * </p> >+ * >+ * @return <code>true</code> if this is an enumeration declaration, >+ * and <code>false</code> if this is a class declaration >+ * @since 2.2 >+ */ >+ public boolean isEnumeration() { >+ return isEnumeration; >+ } >+ >+ /** >+ * Sets whether this type declaration declares a class or an >+ * enumeration. Note that this property is not relevant for interfaces. >+ * <p> >+ * Note: Enum declarations are an experimental language feature >+ * under discussion in JSR-201 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * </p> >+ * >+ * @param isEnumeration <code>true</code> if this is an enumeration >+ * declaration, and <code>false</code> if this is a class >+ * declaration >+ * @since 2.2 >+ */ >+ public void setEnumeration(boolean isEnumeration) { >+ modifying(); >+ this.isEnumeration = isEnumeration; >+ } >+ >+ /** > * Returns the modifiers explicitly specified on this declaration. > * <p> > * Note that deprecated is not included. >@@ -266,8 +332,9 @@ > * Returns the name of the superclass declared in this type > * declaration, or <code>null</code> if there is none. > * <p> >- * Note that this child is not relevant for interface declarations >- * (although it does still figure in subtree equality comparisons). >+ * Note that this child is not relevant for interface and >+ * enumeration declarations (although it does still figure in subtree >+ * equality comparisons). > * </p> > * > * @return the superclass name node, or <code>null</code> if >@@ -281,8 +348,9 @@ > * Sets or clears the name of the superclass declared in this type > * declaration. > * <p> >- * Note that this child is not relevant for interface declarations >- * (although it does still figure in subtree equality comparisons). >+ * Note that this child is not relevant for interface and >+ * enumeration declarations (although it does still figure in subtree >+ * equality comparisons). > * </p> > * > * @param superclassName the superclass name node, or <code>null</code> if >@@ -302,9 +370,10 @@ > > /** > * Returns the live ordered list of names of superinterfaces of this type >- * declaration. For a class declaration, these are the names of the >- * interfaces that this class implements; for an interface declaration, >- * these are the names of the interfaces that this interface extends. >+ * declaration. For a class or enumeration declaration, these are the names >+ * of the interfaces that this class implements; for an interface >+ * declaration, these are the names of the interfaces that this interface >+ * extends. > * > * @return the live list of interface names > * (element type: <code>Name</code>) >@@ -317,8 +386,11 @@ > * Returns the live ordered list of body declarations of this type > * declaration. For a class declaration, these are the > * initializer, field, method, constructor, and member type >- * declarations; for an interface declaration, these are >- * the constant, method, and member type declarations. >+ * declarations; for an interface declaration, these are the constant, >+ * method, and member type declarations. For an enumeration declaration, >+ * these are the enum constant declarations, which are always at the >+ * front of the list, followed by any initializer, field, method, >+ * constructor, and member type declarations. > * > * @return the live list of body declarations > * (element type: <code>BodyDeclaration</code>) >@@ -331,7 +403,9 @@ > * Returns the ordered list of field declarations of this type > * declaration. For a class declaration, these are the > * field declarations; for an interface declaration, these are >- * the constant declarations. >+ * the constant declarations; for an enum declaration, these are >+ * the explicitly declared field declarations (excludes enum >+ * constant declarations). > * <p> > * This convenience method returns this node's body declarations > * with non-fields filtered out. Unlike <code>bodyDeclarations</code>, >@@ -421,6 +495,44 @@ > } > > /** >+ * Returns the ordered list of enum constant declarations of this enum >+ * declaration. This method is not relevant for class and interface >+ * declarations, for which enum constant declarations are meaningless. >+ * <p> >+ * This convenience method returns this node's enum constant declarations >+ * with non-enum constants filtered out. Unlike <code>bodyDeclarations</code>, >+ * this method does not return a live result. >+ * </p> >+ * <p> >+ * Note: Enum declarations are an experimental language feature >+ * under discussion in JSR-201 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * </p> >+ * >+ * @return the (possibly empty) list of enum constant declarations >+ * @since 2.2 >+ */ >+ public EnumConstantDeclaration[] getEnumConstants() { >+ List bd = bodyDeclarations(); >+ int enumCount = 0; >+ for (Iterator it = bd.listIterator(); it.hasNext(); ) { >+ if (it.next() instanceof EnumConstantDeclaration) { >+ enumCount++; >+ } >+ } >+ EnumConstantDeclaration[] enumConstants = new EnumConstantDeclaration[enumCount]; >+ int next = 0; >+ for (Iterator it = bd.listIterator(); it.hasNext(); ) { >+ Object decl = it.next(); >+ if (decl instanceof EnumConstantDeclaration) { >+ enumConstants[next++] = (EnumConstantDeclaration) decl; >+ } >+ } >+ return enumConstants; >+ } >+ >+ /** > * Returns whether this type declaration is a package member (that is, > * a top-level type). > * <p> >@@ -440,18 +552,19 @@ > * Returns whether this type declaration is a type member. > * <p> > * Note that this is a convenience method that simply checks whether >- * this node's parent is a type declaration node or an anonymous >- * class declaration. >+ * this node's parent is a type declaration node, an anonymous >+ * class declaration, or an enumeration constant declaration. > * </p> > * > * @return <code>true</code> if this type declaration is a child of >- * a type declaration node or a class instance creation node, and >- * <code>false</code> otherwise >+ * a type declaration node, a class instance creation node, or an >+ * enum constant declaration, and <code>false</code> otherwise > */ > public boolean isMemberTypeDeclaration() { > ASTNode parent = getParent(); > return (parent instanceof TypeDeclaration) >- || (parent instanceof AnonymousClassDeclaration); >+ || (parent instanceof AnonymousClassDeclaration) >+ || (parent instanceof EnumConstantDeclaration); > } > > /** >@@ -488,25 +601,28 @@ > * Method declared on ASTNode. > */ > void appendDebugString(StringBuffer buffer) { >- buffer.append("TypeDeclaration[");//$NON-NLS-1$ >- buffer.append(isInterface() ? "interface " : "class ");//$NON-NLS-2$//$NON-NLS-1$ >+ buffer.append("TypeDeclaration["); //$NON-NLS-1$ >+ buffer.append(isInterface() >+ ? "interface " //$NON-NLS-1$ >+ : (isEnumeration() >+ ? "enum " : "class ")); //$NON-NLS-2$//$NON-NLS-1$ > buffer.append(getName().getIdentifier()); >- buffer.append(" ");//$NON-NLS-1$ >- for (Iterator it = bodyDeclarations().iterator(); it.hasNext(); ) { >+ buffer.append(" "); //$NON-NLS-1$ >+ for (Iterator it = bodyDeclarations().iterator(); it.hasNext();) { > BodyDeclaration d = (BodyDeclaration) it.next(); > d.appendDebugString(buffer); > if (it.hasNext()) { >- buffer.append(";");//$NON-NLS-1$ >+ buffer.append(";"); //$NON-NLS-1$ > } > } >- buffer.append("]");//$NON-NLS-1$ >+ buffer.append("]"); //$NON-NLS-1$ > } > > /* (omit javadoc for this method) > * Method declared on ASTNode. > */ > int memSize() { >- return super.memSize() + 6 * 4; >+ return super.memSize() + 7 * 4; > } > > /* (omit javadoc for this method)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 36144
: 4577 |
4578