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 4581 Details for
Bug 36142
[DOM/AST] DOM support for JSR-014 generics
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
DOM/AST experimental API for JSR-014 support (2)
ast-JSR-014-patch-20030414.txt (text/plain), 80.75 KB, created by
Jim des Rivieres
on 2003-04-14 14:19:01 EDT
(
hide
)
Description:
DOM/AST experimental API for JSR-014 support (2)
Filename:
MIME Type:
Creator:
Jim des Rivieres
Created:
2003-04-14 14:19:01 EDT
Size:
80.75 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 14 Apr 2003 19:12:36 -0000 >@@ -693,7 +693,7 @@ > * type (<code>Type</code>) by wrapping it. > * </p> > * >- * @param typeName the name of the class or interface >+ * @param typeName the name of the class, interface, or type variable > * @return a new unparented simple type node > * @exception IllegalArgumentException if: > * <ul> >@@ -776,6 +776,58 @@ > return result; > } > >+ /** >+ * Creates and returns a new unparented parameterized type node with the >+ * given type name and an empty list of type arguments. >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * </p> >+ * >+ * @param typeName the name of the class or interface >+ * @return a new unparented parameterized type node >+ * @exception IllegalArgumentException if: >+ * <ul> >+ * <li>the node belongs to a different AST</li> >+ * <li>the node already has a parent</li> >+ * </ul> >+ * @since 2.2 >+ */ >+ public ParameterizedType newParameterizedType(Name typeName) { >+ ParameterizedType result = new ParameterizedType(this); >+ result.setName(typeName); >+ return result; >+ } >+ >+ /** >+ * Creates and returns a new unparented qualified type node with >+ * the given qualifier type and name. >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * </p> >+ * >+ * @param qualifier the qualifier type node >+ * @param name the simple name being qualified >+ * @return a new unparented qualified type node >+ * @exception IllegalArgumentException if: >+ * <ul> >+ * <li>the node belongs to a different AST</li> >+ * <li>the node already has a parent</li> >+ * </ul> >+ * @since 2.2 >+ */ >+ public QualifiedType newQualifiedType(Type qualifier, SimpleName name) { >+ QualifiedType result = new QualifiedType(this); >+ result.setQualifier(qualifier); >+ result.setName(name); >+ return result; >+ } >+ > //=============================== DECLARATIONS =========================== > /** > * Creates an unparented compilation unit node owned by this AST. >@@ -830,8 +882,8 @@ > /** > * Creates an unparented class declaration node owned by this AST. > * The name of the class is an unspecified, but legal, name; >- * no modifiers; no Javadoc comment; no superclass or superinterfaces; >- * and an empty class body. >+ * no modifiers; no type parameters; no Javadoc comment; no superclass >+ * or superinterfaces; and an empty class body. > * <p> > * To create an interface, use this method and then call > * <code>TypeDeclaration.setInterface(true)</code> and >@@ -848,9 +900,9 @@ > /** > * Creates an unparented method declaration node owned by this AST. > * By default, the declaration is for a method of an unspecified, but >- * legal, name; no modifiers; no Javadoc comment; no parameters; return >- * type void; no extra array dimensions; no thrown exceptions; and no >- * body (as opposed to an empty body). >+ * legal, name; no modifiers; no Javadoc comment; no type parameters; >+ * return type void; no parameters; no extra array dimensions; >+ * no thrown exceptions; and no body (as opposed to an empty body). > * <p> > * To create a constructor, use this method and then call > * <code>MethodDeclaration.setConstructor(true)</code> and >@@ -913,6 +965,24 @@ > return result; > } > >+ /** >+ * Creates and returns a new unparented type parameter type node with an >+ * unspecified type variable name and an empty list of type bounds. >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 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 type parameter node >+ * @since 2.2 >+ */ >+ public TypeParameter newTypeParameter() { >+ TypeParameter result = new TypeParameter(this); >+ return result; >+ } >+ > //=============================== STATEMENTS =========================== > /** > * Creates a new unparented local variable declaration statement node >@@ -1569,7 +1639,7 @@ > /** > * Creates and returns a new unparented class instance creation > * ("new") expression node owned by this AST. By default, >- * there is no qualifying expression, an unspecified (but legal) type name, >+ * there is no qualifying expression, an unspecified type, > * an empty list of arguments, and does not declare an anonymous > * class declaration. > * >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 14 Apr 2003 19:12:37 -0000 >@@ -455,7 +455,7 @@ > ClassInstanceCreation o = (ClassInstanceCreation) other; > return ( > safeSubtreeMatch(node.getExpression(), o.getExpression()) >- && safeSubtreeMatch(node.getName(), o.getName()) >+ && safeSubtreeMatch(node.getType(), o.getType()) > && safeSubtreeListMatch(node.arguments(), o.arguments()) > && safeSubtreeMatch( > node.getAnonymousClassDeclaration(), >@@ -907,7 +907,8 @@ > (node.getModifiers() == o.getModifiers()) > && (node.isConstructor() == o.isConstructor()) > && safeSubtreeMatch(node.getJavadoc(), o.getJavadoc()) >- // n.b. compare return type even for constructors >+ // n.b. compare type parameters and return type even for constructors >+ && safeSubtreeListMatch(node.typeParameters(), o.typeParameters()) > && safeSubtreeMatch(node.getReturnType(), o.getReturnType()) > && safeSubtreeMatch(node.getName(), o.getName()) > && safeSubtreeListMatch(node.parameters(), o.parameters()) >@@ -1013,6 +1014,36 @@ > * other object is a node of the same type with structurally isomorphic > * child subtrees. Subclasses may override this method as needed. > * </p> >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 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(ParameterizedType node, Object other) { >+ if (!(other instanceof ParameterizedType)) { >+ return false; >+ } >+ ParameterizedType o = (ParameterizedType) other; >+ return safeSubtreeMatch(node.getName(), o.getName()) >+ && safeSubtreeListMatch(node.typeArguments(), o.typeArguments()); >+ } >+ >+ /** >+ * 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> >@@ -1129,6 +1160,37 @@ > * other object is a node of the same type with structurally isomorphic > * child subtrees. Subclasses may override this method as needed. > * </p> >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 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(QualifiedType node, Object other) { >+ if (!(other instanceof QualifiedType)) { >+ return false; >+ } >+ QualifiedType o = (QualifiedType) other; >+ return ( >+ safeSubtreeMatch(node.getQualifier(), o.getQualifier()) >+ && safeSubtreeMatch(node.getName(), o.getName())); >+ } >+ >+ /** >+ * 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> >@@ -1477,8 +1539,9 @@ > && (node.isInterface() == o.isInterface()) > && safeSubtreeMatch(node.getJavadoc(), o.getJavadoc()) > && safeSubtreeMatch(node.getName(), o.getName()) >- && safeSubtreeMatch(node.getSuperclass(), o.getSuperclass()) >- && safeSubtreeListMatch(node.superInterfaces(), o.superInterfaces()) >+ && safeSubtreeListMatch(node.typeParameters(), o.typeParameters()) >+ && safeSubtreeMatch(node.getSuperclassType(), o.getSuperclassType()) >+ && safeSubtreeListMatch(node.superInterfaceTypes(), o.superInterfaceTypes()) > && safeSubtreeListMatch(node.bodyDeclarations(), o.bodyDeclarations())); > } > >@@ -1524,6 +1587,36 @@ > } > TypeLiteral o = (TypeLiteral) other; > return safeSubtreeMatch(node.getType(), o.getType()); >+ } >+ >+ /** >+ * 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: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 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(TypeParameter node, Object other) { >+ if (!(other instanceof TypeParameter)) { >+ return false; >+ } >+ TypeParameter o = (TypeParameter) other; >+ return safeSubtreeMatch(node.getName(), o.getName()) >+ && safeSubtreeListMatch(node.typeBounds(), o.typeBounds()); > } > > /** >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 14 Apr 2003 19:12:39 -0000 >@@ -549,6 +549,60 @@ > public static final int INSTANCEOF_EXPRESSION = 62; > > /** >+ * Reserved for experimental JSR-201 constructs. >+ * @since 2.2 >+ */ >+ private static final int RESERVED_1 = 63; >+ >+ /** >+ * Reserved for experimental JSR-201 constructs. >+ * @since 2.2 >+ */ >+ private static final int RESERVED_2 = 64; >+ >+ /** >+ * Node type constant indicating a node of type >+ * <code>TypeParameter</code>. >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * </p> >+ * @see TypeParameter >+ * @since 2.2 >+ */ >+ public static final int TYPE_PARAMETER = 65; >+ >+ /** >+ * Node type constant indicating a node of type >+ * <code>ParameterizedType</code>. >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * </p> >+ * @see ParameterizedType >+ * @since 2.2 >+ */ >+ public static final int PARAMETERIZED_TYPE = 66; >+ >+ /** >+ * Node type constant indicating a node of type >+ * <code>QualifiedType</code>. >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * </p> >+ * @see QualifiedType >+ * @since 2.2 >+ */ >+ public static final int QUALIFIED_TYPE = 67; >+ >+ /** > * 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 14 Apr 2003 19:12:39 -0000 >@@ -229,6 +229,20 @@ > public boolean visit(PackageDeclaration node) { > return true; > } >+ >+ /** Visits the given node. >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 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(ParameterizedType node) { >+ return true; >+ } > public boolean visit(ParenthesizedExpression node) { > return true; > } >@@ -244,6 +258,19 @@ > public boolean visit(QualifiedName node) { > return true; > } >+ /** Visits the given node. >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 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(QualifiedType node) { >+ return true; >+ } > public boolean visit(ReturnStatement node) { > return true; > } >@@ -292,6 +319,19 @@ > public boolean visit(TypeLiteral node) { > return true; > } >+ /** Visits the given node. >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 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(TypeParameter node) { >+ return true; >+ } > public boolean visit(SingleVariableDeclaration node) { > return true; > } >@@ -380,6 +420,18 @@ > } > public void endVisit(PackageDeclaration node) { > } >+ /** Ends visit of the given node. >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 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(ParameterizedType node) { >+ } > public void endVisit(ParenthesizedExpression node) { > } > public void endVisit(PostfixExpression node) { >@@ -390,6 +442,18 @@ > } > public void endVisit(QualifiedName node) { > } >+ /** Ends visit of the given node. >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 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(QualifiedType node) { >+ } > public void endVisit(ReturnStatement node) { > } > public void endVisit(SimpleName node) { >@@ -421,6 +485,18 @@ > public void endVisit(TypeDeclarationStatement node) { > } > public void endVisit(TypeLiteral node) { >+ } >+ /** Ends visit of the given node. >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 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(TypeParameter node) { > } > public void endVisit(SingleVariableDeclaration node) { > } >Index: dom/org/eclipse/jdt/core/dom/ClassInstanceCreation.java >=================================================================== >RCS file: /data/cvs/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ClassInstanceCreation.java,v >retrieving revision 1.14 >diff -u -r1.14 ClassInstanceCreation.java >--- dom/org/eclipse/jdt/core/dom/ClassInstanceCreation.java 11 Mar 2003 15:03:51 -0000 1.14 >+++ dom/org/eclipse/jdt/core/dom/ClassInstanceCreation.java 14 Apr 2003 19:12:40 -0000 >@@ -18,10 +18,39 @@ > * > * <pre> > * ClassInstanceCreation: >- * [ Expression <b>.</b> ] <b>new</b> TypeName >+ * [ Expression <b>.</b> ] <b>new</b> Type > * <b>(</b> [ Expression { <b>,</b> Expression } ] <b>)</b> > * [ AnonymousClassDeclaration ] > * </pre> >+ * <p> >+ * Not all node arragements will represent legal Java constructs. In particular, >+ * it is nonsense if the type is a primitive type or an array type (primitive >+ * types cannot be instantiated, and array creations must be represented with >+ * <code>ArrayCreation</code> nodes). The normal use is when the type is a >+ * simple, qualified, or parameterized type. >+ * </p> >+ * <p> >+ * A type like "A.B" can be represented either of two ways: >+ * <ol> >+ * <li> >+ * <code>QualifiedType(SimpleType(SimpleName("A")),SimpleName("B"))</code> >+ * </li> >+ * <li> >+ * <code>SimpleType(QualifiedName(SimpleName("A"),SimpleName("B")))</code> >+ * </li> >+ * </ol> >+ * The first form is preferred when "A" is known to be a type (as opposed >+ * to a package). However, a parser cannot always determine this. Clients >+ * should be prepared to handle either rather than make assumptions. >+ * (Note also that the first form became possible as of 2.2; only the second >+ * form existed in 2.0 and 2.1.) >+ * </p> >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 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 > */ >@@ -33,10 +62,10 @@ > private Expression optionalExpression = null; > > /** >- * The type name; lazily initialized; defaults to a unspecified, >- * legal type name. >+ * The type; lazily initialized; defaults to a unspecified type. >+ * @since 2.2 > */ >- private Name typeName = null; >+ private Type type = null; > > /** > * The list of argument expressions (element type: >@@ -54,7 +83,7 @@ > /** > * Creates a new AST node for a class instance creation expression owned > * by the given AST. By default, there is no qualifying expression, >- * an unspecified (but legal) type name, an empty list of arguments, >+ * an unspecified type, an empty list of arguments, > * and does not declare an anonymous class. > * <p> > * N.B. This constructor is package-private; all subclasses must be >@@ -83,7 +112,7 @@ > result.setSourceRange(this.getStartPosition(), this.getLength()); > result.setExpression( > (Expression) ASTNode.copySubtree(target, getExpression())); >- result.setName((Name) getName().clone(target)); >+ result.setType((Type) getType().clone(target)); > result.arguments().addAll(ASTNode.copySubtrees(target, arguments())); > result.setAnonymousClassDeclaration( > (AnonymousClassDeclaration) >@@ -107,7 +136,7 @@ > if (visitChildren) { > // visit children in normal left to right reading order > acceptChild(visitor, getExpression()); >- acceptChild(visitor, getName()); >+ acceptChild(visitor, getType()); > acceptChildren(visitor, arguments); > acceptChild(visitor, getAnonymousClassDeclaration()); > } >@@ -148,15 +177,28 @@ > * creation expression. > * > * @return the type name node >+ * @deprecated Replaced by <code>getType</code>, which returns >+ * a <code>Type</code> instead of a <code>Name</code>. > */ > public Name getName() { >- if (typeName == null) { >- // lazy initialize - use setter to ensure parent link set too >- long count = getAST().modificationCount(); >- setName(new SimpleName(getAST())); >- getAST().setModificationCount(count); >+ // implement deprecated method in terms of getType >+ Type t = getType(); >+ if (t instanceof SimpleType) { >+ // no problem - extract name from SimpleType >+ SimpleType s = (SimpleType) t; >+ return s.getName(); >+ } else if ((t instanceof ParameterizedType) >+ || (t instanceof QualifiedType)) { >+ // compatibility issue >+ // back-level clients know nothing of new node types added in 2.1 >+ // take this opportunity to inform client of problem >+ throw new RuntimeException("Deprecated AST API method cannot handle newer node types"); //$NON-NLS-1$ >+ } else { >+ // compatibility issue >+ // AST is bogus - illegal for type to be array or primitive type >+ // take this opportunity to inform client of problem >+ throw new RuntimeException("Deprecated AST API method cannot handle malformed AST"); //$NON-NLS-1$ > } >- return typeName; > } > > /** >@@ -169,13 +211,64 @@ > * <li>the node belongs to a different AST</li> > * <li>the node already has a parent</li>` > * </ul> >+ * @deprecated Replaced by <code>setType</code>, which expects >+ * a <code>Type</code> instead of a <code>Name</code>. > */ > public void setName(Name name) { >+ // implement deprecated method in terms of get/setType > if (name == null) { > throw new IllegalArgumentException(); > } >- replaceChild(this.typeName, name, false); >- this.typeName = name; >+ Type t = getType(); >+ if (t instanceof SimpleType) { >+ // if possible edit name in SimpleType >+ SimpleType s = (SimpleType) t; >+ s.setName(name); >+ // give type node same range as name node >+ s.setSourceRange(name.getStartPosition(), name.getLength()); >+ // note that only s will be modified(), not the ClassInst node >+ } else { >+ // all other cases - wrap name in a SimpleType and replace superclassType >+ Type newT = getAST().newSimpleType(name); >+ // give new type node same range as name node >+ newT.setSourceRange(name.getStartPosition(), name.getLength()); >+ setType(newT); >+ } >+ } >+ >+ /** >+ * Returns the type instantiated in this class instance creation expression. >+ * >+ * @return the type node >+ * @since 2.2 >+ */ >+ public Type getType() { >+ if (this.type == null) { >+ // lazy initialize - use setter to ensure parent link set too >+ long count = getAST().modificationCount(); >+ setType(new SimpleType(getAST())); >+ getAST().setModificationCount(count); >+ } >+ return this.type; >+ } >+ >+ /** >+ * Sets the type instantiated in this class instance creation expression. >+ * >+ * @param name 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> >+ * @since 2.2 >+ */ >+ public void setType(Type type) { >+ if (type == null) { >+ throw new IllegalArgumentException(); >+ } >+ replaceChild(this.type, type, false); >+ this.type = type; > } > > /** >@@ -243,7 +336,7 @@ > int treeSize() { > return > memSize() >- + (typeName == null ? 0 : getName().treeSize()) >+ + (type == null ? 0 : getName().treeSize()) > + (optionalExpression == null ? 0 : getExpression().treeSize()) > + arguments.listSize() > + (optionalAnonymousClassDeclaration == null ? 0 : getAnonymousClassDeclaration().treeSize()); >Index: dom/org/eclipse/jdt/core/dom/ITypeBinding.java >=================================================================== >RCS file: /data/cvs/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ITypeBinding.java,v >retrieving revision 1.12 >diff -u -r1.12 ITypeBinding.java >--- dom/org/eclipse/jdt/core/dom/ITypeBinding.java 11 Mar 2003 15:03:51 -0000 1.12 >+++ dom/org/eclipse/jdt/core/dom/ITypeBinding.java 14 Apr 2003 19:12:40 -0000 >@@ -13,11 +13,17 @@ > > /** > * A type binding represents a class type, interface type, array type, a >- * primitive type (including the special return type <code>void</code>), or the >- * null type. >+ * primitive type (including the special return type <code>void</code>), the >+ * null type, or a type variable. > * <p> > * This interface is not intended to be implemented by clients. > * </p> >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * </p> > * > * @see ITypeBinding#getDeclaredTypes() > * @since 2.0 >@@ -34,7 +40,8 @@ > * </p> > * <p> > * The set of primitive types is mutually exclusive with the sets of >- * array types, with the sets of class and interface types, and with the null type. >+ * array types, with the sets of class and interface types, with the null >+ * type, and with type variables. > * </p> > * > * @return <code>true</code> if this type binding is for a primitive type, >@@ -53,8 +60,8 @@ > * </p> > * <p> > * The null type is mutually exclusive with the sets of >- * array types, with the sets of class and interface types, and >- * with the set of primitive types . >+ * array types, with the sets of class and interface types, >+ * with the set of primitive types, and with the set of type variables. > * </p> > * > * @return <code>true</code> if this type binding is for the null type, >@@ -66,7 +73,8 @@ > * Returns whether this type binding represents an array type. > * <p> > * The set of array types is mutually exclusive with the sets of >- * primitive types and with the sets of class and interface types. >+ * primitive types, with the sets of class and interface types, >+ * with the null type, and with the set of type variables. > * </p> > * > * @return <code>true</code> if this type binding is for an array type, >@@ -78,6 +86,29 @@ > public boolean isArray(); > > /** >+ * Returns whether this type binding represents a type variable. >+ * <p> >+ * A type variables is declared in <code>TypeParameter</code> node. >+ * </p> >+ * <p> >+ * Type variables are mutually exclusive with the sets of >+ * array types, with the sets of class and interface types, >+ * with the set of primitive types, and with the null type. >+ * </p> >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 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 type binding is for a type variable, >+ * and <code>false</code> otherwise >+ * @since 2.2 >+ */ >+ public boolean isTypeVariable(); >+ >+ /** > * Returns the binding representing the element type of this array type, > * or <code>null</code> if this is not an array type binding. The element > * type of an array is never itself an array type. >@@ -100,7 +131,8 @@ > * Returns whether this type binding represents a class type. > * <p> > * The set of class types is mutually exclusive with the sets of >- * primive types, array types, interface types, and the null type. >+ * primive types, array types, interface types, the null type, >+ * and with the set of type variables. > * </p> > * > * @return <code>true</code> if this object represents a class, >@@ -116,7 +148,8 @@ > * Returns whether this type binding represents an interface type. > * <p> > * The set of interface types is mutually exclusive with the sets of >- * primive types, array types, class types, and the null type. >+ * primive types, array types, class types, the null type, >+ * and with the set of type variables. > * </p> > * > * @return <code>true</code> if this object represents an interface, >@@ -137,6 +170,7 @@ > * If this represents an anonymous class, it returns an empty string (note that > * it is impossible to have an array type with an anonymous class as element type). > * For the null type, it returns "null". >+ * For type variables, this is the name of the type variable. > * </p> > * > * @return the unqualified name of the type represented by this binding, an >@@ -151,7 +185,7 @@ > * > * @return the binding for the package in which this class or interface is > * declared, or <code>null</code> if this type binding represents a >- * primitive type, an array type, or the null type. >+ * primitive type, an array type, the null type, or a type variable > */ > public IPackageBinding getPackage(); > >@@ -163,8 +197,8 @@ > * interface of which it is a member. The declaring class of a local class > * or interface (including anonymous classes) is the innermost class or > * interface containing the expression or statement in which this type is >- * declared. Array types, primitive types, the null type, and top-level types >- * have no declaring class. >+ * declared. Array types, primitive types, the null type, top-level types, >+ * and type variables have no declaring class. > * </p> > * > * @return the binding of the class or interface that declares this type, >@@ -190,7 +224,8 @@ > * </p> > * <p> > * If this type binding represents an interface, an array type, a >- * primitive type, or the null type, then <code>null</code> is returned. >+ * primitive type, the null type, or a type variable, then <code>null</code> >+ * is returned. > * </p> > * > * @return the superclass of the class represented by this type binding, >@@ -219,7 +254,8 @@ > * <p> > * If the class implements no interfaces, or the interface extends no > * interfaces, or if this type binding represents an array type, a >- * primitive type, or the null type, this method returns an array of length 0. >+ * primitive type, the null type, or a type variable, this method returns >+ * an array of length 0. > * </p> > * > * @return the list of type bindings for the interfaces extended by this >@@ -365,8 +401,9 @@ > * protected, default (package-private) access, and private methods. > * Synthetic methods and constructors may or may not be included. Returns > * an empty list if the class or interface declares no methods or >- * constructors, or if this type binding represents an array type or a >- * primitive type. The resulting bindings are in no particular order. >+ * constructors, or if this type binding represents an array type, a >+ * primitive type, the null type, or a type variable. >+ * The resulting bindings are in no particular order. > * > * @return the list of method bindings for the methods and constructors > * declared by this class or interface, or the empty list if this type does >@@ -377,8 +414,8 @@ > /** > * Returns whether this type binding originated in source code. > * Returns <code>false</code> for primitive types, the null type, array types, >- * and classes and interfaces whose information came from a pre-compiled binary >- * class file. >+ * and classes, interfaces, and type variables whose information came from >+ * a pre-compiled binary class file. > * > * @return <code>true</code> if the type is in source code, > * and <code>false</code> otherwise >@@ -409,6 +446,9 @@ > * <li>Local types (including anonymous classes) and members of local > * types do not have a fully qualified name. For these types, and array > * types thereof, this method returns an empty string.</li> >+ * <li>For type variables, the fully qualified name is just the name of the >+ * type variable. >+ * Example: <code>"X"</code>.</li> > * </ul> > * > * @return the fully qualified name of the type represented by this >Index: dom/org/eclipse/jdt/core/dom/MethodDeclaration.java >=================================================================== >RCS file: /data/cvs/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/MethodDeclaration.java,v >retrieving revision 1.24 >diff -u -r1.24 MethodDeclaration.java >--- dom/org/eclipse/jdt/core/dom/MethodDeclaration.java 11 Mar 2003 15:03:51 -0000 1.24 >+++ dom/org/eclipse/jdt/core/dom/MethodDeclaration.java 14 Apr 2003 19:12:41 -0000 >@@ -20,7 +20,9 @@ > * > * <pre> > * MethodDeclaration: >- * [ Javadoc ] { Modifier } ( Type | <b>void</b> ) Identifier <b>(</b> >+ * [ Javadoc ] { Modifier } >+ * [ <b><</b> TypeParameter { <b>,</b> TypeParameter } <b>></b> ] >+ * ( Type | <b>void</b> ) Identifier <b>(</b> > * [ FormalParameter > * { <b>,</b> FormalParameter } ] <b>)</b> {<b>[</b> <b>]</b> } > * [ <b>throws</b> TypeName { <b>,</b> TypeName } ] ( Block | <b>;</b> ) >@@ -35,10 +37,17 @@ > * 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 return type (method, no modifiers), or the >- * first character of the identifier (constructor, no modifiers). >- * The source range extends through the last character of the ";" token (if >- * no body), or the last character of the block (if body). >+ * first character of the "<" token (method, no modifiers, type parameters), >+ * or the first character of the return type (method, no modifiers, no type >+ * parameters), or the first character of the identifier (constructor, >+ * no modifiers). The source range extends through the last character of the >+ * ";" token (if no body), or the last character of the block (if body). >+ * </p> >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 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 >@@ -66,6 +75,14 @@ > private int modifiers = Modifier.NONE; > > /** >+ * The type paramters (element type: <code>TypeParameter</code>). >+ * Defaults to an empty list. >+ * @since 2.2 >+ */ >+ private ASTNode.NodeList typeParameters = >+ new ASTNode.NodeList(false, TypeParameter.class); >+ >+ /** > * The method name; lazily initialized; defaults to an unspecified, > * legal Java identifier. > */ >@@ -109,9 +126,10 @@ > /** > * Creates a new AST node for a method declaration owned > * by the given AST. By default, the declaration is for a method of an >- * unspecified, but legal, name; no modifiers; no javadoc; no parameters; >- * void return type; no array dimensions after the parameters; no thrown >- * exceptions; and no body (as opposed to an empty body). >+ * unspecified, but legal, name; no modifiers; no javadoc; no type >+ * parameters; void return type; no parameters; no array dimensions after >+ * the parameters; no thrown exceptions; and no body (as opposed to an >+ * empty body). > * <p> > * N.B. This constructor is package-private; all subclasses must be > * declared in the same package; clients are unable to declare >@@ -141,6 +159,8 @@ > (Javadoc) ASTNode.copySubtree(target,(ASTNode) getJavadoc())); > result.setModifiers(getModifiers()); > result.setConstructor(isConstructor()); >+ result.typeParameters().addAll( >+ ASTNode.copySubtrees(target, typeParameters())); > result.setReturnType( > (Type) ASTNode.copySubtree(target, getReturnType())); > result.setExtraDimensions(getExtraDimensions()); >@@ -170,6 +190,7 @@ > if (visitChildren) { > // visit children in normal left to right reading order > acceptChild(visitor, getJavadoc()); >+ acceptChildren(visitor, typeParameters); > // n.b. visit return type even for constructors > acceptChild(visitor, getReturnType()); > acceptChild(visitor, getName()); >@@ -234,8 +255,30 @@ > this.modifiers = modifiers; > } > >-// public List<TypeParameter> typeParameters(); // JSR-014 >- >+ /** >+ * Returns the live ordered list of type parameters of this method >+ * declaration. This list is non-empty for parameterized methods. >+ * <p> >+ * Note that these children are not relevant for constructor declarations >+ * (although it does still figure in subtree equality comparisons >+ * and visits), and is devoid of the binding information ordinarily >+ * available. >+ * </p> >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 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 live list of type parameters >+ * (element type: <code>TypeParameter</code>) >+ * @since 2.2 >+ */ >+ public List typeParameters() { >+ return typeParameters; >+ } >+ > /** > * Returns the name of the method declared in this method declaration. > * For a constructor declaration, this should be the same as the name >@@ -467,7 +510,7 @@ > * Method declared on ASTNode. > */ > int memSize() { >- return super.memSize() + 8 * 4; >+ return super.memSize() + 9 * 4; > } > > /* (omit javadoc for this method) >@@ -477,6 +520,7 @@ > return > memSize() > + (getJavadoc() == null ? 0 : getJavadoc().treeSize()) >+ + typeParameters.listSize() > + (methodName == null ? 0 : getName().treeSize()) > + (returnType == null ? 0 : getReturnType().treeSize()) > + parameters.listSize() >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 14 Apr 2003 19:12:42 -0000 >@@ -280,7 +280,7 @@ > buffer.append(".");//$NON-NLS-1$ > } > buffer.append("new ");//$NON-NLS-1$ >- node.getName().accept(this); >+ node.getType().accept(this); > buffer.append("(");//$NON-NLS-1$ > for (Iterator it = node.arguments().iterator(); it.hasNext(); ) { > Expression e = (Expression) it.next(); >@@ -610,6 +610,28 @@ > } > > /* >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * @see ASTVisitor#visit(ParameterizedType) >+ * @since 2.2 >+ */ >+ public boolean visit(ParameterizedType node) { >+ node.getName().accept(this); >+ buffer.append("<");//$NON-NLS-1$ >+ for (Iterator it = node.typeArguments().iterator(); it.hasNext(); ) { >+ Type t = (Type) it.next(); >+ t.accept(this); >+ if (it.hasNext()) { >+ buffer.append(",");//$NON-NLS-1$ >+ } >+ } >+ buffer.append(">");//$NON-NLS-1$ >+ return false; >+ } >+ >+ /* > * @see ASTVisitor#visit(ParenthesizedExpression) > */ > public boolean visit(ParenthesizedExpression node) { >@@ -656,6 +678,17 @@ > } > > /* >+ * @see ASTVisitor#visit(QualifiedType) >+ * @since 2.2 >+ */ >+ public boolean visit(QualifiedType node) { >+ node.getQualifier().accept(this); >+ buffer.append(".");//$NON-NLS-1$ >+ node.getName().accept(this); >+ return false; >+ } >+ >+ /* > * @see ASTVisitor#visit(ReturnStatement) > */ > public boolean visit(ReturnStatement node) { >@@ -851,17 +884,28 @@ > printModifiers(node.getModifiers()); > buffer.append(node.isInterface() ? "interface " : "class ");//$NON-NLS-2$//$NON-NLS-1$ > node.getName().accept(this); >+ if (!node.typeParameters().isEmpty()) { >+ buffer.append("<");//$NON-NLS-1$ >+ for (Iterator it = node.typeParameters().iterator(); it.hasNext(); ) { >+ TypeParameter t = (TypeParameter) it.next(); >+ t.accept(this); >+ if (it.hasNext()) { >+ buffer.append(",");//$NON-NLS-1$ >+ } >+ } >+ buffer.append(">");//$NON-NLS-1$ >+ } > buffer.append(" ");//$NON-NLS-1$ >- if (node.getSuperclass() != null) { >+ if (node.getSuperclassType() != null) { > buffer.append("extends ");//$NON-NLS-1$ >- node.getSuperclass().accept(this); >+ node.getSuperclassType().accept(this); > buffer.append(" ");//$NON-NLS-1$ > } >- if (!node.superInterfaces().isEmpty()) { >+ if (!node.superInterfaceTypes().isEmpty()) { > buffer.append(node.isInterface() ? "extends " : "implements ");//$NON-NLS-2$//$NON-NLS-1$ >- for (Iterator it = node.superInterfaces().iterator(); it.hasNext(); ) { >- Name n = (Name) it.next(); >- n.accept(this); >+ for (Iterator it = node.superInterfaceTypes().iterator(); it.hasNext(); ) { >+ Type t = (Type) it.next(); >+ t.accept(this); > if (it.hasNext()) { > buffer.append(", ");//$NON-NLS-1$ > } >@@ -892,6 +936,29 @@ > public boolean visit(TypeLiteral node) { > node.getType().accept(this); > buffer.append(".class");//$NON-NLS-1$ >+ return false; >+ } >+ >+ /* >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 and under consideration for inclusion >+ * in the 1.5 release of J2SE. The support here is therefore tentative >+ * and subject to change. >+ * @see ASTVisitor#visit(TypeParameter) >+ * @since 2.2 >+ */ >+ public boolean visit(TypeParameter node) { >+ node.getName().accept(this); >+ if (!node.typeBounds().isEmpty()) { >+ buffer.append(" extends ");//$NON-NLS-1$ >+ for (Iterator it = node.typeBounds().iterator(); it.hasNext(); ) { >+ Type t = (Type) it.next(); >+ t.accept(this); >+ if (it.hasNext()) { >+ buffer.append(" & ");//$NON-NLS-1$ >+ } >+ } >+ } > return false; > } > >Index: dom/org/eclipse/jdt/core/dom/ParameterizedType.java >=================================================================== >RCS file: dom/org/eclipse/jdt/core/dom/ParameterizedType.java >diff -N dom/org/eclipse/jdt/core/dom/ParameterizedType.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ dom/org/eclipse/jdt/core/dom/ParameterizedType.java 14 Apr 2003 19:12:42 -0000 >@@ -0,0 +1,162 @@ >+/******************************************************************************* >+ * Copyright (c) 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.List; >+ >+/** >+ * Type node for a parameterized type. >+ * <pre> >+ * ParameterizedType: >+ * Name <b><</b> Type { <b>,</b> Type } <b>></b> >+ * </pre> >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 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 ParameterizedType extends Type { >+ /** >+ * The type name node; lazily initialized; defaults to a type with >+ * an unspecfied, but legal, name. >+ */ >+ private Name typeName = null; >+ >+ /** >+ * The type arguments (element type: <code>Type</code>). >+ * Defaults to an empty list. >+ */ >+ private ASTNode.NodeList typeArguments = >+ new ASTNode.NodeList(true, Type.class); >+ >+ /** >+ * Creates a new unparented node for a parameterized type owned by the >+ * given AST. By default, an unspecified, but legal, name, and no type >+ * arguments. >+ * <p> >+ * N.B. This constructor is package-private. >+ * </p> >+ * >+ * @param ast the AST that is to own this node >+ */ >+ ParameterizedType(AST ast) { >+ super(ast); >+ } >+ >+ /* (omit javadoc for this method) >+ * Method declared on ASTNode. >+ */ >+ public int getNodeType() { >+ return PARAMETERIZED_TYPE; >+ } >+ >+ /* (omit javadoc for this method) >+ * Method declared on ASTNode. >+ */ >+ ASTNode clone(AST target) { >+ ParameterizedType result = new ParameterizedType(target); >+ result.setSourceRange(this.getStartPosition(), this.getLength()); >+ result.setName((Name) ((ASTNode) getName()).clone(target)); >+ result.typeArguments().addAll( >+ ASTNode.copySubtrees(target, typeArguments())); >+ 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, getName()); >+ acceptChildren(visitor, typeArguments); >+ } >+ visitor.endVisit(this); >+ } >+ >+ /** >+ * Returns the name of this parameterized type. >+ * >+ * @return the name of this parameterized type >+ */ >+ public Name getName() { >+ if (typeName == null) { >+ // lazy initialize - use setter to ensure parent link set too >+ long count = getAST().modificationCount(); >+ setName(new SimpleName(getAST())); >+ getAST().setModificationCount(count); >+ } >+ return typeName; >+ } >+ >+ /** >+ * Sets the name of this parameterized type to the given name. >+ * >+ * @param typeName the new name of this parameterized 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 setName(Name typeName) { >+ if (typeName == null) { >+ throw new IllegalArgumentException(); >+ } >+ replaceChild((ASTNode) this.typeName, (ASTNode) typeName, false); >+ this.typeName = typeName; >+ } >+ >+ /** >+ * Returns the live ordered list of type arguments of this parameterized >+ * type. For the parameterized type to be plausible, the list should contain >+ * at least one element and not contain primitive types. >+ * >+ * @return the live list of type arguments >+ * (element type: <code>Type</code>) >+ */ >+ public List typeArguments() { >+ return typeArguments; >+ } >+ >+ /* (omit javadoc for this method) >+ * Method declared on ASTNode. >+ */ >+ int memSize() { >+ // treat Code as free >+ return BASE_NODE_SIZE + 2 * 4; >+ } >+ >+ /* (omit javadoc for this method) >+ * Method declared on ASTNode. >+ */ >+ int treeSize() { >+ return >+ memSize() >+ + (typeName == null ? 0 : getName().treeSize()) >+ + typeArguments.listSize(); >+ } >+} >+ >Index: dom/org/eclipse/jdt/core/dom/QualifiedType.java >=================================================================== >RCS file: dom/org/eclipse/jdt/core/dom/QualifiedType.java >diff -N dom/org/eclipse/jdt/core/dom/QualifiedType.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ dom/org/eclipse/jdt/core/dom/QualifiedType.java 14 Apr 2003 19:12:42 -0000 >@@ -0,0 +1,198 @@ >+/******************************************************************************* >+ * Copyright (c) 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; >+ >+/** >+ * Type node for a qualified type. >+ * <pre> >+ * QualifiedType: >+ * Type <b>.</b> SimpleName >+ * </pre> >+ * <p> >+ * Not all node arragements will represent legal Java constructs. In particular, >+ * it is nonsense if the type is an array type or primitive type. The normal use >+ * is when the type is a simple or parameterized type. >+ * </p> >+ * <p> >+ * A type like "A.B" can be represented either of two ways: >+ * <ol> >+ * <li> >+ * <code>QualifiedType(SimpleType(SimpleName("A")),SimpleName("B"))</code> >+ * </li> >+ * <li> >+ * <code>SimpleType(QualifiedName(SimpleName("A"),SimpleName("B")))</code> >+ * </li> >+ * </ol> >+ * The first form is preferred when "A" is known to be a type. However, a >+ * parser cannot always determine this. Clients should be prepared to handle >+ * either rather than make assumptions. (Note also that the first form >+ * became possible as of 2.2; only the second form existed in 2.0 and 2.1.) >+ * </p> >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 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 QualifiedType extends Type { >+ /** >+ * The type node; lazily initialized; defaults to a type with >+ * an unspecfied, but legal, simple name. >+ */ >+ private Type qualifier = null; >+ >+ /** >+ * The name being qualified; lazily initialized; defaults to a unspecified, >+ * legal Java identifier. >+ */ >+ private SimpleName name = null; >+ >+ /** >+ * Creates a new unparented node for a qualified type owned by the >+ * given AST. By default, an unspecified, but legal, qualifier and name. >+ * <p> >+ * N.B. This constructor is package-private. >+ * </p> >+ * >+ * @param ast the AST that is to own this node >+ */ >+ QualifiedType(AST ast) { >+ super(ast); >+ } >+ >+ /* (omit javadoc for this method) >+ * Method declared on ASTNode. >+ */ >+ public int getNodeType() { >+ return QUALIFIED_TYPE; >+ } >+ >+ /* (omit javadoc for this method) >+ * Method declared on ASTNode. >+ */ >+ ASTNode clone(AST target) { >+ QualifiedType result = new QualifiedType(target); >+ result.setSourceRange(this.getStartPosition(), this.getLength()); >+ result.setQualifier((Type) ((ASTNode) getQualifier()).clone(target)); >+ result.setName((SimpleName) ((ASTNode) getName()).clone(target)); >+ 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, getQualifier()); >+ acceptChild(visitor, getName()); >+ } >+ visitor.endVisit(this); >+ } >+ >+ /** >+ * Returns the qualifier of this qualified type. >+ * >+ * @return the qualifier of this qualified type >+ */ >+ public Type getQualifier() { >+ if (this.qualifier == null) { >+ // lazy initialize - use setter to ensure parent link set too >+ long count = getAST().modificationCount(); >+ setQualifier(new SimpleType(getAST())); >+ getAST().setModificationCount(count); >+ } >+ return this.qualifier; >+ } >+ >+ /** >+ * Sets the qualifier of this qualified type to the given type. >+ * >+ * @param type the new qualifier of this qualified 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 setQualifier(Type type) { >+ if (type == null) { >+ throw new IllegalArgumentException(); >+ } >+ replaceChild(this.qualifier, type, true); >+ this.qualifier = type; >+ } >+ >+ /** >+ * Returns the name part of this qualified type. >+ * >+ * @return the name being qualified >+ */ >+ public SimpleName getName() { >+ if (this.name == null) { >+ // lazy initialize - use setter to ensure parent link set too >+ long count = getAST().modificationCount(); >+ setName(new SimpleName(getAST())); >+ getAST().setModificationCount(count); >+ } >+ return this.name; >+ } >+ >+ /** >+ * Sets the name part of this qualified type to the given simple name. >+ * >+ * @param name the identifier of this qualified 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 name) { >+ if (name == null) { >+ throw new IllegalArgumentException(); >+ } >+ replaceChild(this.name, name, false); >+ this.name = name; >+ } >+ >+ /* (omit javadoc for this method) >+ * Method declared on ASTNode. >+ */ >+ int memSize() { >+ // treat Code as free >+ return BASE_NODE_SIZE + 2 * 4; >+ } >+ >+ /* (omit javadoc for this method) >+ * Method declared on ASTNode. >+ */ >+ int treeSize() { >+ return >+ memSize() >+ + (qualifier == null ? 0 : getQualifier().treeSize()) >+ + (name == null ? 0 : getName().treeSize()); >+ } >+} >+ >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 14 Apr 2003 19:12:43 -0000 >@@ -140,6 +140,8 @@ > * providing <code>isConstructor</code> is <code>false</code>.</li> > * <li>The variable name in any type of <code>VariableDeclaration</code> > * node.</li> >+ * <li>The type variable name in a <code>TypeParameter</code> >+ * node.</li> > * </ul> > * <p> > * Note that this is a convenience method that simply checks whether >@@ -174,6 +176,10 @@ > VariableDeclarationFragment p = (VariableDeclarationFragment) parent; > // make sure its the name of the variable (not the initializer) > return (p.getName() == this); >+ } >+ if (parent instanceof TypeParameter) { >+ // could only be the type variable name >+ return true; > } > return false; > } >Index: dom/org/eclipse/jdt/core/dom/SimpleType.java >=================================================================== >RCS file: /data/cvs/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SimpleType.java,v >retrieving revision 1.12 >diff -u -r1.12 SimpleType.java >--- dom/org/eclipse/jdt/core/dom/SimpleType.java 11 Mar 2003 15:03:51 -0000 1.12 >+++ dom/org/eclipse/jdt/core/dom/SimpleType.java 14 Apr 2003 19:12:43 -0000 >@@ -12,10 +12,16 @@ > package org.eclipse.jdt.core.dom; > > /** >- * Type node for a named class or interface type. >+ * Type node for a named class type, a named interface type, or a type variable. > * <p> > * This kind of node is used to convert a name (<code>Name</code>) into a type > * (<code>Type</code>) by wrapping it. >+ * </p> >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 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 >Index: dom/org/eclipse/jdt/core/dom/Type.java >=================================================================== >RCS file: /data/cvs/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/Type.java,v >retrieving revision 1.4 >diff -u -r1.4 Type.java >--- dom/org/eclipse/jdt/core/dom/Type.java 11 Mar 2003 15:03:51 -0000 1.4 >+++ dom/org/eclipse/jdt/core/dom/Type.java 14 Apr 2003 19:12:43 -0000 >@@ -13,14 +13,17 @@ > > /** > * Abstract base class of all type AST node types. A type node represents a >- * reference to a primitive type (including void), to a named class or >- * interface type, or to an array type. >+ * reference to a primitive type (including void), to an array type, or to a >+ * simple named type (or type variable), to a qualified type, or to a >+ * parameterized type. > * <p> > * <pre> > * Type: > * PrimitiveType >- * SimpleType > * ArrayType >+ * SimpleType >+ * QualifiedType >+ * ParameterizedType > * PrimitiveType: > * <b>byte</b> > * <b>short</b> >@@ -31,12 +34,22 @@ > * <b>double</b> > * <b>boolean</b> > * <b>void</b> >- * SimpleType: >- * TypeName > * ArrayType: > * Type <b>[</b> <b>]</b> >+ * SimpleType: >+ * TypeName >+ * ParameterizedType: >+ * Name <b><</b> Type { <b>,</b> Type } <b>></b> >+ * QualifiedType: >+ * Type <b>.</b> SimpleName > * </pre> > * </p> >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 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 > */ >@@ -88,6 +101,57 @@ > } > > /** >+ * Returns whether this type is a parameterized type >+ * (<code>ParameterizedType</code>). >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 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 parameterized type, and >+ * <code>false</code> otherwise >+ * @since 2.2 >+ */ >+ public final boolean isParameterizedType() { >+ return (this instanceof ParameterizedType); >+ } >+ >+ /** >+ * Returns whether this type is a qualified type >+ * (<code>QualifiedType</code>). >+ * <p> >+ * Note that a type like "A.B" can be represented either of two ways: >+ * <ol> >+ * <li> >+ * <code>QualifiedType(SimpleType(SimpleName("A")),SimpleName("B"))</code> >+ * </li> >+ * <li> >+ * <code>SimpleType(QualifiedName(SimpleName("A"),SimpleName("B")))</code> >+ * </li> >+ * </ol> >+ * The first form is preferred when "A" is known to be a type. However, a >+ * parser cannot always determine this. Clients should be prepared to handle >+ * either rather than make assumptions. (Note also that the first form >+ * became possible as of 2.2; only the second form existed in 2.0 and 2.1.) >+ * </p> >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 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 qualified type, and >+ * <code>false</code> otherwise >+ * @since 2.2 >+ */ >+ public final boolean isQualifiedType() { >+ return (this instanceof QualifiedType); >+ } >+ >+ /** > * Resolves and returns the binding for this type. > * <p> > * Note that bindings are generally unavailable unless requested when the >@@ -100,31 +164,4 @@ > public final ITypeBinding resolveBinding() { > return getAST().getBindingResolver().resolveType(this); > } >- >-// JSR-014 >-// /** >-// * Returns whether this type is a parameterized type >-// * (<code>ParameterizedType</code>). >-// * >-// * @return <code>true</code> if this is a parameterized type, and >-// * <code>false</code> otherwise >-// */ >-// public final boolean isParameterizedType() { >-// return (this instanceof ParameterizedType); >-// } >- >-// public IBinding resolvedType(); >-} >- >-//// JSR-014 >-//public class ParameterizedType extends Type { >-// public ParameterizedType(AST ast) { >-// super(ast); >-// } >-// >-// public Type getGenericType(); >-// public void setGenericType(Type genericType); >-// >-// public NodeList<Type> parameters(); >-//} >- >+} >\ No newline at end of file >Index: dom/org/eclipse/jdt/core/dom/TypeBinding.java >=================================================================== >RCS file: /data/cvs/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeBinding.java,v >retrieving revision 1.21 >diff -u -r1.21 TypeBinding.java >--- dom/org/eclipse/jdt/core/dom/TypeBinding.java 11 Mar 2003 15:03:51 -0000 1.21 >+++ dom/org/eclipse/jdt/core/dom/TypeBinding.java 14 Apr 2003 19:12:44 -0000 >@@ -88,6 +88,14 @@ > } > > /* >+ * @see ITypeBinding#isTypeVariable() >+ */ >+ public boolean isTypeVariable() { >+ // TODO: missing implementation of type variables (JSR-014) >+ throw new RuntimeException("Not implemented yet"); >+ } >+ >+ /* > * @see IBinding#getName() > */ > public String getName() { >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 14 Apr 2003 19:12:44 -0000 >@@ -11,6 +11,7 @@ > > package org.eclipse.jdt.core.dom; > >+import java.util.AbstractList; > import java.util.Iterator; > import java.util.List; > >@@ -24,11 +25,13 @@ > * InterfaceDeclaration > * ClassDeclaration: > * [ Javadoc ] { Modifier } <b>class</b> Identifier >- * [ <b>extends</b> Type] >+ * [ <b><</b> TypeParameter { <b>,</b> TypeParameter } <b>></b> ] >+ * [ <b>extends</b> Type ] > * [ <b>implements</b> Type { <b>,</b> Type } ] > * <b>{</b> { ClassBodyDeclaration | <b>;</b> } <b>}</b> > * InterfaceDeclaration: > * [ Javadoc ] { Modifier } <b>interface</b> Identifier >+ * [ <b><</b> TypeParameter { <b>,</b> TypeParameter } <b>></b> ] > * [ <b>extends</b> Type { <b>,</b> Type } ] > * <b>{</b> { InterfaceBodyDeclaration | <b>;</b> } <b>}</b> > * </pre> >@@ -42,6 +45,12 @@ > * no body), or the last character of the "}" token following the body > * declarations. > * </p> >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 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 > */ >@@ -74,18 +83,28 @@ > private SimpleName typeName = null; > > /** >- * The optional superclass name; <code>null</code> if none. >+ * The type paramters (element type: <code>TypeParameter</code>). >+ * Defaults to an empty list. >+ * @since 2.2 >+ */ >+ private ASTNode.NodeList typeParameters = >+ new ASTNode.NodeList(false, TypeParameter.class); >+ >+ /** >+ * The optional superclass type; <code>null</code> if none. > * Defaults to none. Note that this field is not used for > * interface declarations. >+ * @since 2.2 > */ >- private Name optionalSuperclassName = null; >+ private Type optionalSuperclassType = null; > > /** >- * The superinterface names (element type: <code>Name</code>). >+ * The superinterface types (element type: <code>Type</code>). > * Defaults to an empty list. >+ * @since 2.2 > */ >- private ASTNode.NodeList superInterfaceNames = >- new ASTNode.NodeList(false, Name.class); >+ private ASTNode.NodeList superInterfaceTypes = >+ new ASTNode.NodeList(false, Type.class); > > /** > * The body declarations (element type: <code>BodyDeclaration</code>). >@@ -98,8 +117,8 @@ > * Creates a new AST node for a type declaration owned by the given > * AST. By default, the type declaration is for a class of an > * unspecified, but legal, name; no modifiers; no javadoc; >- * no superclass or superinterfaces; and an empty list of body >- * declarations. >+ * no type parameters; no superclass or superinterfaces; 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 >@@ -130,10 +149,12 @@ > (Javadoc) ASTNode.copySubtree(target,(ASTNode) getJavadoc())); > result.setInterface(isInterface()); > result.setName((SimpleName) getName().clone(target)); >- result.setSuperclass( >- (Name) ASTNode.copySubtree(target,(ASTNode) getSuperclass())); >- result.superInterfaces().addAll( >- ASTNode.copySubtrees(target, superInterfaces())); >+ result.typeParameters().addAll( >+ ASTNode.copySubtrees(target, typeParameters())); >+ result.setSuperclassType( >+ (Type) ASTNode.copySubtree(target,(ASTNode) getSuperclassType())); >+ result.superInterfaceTypes().addAll( >+ ASTNode.copySubtrees(target, superInterfaceTypes())); > result.bodyDeclarations().addAll( > ASTNode.copySubtrees(target, bodyDeclarations())); > return result; >@@ -156,8 +177,9 @@ > // visit children in normal left to right reading order > acceptChild(visitor, getJavadoc()); > acceptChild(visitor, getName()); >- acceptChild(visitor, getSuperclass()); >- acceptChildren(visitor, superInterfaceNames); >+ acceptChildren(visitor, typeParameters); >+ acceptChild(visitor, getSuperclassType()); >+ acceptChildren(visitor, superInterfaceTypes); > acceptChildren(visitor, bodyDeclarations); > } > visitor.endVisit(this); >@@ -257,11 +279,24 @@ > this.typeName = typeName; > } > >-// JSR-014 feature >-// public List<TypeParameter> typeParameters() { >-// throw RuntimeException("not implemented yet"); >-// } >- >+ /** >+ * Returns the live ordered list of type parameters of this type >+ * declaration. This list is non-empty for parameterized types. >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 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 live list of type parameters >+ * (element type: <code>TypeParameter</code>) >+ * @since 2.2 >+ */ >+ public List typeParameters() { >+ return typeParameters; >+ } >+ > /** > * Returns the name of the superclass declared in this type > * declaration, or <code>null</code> if there is none. >@@ -272,9 +307,31 @@ > * > * @return the superclass name node, or <code>null</code> if > * there is none >+ * @deprecated Replaced by <code>getSuperclassType</code>, which returns >+ * a <code>Type</code> instead of a <code>Name</code>. > */ > public Name getSuperclass() { >- return optionalSuperclassName; >+ // implement deprecated method in terms of get/setSuperclassType >+ Type superclassType = getSuperclassType(); >+ if (superclassType == null) { >+ // return null if no superclass type >+ return null; >+ } else if (superclassType instanceof SimpleType) { >+ // no problem - extract name from SimpleType >+ SimpleType t = (SimpleType) superclassType; >+ return t.getName(); >+ } else if ((superclassType instanceof ParameterizedType) >+ || (superclassType instanceof QualifiedType)) { >+ // compatibility issue >+ // back-level clients know nothing of new node types added in 2.1 >+ // take this opportunity to inform client of problem >+ throw new RuntimeException("Deprecated AST API method cannot handle newer node types"); //$NON-NLS-1$ >+ } else { >+ // compatibility issue >+ // AST is bogus - illegal for type to be array or primitive type >+ // take this opportunity to inform client of problem >+ throw new RuntimeException("Deprecated AST API method cannot handle malformed AST"); //$NON-NLS-1$ >+ } > } > > /** >@@ -292,12 +349,72 @@ > * <li>the node belongs to a different AST</li> > * <li>the node already has a parent</li> > * </ul> >+ * @deprecated Replaced by <code>setSuperclassType</code>, which expects >+ * a <code>Type</code> instead of a <code>Name</code>. > */ > public void setSuperclass(Name superclassName) { >- replaceChild( >- (ASTNode) this.optionalSuperclassName, >- (ASTNode) superclassName, false); >- this.optionalSuperclassName = superclassName; >+ // implement deprecated method in terms of get/setSuperclassType >+ if (superclassName == null) { >+ setSuperclassType(null); >+ } else { >+ Type superclassType = getSuperclassType(); >+ if (superclassType instanceof SimpleType) { >+ // if possible edit name in SimpleType >+ SimpleType s = (SimpleType) superclassType; >+ s.setName(superclassName); >+ // give type node same range as name node >+ s.setSourceRange( >+ superclassName.getStartPosition(), >+ superclassName.getLength()); >+ // note that only s will be modified(), not the TypeDecl node >+ } else { >+ // all other cases - wrap name in a SimpleType and replace superclassType >+ Type newT = getAST().newSimpleType(superclassName); >+ // give new type node same range as name node >+ newT.setSourceRange( >+ superclassName.getStartPosition(), >+ superclassName.getLength()); >+ setSuperclassType(newT); >+ } >+ } >+ } >+ >+ /** >+ * Returns 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). >+ * </p> >+ * >+ * @return the superclass type node, or <code>null</code> if >+ * there is none >+ * @since 2.2 >+ */ >+ public Type getSuperclassType() { >+ return this.optionalSuperclassType; >+ } >+ >+ /** >+ * Sets or clears 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). >+ * </p> >+ * >+ * @param superclassType the superclass type node, or <code>null</code> if >+ * there is none >+ * @exception IllegalArgumentException if: >+ * <ul> >+ * <li>the node belongs to a different AST</li> >+ * <li>the node already has a parent</li> >+ * </ul> >+ * @since 2.2 >+ */ >+ public void setSuperclassType(Type superclassType) { >+ replaceChild(this.optionalSuperclassType, superclassType, true); >+ this.optionalSuperclassType = superclassType; > } > > /** >@@ -308,9 +425,126 @@ > * > * @return the live list of interface names > * (element type: <code>Name</code>) >+ * @deprecated Replaced by <code>superInterfaceTypes</code>, which contains >+ * a list of <code>Type</code>s instead of <code>Name</code>s. > */ > public List superInterfaces() { >- return superInterfaceNames; >+ // implement deprecated method in terms of superInterfaceTypes() >+ // return special implementation of List<Name> in terms of List<Type> >+ return new AbstractList() { >+ /** >+ * @see java.util.AbstractCollection#size() >+ */ >+ public int size() { >+ return superInterfaceTypes().size(); >+ } >+ >+ /** >+ * @see AbstractList#get(int) >+ */ >+ public Object get(int index) { >+ Type t = (Type) superInterfaceTypes().get(index); >+ if (t instanceof SimpleType) { >+ // old client reading an old style element >+ SimpleType s = (SimpleType) t; >+ return s.getName(); >+ } else if ((t instanceof ParameterizedType) >+ || (t instanceof QualifiedType)) { >+ // compatibility issue >+ // back-level clients know nothing of new node types added in 2.1 >+ // take this opportunity to inform client of problem >+ throw new RuntimeException("Deprecated AST API method (TypeDeclaration.superinterfaces()) cannot handle newer node types"); //$NON-NLS-1$ >+ } else { >+ // compatibility issue >+ // AST is bogus - illegal for type to be array or primitive type >+ // take this opportunity to inform client of problem >+ throw new RuntimeException("Deprecated AST API method (TypeDeclaration.superinterfaces()) cannot handle malformed AST"); //$NON-NLS-1$ >+ } >+ } >+ >+ /** >+ * @see List#set(int, java.lang.Object) >+ */ >+ public Object set(int index, Object element) { >+ if (!(element instanceof Name)) { >+ throw new IllegalArgumentException(); >+ } >+ Type oldType = (Type) superInterfaceTypes().get(index); >+ Name newName = (Name) element; >+ if (oldType instanceof SimpleType) { >+ // old client operating on old style element >+ SimpleType s = (SimpleType) oldType; >+ Name oldName = s.getName(); >+ if (oldName != element) { >+ s.setName(newName); >+ // give type node same range as name node >+ s.setSourceRange( >+ newName.getStartPosition(), >+ newName.getLength()); >+ } >+ return oldName; >+ } else { >+ // old client replaced a new-fangled element >+ Type newType = getAST().newSimpleType(newName); >+ // give new type node same range as name node >+ newType.setSourceRange( >+ newName.getStartPosition(), >+ newName.getLength()); >+ superInterfaceTypes().set(index, newType); >+ // no choice but to return old new-fangled element >+ return oldType; >+ } >+ } >+ >+ /** >+ * @see List#add(int, java.lang.Object) >+ */ >+ public void add(int index, Object element) { >+ if (!(element instanceof Name)) { >+ throw new IllegalArgumentException(); >+ } >+ Name newName = (Name) element; >+ Type newType = getAST().newSimpleType(newName); >+ // give new type node same range as name node >+ newType.setSourceRange( >+ newName.getStartPosition(), >+ newName.getLength()); >+ superInterfaceTypes().add(index, newType); >+ } >+ >+ /** >+ * @see List#remove(int) >+ */ >+ public Object remove(int index) { >+ Object result = superInterfaceTypes().remove(index); >+ if (result instanceof SimpleType) { >+ // old client operating on old style element >+ SimpleType s = (SimpleType) result; >+ Name oldName = s.getName(); >+ // make sure that oldName has no parent afterwards >+ s.setName(getAST().newSimpleName("deleted")); //$NON-NLS-1$ >+ return oldName; >+ } else { >+ // old client removing a new-fangled element >+ // take a chance that they ignore result >+ return result; >+ } >+ } >+ }; >+ } >+ >+ /** >+ * Returns the live ordered list of superinterfaces of this type >+ * declaration. For a class declaration, these are the interfaces >+ * that this class implements; for an interface declaration, >+ * these are the interfaces that this interface extends. >+ * >+ * @return the live list of interface types >+ * (element type: <code>Type</code>) >+ * @since 2.2 >+ */ >+ public List superInterfaceTypes() { >+ return superInterfaceTypes; > } > > /** >@@ -506,7 +740,7 @@ > * Method declared on ASTNode. > */ > int memSize() { >- return super.memSize() + 6 * 4; >+ return super.memSize() + 7 * 4; > } > > /* (omit javadoc for this method) >@@ -517,8 +751,9 @@ > memSize() > + (getJavadoc() == null ? 0 : getJavadoc().treeSize()) > + (typeName == null ? 0 : getName().treeSize()) >- + (optionalSuperclassName == null ? 0 : getSuperclass().treeSize()) >- + superInterfaceNames.listSize() >+ + typeParameters.listSize() >+ + (optionalSuperclassType == null ? 0 : getSuperclassType().treeSize()) >+ + superInterfaceTypes.listSize() > + bodyDeclarations.listSize(); > } > } >Index: dom/org/eclipse/jdt/core/dom/TypeParameter.java >=================================================================== >RCS file: dom/org/eclipse/jdt/core/dom/TypeParameter.java >diff -N dom/org/eclipse/jdt/core/dom/TypeParameter.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ dom/org/eclipse/jdt/core/dom/TypeParameter.java 14 Apr 2003 19:12:45 -0000 >@@ -0,0 +1,165 @@ >+/******************************************************************************* >+ * Copyright (c) 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.List; >+ >+/** >+ * Type parameter node. >+ * <pre> >+ * TypeParameter: >+ * TypeVariable [ <b>extends</b> Type { <b>&</b> Type } ] >+ * </pre> >+ * <p> >+ * Note: Support for generic types is an experimental language feature >+ * under discussion in JSR-014 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 TypeParameter extends ASTNode { >+ /** >+ * The type variable node; lazily initialized; defaults to an unspecfied, >+ * but legal, name. >+ */ >+ private SimpleName typeVariableName = null; >+ >+ /** >+ * The type bounds (element type: <code>Type</code>). >+ * Defaults to an empty list. >+ */ >+ private ASTNode.NodeList typeBounds = >+ new ASTNode.NodeList(false, Type.class); >+ >+ /** >+ * Creates a new unparented node for a parameterized type owned by the >+ * given AST. By default, an unspecified, but legal, type variable name, >+ * and no type bounds. >+ * <p> >+ * N.B. This constructor is package-private. >+ * </p> >+ * >+ * @param ast the AST that is to own this node >+ */ >+ TypeParameter(AST ast) { >+ super(ast); >+ } >+ >+ /* (omit javadoc for this method) >+ * Method declared on ASTNode. >+ */ >+ public int getNodeType() { >+ return TYPE_PARAMETER; >+ } >+ >+ /* (omit javadoc for this method) >+ * Method declared on ASTNode. >+ */ >+ ASTNode clone(AST target) { >+ TypeParameter result = new TypeParameter(target); >+ result.setSourceRange(this.getStartPosition(), this.getLength()); >+ result.setName((SimpleName) ((ASTNode) getName()).clone(target)); >+ result.typeBounds().addAll( >+ ASTNode.copySubtrees(target, typeBounds())); >+ 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, getName()); >+ acceptChildren(visitor, typeBounds); >+ } >+ visitor.endVisit(this); >+ } >+ >+ /** >+ * Returns the name of the type variable declared in this type parameter. >+ * >+ * @return the name of the type variable >+ */ >+ public SimpleName getName() { >+ if (typeVariableName == null) { >+ // lazy initialize - use setter to ensure parent link set too >+ long count = getAST().modificationCount(); >+ setName(new SimpleName(getAST())); >+ getAST().setModificationCount(count); >+ } >+ return typeVariableName; >+ } >+ >+ /** >+ * Sets the name of the type variable of this type parameter to the given >+ * name. >+ * >+ * @param typeName the new name of this type parameter >+ * @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 typeName) { >+ if (typeName == null) { >+ throw new IllegalArgumentException(); >+ } >+ replaceChild(this.typeVariableName, typeName, false); >+ this.typeVariableName = typeName; >+ } >+ >+ /** >+ * Returns the live ordered list of type bounds of this type parameter. >+ * For the type parameter to be plausible, there can be at most one >+ * class in the list, and it must be first, and the remaining ones must be >+ * interfaces; the list should not contain primitive types (but array types >+ * and parameterized types are allowed). >+ * >+ * @return the live list of type bounds >+ * (element type: <code>Type</code>) >+ */ >+ public List typeBounds() { >+ return typeBounds; >+ } >+ >+ /* (omit javadoc for this method) >+ * Method declared on ASTNode. >+ */ >+ int memSize() { >+ // treat Code as free >+ return BASE_NODE_SIZE + 2 * 4; >+ } >+ >+ /* (omit javadoc for this method) >+ * Method declared on ASTNode. >+ */ >+ int treeSize() { >+ return >+ memSize() >+ + (typeVariableName == null ? 0 : getName().treeSize()) >+ + typeBounds.listSize(); >+ } >+} >+
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 36142
:
4579
|
4580
| 4581