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 18:47:37 -0000
@@ -693,7 +693,7 @@
* type (Type
) by wrapping it.
*
+ * 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. + *
+ * + * @param typeName the name of the class or interface + * @return a new unparented parameterized type node + * @exception IllegalArgumentException if: + *+ * 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. + *
+ * + * @param qualifier the qualifier type node + * @param name the simple name being qualified + * @return a new unparented qualified type node + * @exception IllegalArgumentException if: + *
* To create an interface, use this method and then call
* TypeDeclaration.setInterface(true)
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).
*
* To create a constructor, use this method and then call
* MethodDeclaration.setConstructor(true)
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.
+ *
+ * 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. + *
+ * + * @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 18:47:39 -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. * + *+ * 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. + *
+ * + * @param node the node + * @param other the other object, ornull
+ * @return true
if the subtree matches, or
+ * false
if they do not match or the other object has a
+ * different node type or is null
+ * @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.
+ * + * 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. + *
* * @param node the node * @param other the other object, ornull
@@ -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.
*
+ * + * 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. + *
+ * + * @param node the node + * @param other the other object, ornull
+ * @return true
if the subtree matches, or
+ * false
if they do not match or the other object has a
+ * different node type or is null
+ * @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.
+ * + * 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. + *
* * @param node the node * @param other the other object, ornull
@@ -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.
+ * + * 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. + *
+ *+ * 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. + *
+ * + * @param node the node + * @param other the other object, ornull
+ * @return true
if the subtree matches, or
+ * false
if they do not match or the other object has a
+ * different node type or is null
+ * @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 18:47:42 -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
+ * TypeParameter
.
+ * + * 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 TypeParameter + * @since 2.2 + */ + public static final int TYPE_PARAMETER = 65; + + /** + * Node type constant indicating a node of type + *ParameterizedType
.
+ * + * 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 ParameterizedType + * @since 2.2 + */ + public static final int PARAMETERIZED_TYPE = 66; + + /** + * Node type constant indicating a node of type + *QualifiedType
.
+ * + * 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 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 18:47:43 -0000 @@ -229,6 +229,20 @@ public boolean visit(PackageDeclaration node) { return true; } + + /** Visits the given node. + *+ * 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. + *
+ * + * @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. + *+ * 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. + *
+ * + * @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. + *+ * 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. + *
+ * + * @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. + *+ * 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. + *
+ * + * @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. + *+ * 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. + *
+ * + * @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. + *+ * 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. + *
+ * + * @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 18:47:45 -0000 @@ -18,10 +18,39 @@ * ** ClassInstanceCreation: - * [ Expression . ] new TypeName + * [ Expression . ] new Type * ( [ Expression { , Expression } ] ) * [ AnonymousClassDeclaration ] *+ *
+ * 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
+ * ArrayCreation
nodes). The normal use is when the type is a
+ * simple, qualified, or parameterized type.
+ *
+ * A type like "A.B" can be represented either of two ways: + *
QualifiedType(SimpleType(SimpleName("A")),SimpleName("B"))
+ * SimpleType(QualifiedName(SimpleName("A"),SimpleName("B")))
+ * + * 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. + *
* * @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. *
* 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 getType
, which returns
+ * a Type
instead of a Name
.
*/
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 @@
*
setType
, which expects
+ * a Type
instead of a Name
.
*/
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:
+ * void
), or the
- * null type.
+ * primitive type (including the special return type void
), the
+ * null type, or a type variable.
* * This interface is not intended to be implemented by clients. *
+ *+ * 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 ITypeBinding#getDeclaredTypes() * @since 2.0 @@ -34,7 +40,8 @@ * ** 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. *
* * @returntrue
if this type binding is for a primitive type,
@@ -53,8 +60,8 @@
*
* * 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. *
* * @returntrue
if this type binding is for the null type,
@@ -66,7 +73,8 @@
* Returns whether this type binding represents an array type.
* * 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. *
* * @returntrue
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.
+ *
+ * A type variables is declared in TypeParameter
node.
+ *
+ * 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. + *
+ *+ * 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. + *
+ * + * @returntrue
if this type binding is for a type variable,
+ * and false
otherwise
+ * @since 2.2
+ */
+ public boolean isTypeVariable();
+
+ /**
* Returns the binding representing the element type of this array type,
* or null
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.
* * 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. *
* * @returntrue
if this object represents a class,
@@ -116,7 +148,8 @@
* Returns whether this type binding represents an interface type.
* * 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. *
* * @returntrue
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.
*
*
* @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 null
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.
*
*
* @return the binding of the class or interface that declares this type,
@@ -190,7 +224,8 @@
*
*
* If this type binding represents an interface, an array type, a
- * primitive type, or the null type, then null
is returned.
+ * primitive type, the null type, or a type variable, then null
+ * is returned.
*
* 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. *
* * @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. * Returnsfalse
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 true
if the type is in source code,
* and false
otherwise
@@ -409,6 +446,9 @@
* "X"
.* MethodDeclaration: - * [ Javadoc ] { Modifier } ( Type | void ) Identifier ( + * [ Javadoc ] { Modifier } + * [ < TypeParameter { , TypeParameter } > ] + * ( Type | void ) Identifier ( * [ FormalParameter * { , FormalParameter } ] ) {[ ] } * [ throws TypeName { , TypeName } ] ( Block | ; ) @@ -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). + * + *+ * 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. *
* * @since 2.0 @@ -66,6 +75,14 @@ private int modifiers = Modifier.NONE; /** + * The type paramters (element type:TypeParameter
). + * 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). ** 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
+ *typeParameters(); // JSR-014 - + /** + * Returns the live ordered list of type parameters of this method + * declaration. This list is non-empty for parameterized methods. + * + * 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. + *
+ *+ * 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. + *
+ * + * @return the live list of type parameters + * (element type:TypeParameter
) + * @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 18:47:48 -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 18:47:49 -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. + *+ * ParameterizedType: + * Name < Type { , Type } > + *+ *+ * 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. + *
+ * + * @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:Type
). + * 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. + *+ * N.B. This constructor is package-private. + *
+ * + * @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: + *+ *
+ */ + 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:- the node belongs to a different AST
+ *- the node already has a parent
+ *Type
) + */ + 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 18:47:49 -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. + *+ * QualifiedType: + * Type . SimpleName + *+ *+ * 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. + *
+ *+ * A type like "A.B" can be represented either of two ways: + *
+ *
+ * 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.) + *- + *
+ *QualifiedType(SimpleType(SimpleName("A")),SimpleName("B"))
+ *- + *
+ *SimpleType(QualifiedName(SimpleName("A"),SimpleName("B")))
+ *+ * 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. + *
+ * + * @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. + *+ * N.B. This constructor is package-private. + *
+ * + * @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: + *
isConstructor
is false
.
* VariableDeclaration
* node.TypeParameter
+ * node.* 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 18:47:50 -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. *
* This kind of node is used to convert a name (Name
) into a type
* (Type
) by wrapping it.
+ *
+ * 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. *
* * @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 18:47:50 -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. **
* Type: * PrimitiveType - * SimpleType * ArrayType + * SimpleType + * QualifiedType + * ParameterizedType * PrimitiveType: * byte * short @@ -31,12 +34,22 @@ * double * boolean * void - * SimpleType: - * TypeName * ArrayType: * Type [ ] + * SimpleType: + * TypeName + * ParameterizedType: + * Name < Type { , Type } > + * QualifiedType: + * Type . SimpleName ** + *
+ * 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. + *
* * @since 2.0 */ @@ -88,6 +101,57 @@ } /** + * Returns whether this type is a parameterized type + * (ParameterizedType
).
+ * + * 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. + *
+ * + * @returntrue
if this is a parameterized type, and
+ * false
otherwise
+ * @since 2.2
+ */
+ public final boolean isParameterizedType() {
+ return (this instanceof ParameterizedType);
+ }
+
+ /**
+ * Returns whether this type is a qualified type
+ * (QualifiedType
).
+ * + * Note that a type like "A.B" can be represented either of two ways: + *
QualifiedType(SimpleType(SimpleName("A")),SimpleName("B"))
+ * SimpleType(QualifiedName(SimpleName("A"),SimpleName("B")))
+ * + * 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. + *
+ * + * @returntrue
if this is a qualified type, and
+ * false
otherwise
+ * @since 2.2
+ */
+ public final boolean isQualifiedType() {
+ return (this instanceof QualifiedType);
+ }
+
+ /**
* Resolves and returns the binding for this type.
*
* 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
-// * (ParameterizedType
).
-// *
-// * @return true
if this is a parameterized type, and
-// * false
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
+ * 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. + *
* * @since 2.0 */ @@ -74,18 +83,28 @@ private SimpleName typeName = null; /** - * The optional superclass name;null
if none.
+ * The type paramters (element type: TypeParameter
).
+ * Defaults to an empty list.
+ * @since 2.2
+ */
+ private ASTNode.NodeList typeParameters =
+ new ASTNode.NodeList(false, TypeParameter.class);
+
+ /**
+ * The optional superclass type; null
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: Name
).
+ * The superinterface types (element type: Type
).
* 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: BodyDeclaration
).
@@ -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.
*
* 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
+ * 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.
+ *
+ * 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 declarations
+ * (although it does still figure in subtree equality comparisons).
+ *
+ * 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.
+ *
+ * N.B. This constructor is package-private.
+ * TypeParameter
)
+ * @since 2.2
+ */
+ public List typeParameters() {
+ return typeParameters;
+ }
+
/**
* Returns the name of the superclass declared in this type
* declaration, or null
if there is none.
@@ -272,9 +307,31 @@
*
* @return the superclass name node, or null
if
* there is none
+ * @deprecated Replaced by getSuperclassType
, which returns
+ * a Type
instead of a Name
.
*/
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 @@
* setSuperclassType
, which expects
+ * a Type
instead of a Name
.
*/
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 null
if there is none.
+ * null
if
+ * there is none
+ * @since 2.2
+ */
+ public Type getSuperclassType() {
+ return this.optionalSuperclassType;
+ }
+
+ /**
+ * Sets or clears the superclass declared in this type
+ * declaration.
+ * null
if
+ * there is none
+ * @exception IllegalArgumentException if:
+ *
+ *
+ * @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: Name
)
+ * @deprecated Replaced by superInterfaceTypes
, which contains
+ * a list of Type
s instead of Name
s.
*/
public List superInterfaces() {
- return superInterfaceNames;
+ // implement deprecated method in terms of superInterfaceTypes()
+ // return special implementation of ListType
)
+ * @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 18:47:52 -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.
+ *
+ * TypeParameter:
+ * TypeVariable [ extends Type { & Type } ]
+ *
+ * Type
).
+ * 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.
+ *
+ *
+ */
+ 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: Type
)
+ */
+ 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();
+ }
+}
+