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

Collapse All | Expand All

(-)dom/org/eclipse/jdt/core/dom/AST.java (-7 / +77 lines)
Lines 693-699 Link Here
693
	 * type (<code>Type</code>) by wrapping it.
693
	 * type (<code>Type</code>) by wrapping it.
694
	 * </p>
694
	 * </p>
695
	 * 
695
	 * 
696
	 * @param typeName the name of the class or interface
696
	 * @param typeName the name of the class, interface, or type variable
697
	 * @return a new unparented simple type node
697
	 * @return a new unparented simple type node
698
	 * @exception IllegalArgumentException if:
698
	 * @exception IllegalArgumentException if:
699
	 * <ul>
699
	 * <ul>
Lines 776-781 Link Here
776
		return result;
776
		return result;
777
	}
777
	}
778
778
779
	/**
780
	 * Creates and returns a new unparented parameterized type node with the
781
	 * given type name and an empty list of type arguments.
782
	 * <p>
783
	 * Note: Support for generic types is an experimental language feature 
784
	 * under discussion in JSR-014 and under consideration for inclusion
785
	 * in the 1.5 release of J2SE. The support here is therefore tentative
786
	 * and subject to change.
787
	 * </p>
788
	 * 
789
	 * @param typeName the name of the class or interface
790
	 * @return a new unparented parameterized type node
791
	 * @exception IllegalArgumentException if:
792
	 * <ul>
793
	 * <li>the node belongs to a different AST</li>
794
	 * <li>the node already has a parent</li>
795
	 * </ul>
796
	 * @since 2.2
797
	 */
798
	public ParameterizedType newParameterizedType(Name typeName) {
799
		ParameterizedType result = new ParameterizedType(this);
800
		result.setName(typeName);
801
		return result;
802
	}
803
804
	/**
805
	 * Creates and returns a new unparented qualified type node with 
806
	 * the given qualifier type and name.
807
	 * <p>
808
	 * Note: Support for generic types is an experimental language feature 
809
	 * under discussion in JSR-014 and under consideration for inclusion
810
	 * in the 1.5 release of J2SE. The support here is therefore tentative
811
	 * and subject to change.
812
	 * </p>
813
	 * 
814
	 * @param qualifier the qualifier type node
815
	 * @param name the simple name being qualified
816
	 * @return a new unparented qualified type node
817
	 * @exception IllegalArgumentException if:
818
	 * <ul>
819
	 * <li>the node belongs to a different AST</li>
820
	 * <li>the node already has a parent</li>
821
	 * </ul>
822
	 * @since 2.2
823
	 */
824
	public QualifiedType newQualifiedType(Type qualifier, SimpleName name) {
825
		QualifiedType result = new QualifiedType(this);
826
		result.setQualifier(qualifier);
827
		result.setName(name);
828
		return result;
829
	}
830
779
	//=============================== DECLARATIONS ===========================
831
	//=============================== DECLARATIONS ===========================
780
	/**
832
	/**
781
	 * Creates an unparented compilation unit node owned by this AST.
833
	 * Creates an unparented compilation unit node owned by this AST.
Lines 830-837 Link Here
830
	/**
882
	/**
831
	 * Creates an unparented class declaration node owned by this AST.
883
	 * Creates an unparented class declaration node owned by this AST.
832
	 * The name of the class is an unspecified, but legal, name; 
884
	 * The name of the class is an unspecified, but legal, name; 
833
	 * no modifiers; no Javadoc comment; no superclass or superinterfaces; 
885
	 * no modifiers; no type parameters; no Javadoc comment; no superclass 
834
	 * and an empty class body.
886
	 * or superinterfaces;  and an empty class body.
835
	 * <p>
887
	 * <p>
836
	 * To create an interface, use this method and then call
888
	 * To create an interface, use this method and then call
837
	 * <code>TypeDeclaration.setInterface(true)</code> and
889
	 * <code>TypeDeclaration.setInterface(true)</code> and
Lines 848-856 Link Here
848
	/**
900
	/**
849
	 * Creates an unparented method declaration node owned by this AST.
901
	 * Creates an unparented method declaration node owned by this AST.
850
	 * By default, the declaration is for a method of an unspecified, but 
902
	 * By default, the declaration is for a method of an unspecified, but 
851
	 * legal, name; no modifiers; no Javadoc comment; no parameters; return
903
	 * legal, name; no modifiers; no Javadoc comment; no type parameters; 
852
	 * type void; no extra array dimensions; no thrown exceptions; and no
904
	 * return type void; no parameters; no extra array dimensions; 
853
	 * body (as opposed to an empty body).
905
	 * no thrown exceptions; and no body (as opposed to an empty body).
854
	 * <p>
906
	 * <p>
855
	 * To create a constructor, use this method and then call
907
	 * To create a constructor, use this method and then call
856
	 * <code>MethodDeclaration.setConstructor(true)</code> and
908
	 * <code>MethodDeclaration.setConstructor(true)</code> and
Lines 913-918 Link Here
913
		return result;
965
		return result;
914
	}
966
	}
915
	
967
	
968
	/**
969
	 * Creates and returns a new unparented type parameter type node with an
970
	 * unspecified type variable name and an empty list of type bounds.
971
	 * <p>
972
	 * Note: Support for generic types is an experimental language feature 
973
	 * under discussion in JSR-014 and under consideration for inclusion
974
	 * in the 1.5 release of J2SE. The support here is therefore tentative
975
	 * and subject to change.
976
	 * </p>
977
	 * 
978
	 * @return a new unparented type parameter node
979
	 * @since 2.2
980
	 */
981
	public TypeParameter newTypeParameter() {
982
		TypeParameter result = new TypeParameter(this);
983
		return result;
984
	}
985
916
	//=============================== STATEMENTS ===========================
986
	//=============================== STATEMENTS ===========================
917
	/**
987
	/**
918
	 * Creates a new unparented local variable declaration statement node 
988
	 * Creates a new unparented local variable declaration statement node 
Lines 1569-1575 Link Here
1569
	/**
1639
	/**
1570
	 * Creates and returns a new unparented class instance creation 
1640
	 * Creates and returns a new unparented class instance creation 
1571
	 * ("new") expression node owned by this AST. By default, 
1641
	 * ("new") expression node owned by this AST. By default, 
1572
	 * there is no qualifying expression, an unspecified (but legal) type name,
1642
	 * there is no qualifying expression, an unspecified type,
1573
	 * an empty list of arguments, and does not declare an anonymous
1643
	 * an empty list of arguments, and does not declare an anonymous
1574
	 * class declaration.
1644
	 * class declaration.
1575
	 * 
1645
	 * 
(-)dom/org/eclipse/jdt/core/dom/ASTMatcher.java (-4 / +97 lines)
Lines 455-461 Link Here
455
		ClassInstanceCreation o = (ClassInstanceCreation) other;
455
		ClassInstanceCreation o = (ClassInstanceCreation) other;
456
		return (
456
		return (
457
			safeSubtreeMatch(node.getExpression(), o.getExpression())
457
			safeSubtreeMatch(node.getExpression(), o.getExpression())
458
				&& safeSubtreeMatch(node.getName(), o.getName())
458
				&& safeSubtreeMatch(node.getType(), o.getType())
459
				&& safeSubtreeListMatch(node.arguments(), o.arguments())
459
				&& safeSubtreeListMatch(node.arguments(), o.arguments())
460
				&& safeSubtreeMatch(
460
				&& safeSubtreeMatch(
461
					node.getAnonymousClassDeclaration(),
461
					node.getAnonymousClassDeclaration(),
Lines 907-913 Link Here
907
			(node.getModifiers() == o.getModifiers())
907
			(node.getModifiers() == o.getModifiers())
908
				&& (node.isConstructor() == o.isConstructor())
908
				&& (node.isConstructor() == o.isConstructor())
909
				&& safeSubtreeMatch(node.getJavadoc(), o.getJavadoc())
909
				&& safeSubtreeMatch(node.getJavadoc(), o.getJavadoc())
910
				// n.b. compare return type even for constructors
910
				// n.b. compare type parameters and return type even for constructors
911
				&& safeSubtreeListMatch(node.typeParameters(), o.typeParameters())
911
				&& safeSubtreeMatch(node.getReturnType(), o.getReturnType())
912
				&& safeSubtreeMatch(node.getReturnType(), o.getReturnType())
912
				&& safeSubtreeMatch(node.getName(), o.getName())
913
				&& safeSubtreeMatch(node.getName(), o.getName())
913
				&& safeSubtreeListMatch(node.parameters(), o.parameters())
914
				&& safeSubtreeListMatch(node.parameters(), o.parameters())
Lines 1013-1018 Link Here
1013
	 * other object is a node of the same type with structurally isomorphic
1014
	 * other object is a node of the same type with structurally isomorphic
1014
	 * child subtrees. Subclasses may override this method as needed.
1015
	 * child subtrees. Subclasses may override this method as needed.
1015
	 * </p>
1016
	 * </p>
1017
	 * <p>
1018
	 * Note: Support for generic types is an experimental language feature 
1019
	 * under discussion in JSR-014 and under consideration for inclusion
1020
	 * in the 1.5 release of J2SE. The support here is therefore tentative
1021
	 * and subject to change.
1022
	 * </p>
1023
	 * 
1024
	 * @param node the node
1025
	 * @param other the other object, or <code>null</code>
1026
	 * @return <code>true</code> if the subtree matches, or 
1027
	 *   <code>false</code> if they do not match or the other object has a
1028
	 *   different node type or is <code>null</code>
1029
	 * @since 2.2
1030
	 */
1031
	public boolean match(ParameterizedType node, Object other) {
1032
		if (!(other instanceof ParameterizedType)) {
1033
			return false;
1034
		}
1035
		ParameterizedType o = (ParameterizedType) other;
1036
		return safeSubtreeMatch(node.getName(), o.getName())
1037
				&& safeSubtreeListMatch(node.typeArguments(), o.typeArguments());
1038
	}
1039
1040
	/**
1041
	 * Returns whether the given node and the other object match.
1042
	 * <p>
1043
	 * The default implementation provided by this class tests whether the
1044
	 * other object is a node of the same type with structurally isomorphic
1045
	 * child subtrees. Subclasses may override this method as needed.
1046
	 * </p>
1016
	 * 
1047
	 * 
1017
	 * @param node the node
1048
	 * @param node the node
1018
	 * @param other the other object, or <code>null</code>
1049
	 * @param other the other object, or <code>null</code>
Lines 1129-1134 Link Here
1129
	 * other object is a node of the same type with structurally isomorphic
1160
	 * other object is a node of the same type with structurally isomorphic
1130
	 * child subtrees. Subclasses may override this method as needed.
1161
	 * child subtrees. Subclasses may override this method as needed.
1131
	 * </p>
1162
	 * </p>
1163
	 * <p>
1164
	 * Note: Support for generic types is an experimental language feature 
1165
	 * under discussion in JSR-014 and under consideration for inclusion
1166
	 * in the 1.5 release of J2SE. The support here is therefore tentative
1167
	 * and subject to change.
1168
	 * </p>
1169
	 * 
1170
	 * @param node the node
1171
	 * @param other the other object, or <code>null</code>
1172
	 * @return <code>true</code> if the subtree matches, or 
1173
	 *   <code>false</code> if they do not match or the other object has a
1174
	 *   different node type or is <code>null</code>
1175
	 * @since 2.2
1176
	 */
1177
	public boolean match(QualifiedType node, Object other) {
1178
		if (!(other instanceof QualifiedType)) {
1179
			return false;
1180
		}
1181
		QualifiedType o = (QualifiedType) other;
1182
		return (
1183
			safeSubtreeMatch(node.getQualifier(), o.getQualifier())
1184
				&& safeSubtreeMatch(node.getName(), o.getName()));
1185
	}
1186
1187
	/**
1188
	 * Returns whether the given node and the other object match.
1189
	 * <p>
1190
	 * The default implementation provided by this class tests whether the
1191
	 * other object is a node of the same type with structurally isomorphic
1192
	 * child subtrees. Subclasses may override this method as needed.
1193
	 * </p>
1132
	 * 
1194
	 * 
1133
	 * @param node the node
1195
	 * @param node the node
1134
	 * @param other the other object, or <code>null</code>
1196
	 * @param other the other object, or <code>null</code>
Lines 1477-1484 Link Here
1477
				&& (node.isInterface() == o.isInterface())
1539
				&& (node.isInterface() == o.isInterface())
1478
				&& safeSubtreeMatch(node.getJavadoc(), o.getJavadoc())
1540
				&& safeSubtreeMatch(node.getJavadoc(), o.getJavadoc())
1479
				&& safeSubtreeMatch(node.getName(), o.getName())
1541
				&& safeSubtreeMatch(node.getName(), o.getName())
1480
				&& safeSubtreeMatch(node.getSuperclass(), o.getSuperclass())
1542
				&& safeSubtreeListMatch(node.typeParameters(), o.typeParameters())
1481
				&& safeSubtreeListMatch(node.superInterfaces(), o.superInterfaces())
1543
				&& safeSubtreeMatch(node.getSuperclassType(), o.getSuperclassType())
1544
				&& safeSubtreeListMatch(node.superInterfaceTypes(), o.superInterfaceTypes())
1482
				&& safeSubtreeListMatch(node.bodyDeclarations(), o.bodyDeclarations()));
1545
				&& safeSubtreeListMatch(node.bodyDeclarations(), o.bodyDeclarations()));
1483
	}
1546
	}
1484
1547
Lines 1524-1529 Link Here
1524
		}
1587
		}
1525
		TypeLiteral o = (TypeLiteral) other;
1588
		TypeLiteral o = (TypeLiteral) other;
1526
		return safeSubtreeMatch(node.getType(), o.getType());
1589
		return safeSubtreeMatch(node.getType(), o.getType());
1590
	}
1591
1592
	/**
1593
	 * Returns whether the given node and the other object match.
1594
	 * <p>
1595
	 * The default implementation provided by this class tests whether the
1596
	 * other object is a node of the same type with structurally isomorphic
1597
	 * child subtrees. Subclasses may override this method as needed.
1598
	 * </p>
1599
	 * <p>
1600
	 * Note: Support for generic types is an experimental language feature 
1601
	 * under discussion in JSR-014 and under consideration for inclusion
1602
	 * in the 1.5 release of J2SE. The support here is therefore tentative
1603
	 * and subject to change.
1604
	 * </p>
1605
	 * 
1606
	 * @param node the node
1607
	 * @param other the other object, or <code>null</code>
1608
	 * @return <code>true</code> if the subtree matches, or 
1609
	 *   <code>false</code> if they do not match or the other object has a
1610
	 *   different node type or is <code>null</code>
1611
	 * @since 2.2
1612
	 */
1613
	public boolean match(TypeParameter node, Object other) {
1614
		if (!(other instanceof TypeParameter)) {
1615
			return false;
1616
		}
1617
		TypeParameter o = (TypeParameter) other;
1618
		return safeSubtreeMatch(node.getName(), o.getName())
1619
				&& safeSubtreeListMatch(node.typeBounds(), o.typeBounds());
1527
	}
1620
	}
1528
1621
1529
	/**
1622
	/**
(-)dom/org/eclipse/jdt/core/dom/ASTNode.java (+54 lines)
Lines 549-554 Link Here
549
	public static final int INSTANCEOF_EXPRESSION = 62;
549
	public static final int INSTANCEOF_EXPRESSION = 62;
550
550
551
	/**
551
	/**
552
	 * Reserved for experimental JSR-201 constructs.
553
	 * @since 2.2
554
	 */
555
	private static final int RESERVED_1 = 63;
556
557
	/**
558
	 * Reserved for experimental JSR-201 constructs.
559
	 * @since 2.2
560
	 */
561
	private static final int RESERVED_2 = 64;
562
563
	/**
564
	 * Node type constant indicating a node of type 
565
	 * <code>TypeParameter</code>.
566
	 * <p>
567
	 * Note: Support for generic types is an experimental language feature 
568
	 * under discussion in JSR-014 and under consideration for inclusion
569
	 * in the 1.5 release of J2SE. The support here is therefore tentative
570
	 * and subject to change.
571
	 * </p>
572
	 * @see TypeParameter
573
	 * @since 2.2
574
	 */
575
	public static final int TYPE_PARAMETER = 65;
576
577
	/**
578
	 * Node type constant indicating a node of type 
579
	 * <code>ParameterizedType</code>.
580
	 * <p>
581
	 * Note: Support for generic types is an experimental language feature 
582
	 * under discussion in JSR-014 and under consideration for inclusion
583
	 * in the 1.5 release of J2SE. The support here is therefore tentative
584
	 * and subject to change.
585
	 * </p>
586
	 * @see ParameterizedType
587
	 * @since 2.2
588
	 */
589
	public static final int PARAMETERIZED_TYPE = 66;
590
591
	/**
592
	 * Node type constant indicating a node of type 
593
	 * <code>QualifiedType</code>.
594
	 * <p>
595
	 * Note: Support for generic types is an experimental language feature 
596
	 * under discussion in JSR-014 and under consideration for inclusion
597
	 * in the 1.5 release of J2SE. The support here is therefore tentative
598
	 * and subject to change.
599
	 * </p>
600
	 * @see QualifiedType
601
	 * @since 2.2
602
	 */
603
	public static final int QUALIFIED_TYPE = 67;
604
605
	/**
552
	 * Owning AST.
606
	 * Owning AST.
553
	 */
607
	 */
554
	private final AST owner;
608
	private final AST owner;
(-)dom/org/eclipse/jdt/core/dom/ASTVisitor.java (+76 lines)
Lines 229-234 Link Here
229
	public boolean visit(PackageDeclaration node) {
229
	public boolean visit(PackageDeclaration node) {
230
		return true;
230
		return true;
231
	}
231
	}
232
233
	/** Visits the given node.
234
	 * <p>
235
	 * Note: Support for generic types is an experimental language feature 
236
	 * under discussion in JSR-014 and under consideration for inclusion
237
	 * in the 1.5 release of J2SE. The support here is therefore tentative
238
	 * and subject to change.
239
	 * </p>
240
	 * 
241
	 * @since 2.2
242
	 */
243
	public boolean visit(ParameterizedType node) {
244
		return true;
245
	}
232
	public boolean visit(ParenthesizedExpression node) {
246
	public boolean visit(ParenthesizedExpression node) {
233
		return true;
247
		return true;
234
	}
248
	}
Lines 244-249 Link Here
244
	public boolean visit(QualifiedName node) {
258
	public boolean visit(QualifiedName node) {
245
		return true;
259
		return true;
246
	}
260
	}
261
	/** Visits the given node.
262
	 * <p>
263
	 * Note: Support for generic types is an experimental language feature 
264
	 * under discussion in JSR-014 and under consideration for inclusion
265
	 * in the 1.5 release of J2SE. The support here is therefore tentative
266
	 * and subject to change.
267
	 * </p>
268
	 * 
269
	 * @since 2.2
270
	 */
271
	public boolean visit(QualifiedType node) {
272
		return true;
273
	}
247
	public boolean visit(ReturnStatement node) {
274
	public boolean visit(ReturnStatement node) {
248
		return true;
275
		return true;
249
	}
276
	}
Lines 292-297 Link Here
292
	public boolean visit(TypeLiteral node) {
319
	public boolean visit(TypeLiteral node) {
293
		return true;
320
		return true;
294
	}
321
	}
322
	/** Visits the given node.
323
	 * <p>
324
	 * Note: Support for generic types is an experimental language feature 
325
	 * under discussion in JSR-014 and under consideration for inclusion
326
	 * in the 1.5 release of J2SE. The support here is therefore tentative
327
	 * and subject to change.
328
	 * </p>
329
	 * 
330
	 * @since 2.2
331
	 */
332
	public boolean visit(TypeParameter node) {
333
		return true;
334
	}
295
	public boolean visit(SingleVariableDeclaration node) {
335
	public boolean visit(SingleVariableDeclaration node) {
296
		return true;
336
		return true;
297
	}
337
	}
Lines 380-385 Link Here
380
	}
420
	}
381
	public void endVisit(PackageDeclaration node) {
421
	public void endVisit(PackageDeclaration node) {
382
	}
422
	}
423
	/** Ends visit of the given node.
424
	 * <p>
425
	 * Note: Support for generic types is an experimental language feature 
426
	 * under discussion in JSR-014 and under consideration for inclusion
427
	 * in the 1.5 release of J2SE. The support here is therefore tentative
428
	 * and subject to change.
429
	 * </p>
430
	 * 
431
	 * @since 2.2
432
	 */
433
	public void endVisit(ParameterizedType node) {
434
	}
383
	public void endVisit(ParenthesizedExpression node) {
435
	public void endVisit(ParenthesizedExpression node) {
384
	}
436
	}
385
	public void endVisit(PostfixExpression node) {
437
	public void endVisit(PostfixExpression node) {
Lines 390-395 Link Here
390
	}
442
	}
391
	public void endVisit(QualifiedName node) {
443
	public void endVisit(QualifiedName node) {
392
	}
444
	}
445
	/** Ends visit of the given node.
446
	 * <p>
447
	 * Note: Support for generic types is an experimental language feature 
448
	 * under discussion in JSR-014 and under consideration for inclusion
449
	 * in the 1.5 release of J2SE. The support here is therefore tentative
450
	 * and subject to change.
451
	 * </p>
452
	 * 
453
	 * @since 2.2
454
	 */
455
	public void endVisit(QualifiedType node) {
456
	}
393
	public void endVisit(ReturnStatement node) {
457
	public void endVisit(ReturnStatement node) {
394
	}
458
	}
395
	public void endVisit(SimpleName node) {
459
	public void endVisit(SimpleName node) {
Lines 421-426 Link Here
421
	public void endVisit(TypeDeclarationStatement node) {
485
	public void endVisit(TypeDeclarationStatement node) {
422
	}
486
	}
423
	public void endVisit(TypeLiteral node) {
487
	public void endVisit(TypeLiteral node) {
488
	}
489
	/** Ends visit of the given node.
490
	 * <p>
491
	 * Note: Support for generic types is an experimental language feature 
492
	 * under discussion in JSR-014 and under consideration for inclusion
493
	 * in the 1.5 release of J2SE. The support here is therefore tentative
494
	 * and subject to change.
495
	 * </p>
496
	 * 
497
	 * @since 2.2
498
	 */
499
	public void endVisit(TypeParameter node) {
424
	}
500
	}
425
	public void endVisit(SingleVariableDeclaration node) {
501
	public void endVisit(SingleVariableDeclaration node) {
426
	}
502
	}
(-)dom/org/eclipse/jdt/core/dom/ClassInstanceCreation.java (-16 / +109 lines)
Lines 18-27 Link Here
18
 *
18
 *
19
 * <pre>
19
 * <pre>
20
 * ClassInstanceCreation:
20
 * ClassInstanceCreation:
21
 *        [ Expression <b>.</b> ] <b>new</b> TypeName
21
 *        [ Expression <b>.</b> ] <b>new</b> Type
22
 *            <b>(</b> [ Expression { <b>,</b> Expression } ] <b>)</b>
22
 *            <b>(</b> [ Expression { <b>,</b> Expression } ] <b>)</b>
23
 *            [ AnonymousClassDeclaration ]
23
 *            [ AnonymousClassDeclaration ]
24
 * </pre>
24
 * </pre>
25
 * <p>
26
 * Not all node arragements will represent legal Java constructs. In particular,
27
 * it is nonsense if the type is a primitive type or an array type (primitive
28
 * types cannot be instantiated, and array creations must be represented with
29
 * <code>ArrayCreation</code> nodes). The normal use is when the type is a
30
 * simple, qualified, or parameterized type.
31
 * </p>
32
 * <p>
33
 * A type like "A.B" can be represented either of two ways:
34
 * <ol>
35
 * <li>
36
 * <code>QualifiedType(SimpleType(SimpleName("A")),SimpleName("B"))</code>
37
 * </li>
38
 * <li>
39
 * <code>SimpleType(QualifiedName(SimpleName("A"),SimpleName("B")))</code>
40
 * </li>
41
 * </ol>
42
 * The first form is preferred when "A" is known to be a type (as opposed
43
 * to a package). However, a parser cannot always determine this. Clients
44
 * should be prepared to handle either rather than make assumptions.
45
 * (Note also that the first form became possible as of 2.2; only the second
46
 * form existed in 2.0 and 2.1.)
47
 * </p>
48
 * <p>
49
 * Note: Support for generic types is an experimental language feature 
50
 * under discussion in JSR-014 and under consideration for inclusion
51
 * in the 1.5 release of J2SE. The support here is therefore tentative
52
 * and subject to change.
53
 * </p>
25
 * 
54
 * 
26
 * @since 2.0
55
 * @since 2.0
27
 */
56
 */
Lines 33-42 Link Here
33
	private Expression optionalExpression = null;
62
	private Expression optionalExpression = null;
34
	
63
	
35
	/**
64
	/**
36
	 * The type name; lazily initialized; defaults to a unspecified,
65
	 * The type; lazily initialized; defaults to a unspecified type.
37
	 * legal type name.
66
	 * @since 2.2
38
	 */
67
	 */
39
	private Name typeName = null;
68
	private Type type = null;
40
	
69
	
41
	/**
70
	/**
42
	 * The list of argument expressions (element type: 
71
	 * The list of argument expressions (element type: 
Lines 54-60 Link Here
54
	/**
83
	/**
55
	 * Creates a new AST node for a class instance creation expression owned 
84
	 * Creates a new AST node for a class instance creation expression owned 
56
	 * by the given AST. By default, there is no qualifying expression,
85
	 * by the given AST. By default, there is no qualifying expression,
57
	 * an unspecified (but legal) type name, an empty list of arguments,
86
	 * an unspecified type, an empty list of arguments,
58
	 * and does not declare an anonymous class.
87
	 * and does not declare an anonymous class.
59
	 * <p>
88
	 * <p>
60
	 * N.B. This constructor is package-private; all subclasses must be 
89
	 * N.B. This constructor is package-private; all subclasses must be 
Lines 83-89 Link Here
83
		result.setSourceRange(this.getStartPosition(), this.getLength());
112
		result.setSourceRange(this.getStartPosition(), this.getLength());
84
		result.setExpression(
113
		result.setExpression(
85
			(Expression) ASTNode.copySubtree(target, getExpression()));
114
			(Expression) ASTNode.copySubtree(target, getExpression()));
86
		result.setName((Name) getName().clone(target));
115
		result.setType((Type) getType().clone(target));
87
		result.arguments().addAll(ASTNode.copySubtrees(target, arguments()));
116
		result.arguments().addAll(ASTNode.copySubtrees(target, arguments()));
88
		result.setAnonymousClassDeclaration(
117
		result.setAnonymousClassDeclaration(
89
			(AnonymousClassDeclaration) 
118
			(AnonymousClassDeclaration) 
Lines 107-113 Link Here
107
		if (visitChildren) {
136
		if (visitChildren) {
108
			// visit children in normal left to right reading order
137
			// visit children in normal left to right reading order
109
			acceptChild(visitor, getExpression());
138
			acceptChild(visitor, getExpression());
110
			acceptChild(visitor, getName());
139
			acceptChild(visitor, getType());
111
			acceptChildren(visitor, arguments);
140
			acceptChildren(visitor, arguments);
112
			acceptChild(visitor, getAnonymousClassDeclaration());
141
			acceptChild(visitor, getAnonymousClassDeclaration());
113
		}
142
		}
Lines 148-162 Link Here
148
	 * creation expression.
177
	 * creation expression.
149
	 * 
178
	 * 
150
	 * @return the type name node
179
	 * @return the type name node
180
	 * @deprecated Replaced by <code>getType</code>, which returns
181
	 * a <code>Type</code> instead of a <code>Name</code>.
151
	 */ 
182
	 */ 
152
	public Name getName() {
183
	public Name getName() {
153
		if (typeName == null) {
184
		// implement deprecated method in terms of getType
154
			// lazy initialize - use setter to ensure parent link set too
185
		Type t = getType();
155
			long count = getAST().modificationCount();
186
		if (t instanceof SimpleType) {
156
			setName(new SimpleName(getAST()));
187
			// no problem - extract name from SimpleType
157
			getAST().setModificationCount(count);
188
			SimpleType s = (SimpleType) t;
189
			return s.getName();
190
		} else if ((t instanceof ParameterizedType)
191
			     || (t instanceof QualifiedType)) {
192
			// compatibility issue
193
			// back-level clients know nothing of new node types added in 2.1
194
			// take this opportunity to inform client of problem
195
			throw new RuntimeException("Deprecated AST API method cannot handle newer node types"); //$NON-NLS-1$
196
		} else {
197
			// compatibility issue
198
			// AST is bogus - illegal for type to be array or primitive type
199
			// take this opportunity to inform client of problem
200
			throw new RuntimeException("Deprecated AST API method cannot handle malformed AST"); //$NON-NLS-1$
158
		}
201
		}
159
		return typeName;
160
	}
202
	}
161
	
203
	
162
	/**
204
	/**
Lines 169-181 Link Here
169
	 * <li>the node belongs to a different AST</li>
211
	 * <li>the node belongs to a different AST</li>
170
	 * <li>the node already has a parent</li>`
212
	 * <li>the node already has a parent</li>`
171
	 * </ul>
213
	 * </ul>
214
	 * @deprecated Replaced by <code>setType</code>, which expects
215
	 * a <code>Type</code> instead of a <code>Name</code>.
172
	 */ 
216
	 */ 
173
	public void setName(Name name) {
217
	public void setName(Name name) {
218
		// implement deprecated method in terms of get/setType
174
		if (name == null) {
219
		if (name == null) {
175
			throw new IllegalArgumentException();
220
			throw new IllegalArgumentException();
176
		}
221
		}
177
		replaceChild(this.typeName, name, false);
222
		Type t = getType();
178
		this.typeName = name;
223
		if (t instanceof SimpleType) {
224
			// if possible edit name in SimpleType
225
			SimpleType s = (SimpleType) t;
226
			s.setName(name);
227
			// give type node same range as name node
228
			s.setSourceRange(name.getStartPosition(), name.getLength());
229
			// note that only s will be modified(), not the ClassInst node
230
		} else {
231
			// all other cases - wrap name in a SimpleType and replace superclassType
232
			Type newT = getAST().newSimpleType(name);
233
			// give new type node same range as name node
234
			newT.setSourceRange(name.getStartPosition(), name.getLength());
235
			setType(newT);
236
		}
237
	}
238
239
	/**
240
	 * Returns the type instantiated in this class instance creation expression.
241
	 * 
242
	 * @return the type node
243
	 * @since 2.2
244
	 */ 
245
	public Type getType() {
246
		if (this.type == null) {
247
			// lazy initialize - use setter to ensure parent link set too
248
			long count = getAST().modificationCount();
249
			setType(new SimpleType(getAST()));
250
			getAST().setModificationCount(count);
251
		}
252
		return this.type;
253
	}
254
	
255
	/**
256
	 * Sets the type instantiated in this class instance creation expression.
257
	 * 
258
	 * @param name the new type
259
	 * @exception IllegalArgumentException if:
260
	 * <ul>
261
	 * <li>the node belongs to a different AST</li>
262
	 * <li>the node already has a parent</li>`
263
	 * </ul>
264
	 * @since 2.2
265
	 */ 
266
	public void setType(Type type) {
267
		if (type == null) {
268
			throw new IllegalArgumentException();
269
		}
270
		replaceChild(this.type, type, false);
271
		this.type = type;
179
	}
272
	}
180
273
181
	/**
274
	/**
Lines 243-249 Link Here
243
	int treeSize() {
336
	int treeSize() {
244
		return 
337
		return 
245
			memSize()
338
			memSize()
246
			+ (typeName == null ? 0 : getName().treeSize())
339
			+ (type == null ? 0 : getName().treeSize())
247
			+ (optionalExpression == null ? 0 : getExpression().treeSize())
340
			+ (optionalExpression == null ? 0 : getExpression().treeSize())
248
			+ arguments.listSize()
341
			+ arguments.listSize()
249
			+ (optionalAnonymousClassDeclaration == null ? 0 : getAnonymousClassDeclaration().treeSize());
342
			+ (optionalAnonymousClassDeclaration == null ? 0 : getAnonymousClassDeclaration().treeSize());
(-)dom/org/eclipse/jdt/core/dom/ITypeBinding.java (-17 / +57 lines)
Lines 13-23 Link Here
13
13
14
/**
14
/**
15
 * A type binding represents a class type, interface type, array type, a 
15
 * A type binding represents a class type, interface type, array type, a 
16
 * primitive type (including the special return type <code>void</code>), or the
16
 * primitive type (including the special return type <code>void</code>), the
17
 * null type.
17
 * null type, or a type variable.
18
 * <p>
18
 * <p>
19
 * This interface is not intended to be implemented by clients.
19
 * This interface is not intended to be implemented by clients.
20
 * </p>
20
 * </p>
21
 * <p>
22
 * Note: Support for generic types is an experimental language feature 
23
 * under discussion in JSR-014 and under consideration for inclusion
24
 * in the 1.5 release of J2SE. The support here is therefore tentative
25
 * and subject to change.
26
 * </p>
21
 * 
27
 * 
22
 * @see ITypeBinding#getDeclaredTypes()
28
 * @see ITypeBinding#getDeclaredTypes()
23
 * @since 2.0
29
 * @since 2.0
Lines 34-40 Link Here
34
	 * </p>
40
	 * </p>
35
	 * <p>
41
	 * <p>
36
	 * The set of primitive types is mutually exclusive with the sets of
42
	 * The set of primitive types is mutually exclusive with the sets of
37
	 * array types, with the sets of class and interface types, and with the null type.
43
	 * array types, with the sets of class and interface types, with the null
44
	 * type, and with type variables.
38
	 * </p>
45
	 * </p>
39
	 * 
46
	 * 
40
	 * @return <code>true</code> if this type binding is for a primitive type,
47
	 * @return <code>true</code> if this type binding is for a primitive type,
Lines 53-60 Link Here
53
	 * </p>
60
	 * </p>
54
	 * <p>
61
	 * <p>
55
	 * The null type is mutually exclusive with the sets of
62
	 * The null type is mutually exclusive with the sets of
56
	 * array types, with the sets of class and interface types, and 
63
	 * array types, with the sets of class and interface types,
57
	 * with the set of primitive types .
64
	 * with the set of primitive types, and with the set of type variables.
58
	 * </p>
65
	 * </p>
59
	 * 
66
	 * 
60
	 * @return <code>true</code> if this type binding is for the null type,
67
	 * @return <code>true</code> if this type binding is for the null type,
Lines 66-72 Link Here
66
	 * Returns whether this type binding represents an array type.
73
	 * Returns whether this type binding represents an array type.
67
	 * <p>
74
	 * <p>
68
	 * The set of array types is mutually exclusive with the sets of
75
	 * The set of array types is mutually exclusive with the sets of
69
	 * primitive types and with the sets of class and interface types.
76
	 * primitive types, with the sets of class and interface types, 
77
	 * with the null type, and with the set of type variables.
70
	 * </p>
78
	 * </p>
71
	 *
79
	 *
72
	 * @return <code>true</code> if this type binding is for an array type,
80
	 * @return <code>true</code> if this type binding is for an array type,
Lines 78-83 Link Here
78
	public boolean isArray();
86
	public boolean isArray();
79
	
87
	
80
	/**
88
	/**
89
	 * Returns whether this type binding represents a type variable.
90
	 * <p>
91
	 * A type variables is declared in <code>TypeParameter</code> node.
92
	 * </p>
93
	 * <p>
94
	 * Type variables are mutually exclusive with the sets of
95
	 * array types, with the sets of class and interface types,
96
	 * with the set of primitive types, and with the null type.
97
	 * </p>
98
	 * <p>
99
	 * Note: Support for generic types is an experimental language feature 
100
	 * under discussion in JSR-014 and under consideration for inclusion
101
	 * in the 1.5 release of J2SE. The support here is therefore tentative
102
	 * and subject to change.
103
	 * </p>
104
	 * 
105
	 * @return <code>true</code> if this type binding is for a type variable,
106
	 *   and <code>false</code> otherwise
107
	 * @since 2.2
108
	 */
109
	public boolean isTypeVariable();
110
	
111
	/**
81
	 * Returns the binding representing the element type of this array type,
112
	 * Returns the binding representing the element type of this array type,
82
	 * or <code>null</code> if this is not an array type binding. The element
113
	 * or <code>null</code> if this is not an array type binding. The element
83
	 * type of an array is never itself an array type.
114
	 * type of an array is never itself an array type.
Lines 100-106 Link Here
100
	 * Returns whether this type binding represents a class type.
131
	 * Returns whether this type binding represents a class type.
101
	 * <p>
132
	 * <p>
102
	 * The set of class types is mutually exclusive with the sets of
133
	 * The set of class types is mutually exclusive with the sets of
103
	 * primive types, array types, interface types, and the null type.
134
	 * primive types, array types, interface types, the null type,
135
	 * and with the set of type variables.
104
	 * </p>
136
	 * </p>
105
	 *
137
	 *
106
	 * @return <code>true</code> if this object represents a class,
138
	 * @return <code>true</code> if this object represents a class,
Lines 116-122 Link Here
116
	 * Returns whether this type binding represents an interface type.
148
	 * Returns whether this type binding represents an interface type.
117
	 * <p>
149
	 * <p>
118
	 * The set of interface types is mutually exclusive with the sets of
150
	 * The set of interface types is mutually exclusive with the sets of
119
	 * primive types, array types, class types, and the null type.
151
	 * primive types, array types, class types, the null type, 
152
	 * and with the set of type variables.
120
	 * </p>
153
	 * </p>
121
	 *
154
	 *
122
	 * @return <code>true</code> if this object represents an interface,
155
	 * @return <code>true</code> if this object represents an interface,
Lines 137-142 Link Here
137
	 * If this represents an anonymous class, it returns an empty string (note that
170
	 * If this represents an anonymous class, it returns an empty string (note that
138
	 * it is impossible to have an array type with an anonymous class as element type).
171
	 * it is impossible to have an array type with an anonymous class as element type).
139
	 * For the null type, it returns "null".
172
	 * For the null type, it returns "null".
173
	 * For type variables, this is the name of the type variable.
140
	 * </p>
174
	 * </p>
141
	 * 
175
	 * 
142
	 * @return the unqualified name of the type represented by this binding, an
176
	 * @return the unqualified name of the type represented by this binding, an
Lines 151-157 Link Here
151
	 * 
185
	 * 
152
	 * @return the binding for the package in which this class or interface is
186
	 * @return the binding for the package in which this class or interface is
153
	 *   declared, or <code>null</code> if this type binding represents a 
187
	 *   declared, or <code>null</code> if this type binding represents a 
154
	 *   primitive type, an array type, or the null type.
188
	 *   primitive type, an array type, the null type, or a type variable
155
	 */
189
	 */
156
	public IPackageBinding getPackage();
190
	public IPackageBinding getPackage();
157
	
191
	
Lines 163-170 Link Here
163
	 * interface of which it is a member. The declaring class of a local class
197
	 * interface of which it is a member. The declaring class of a local class
164
	 * or interface (including anonymous classes) is the innermost class or
198
	 * or interface (including anonymous classes) is the innermost class or
165
	 * interface containing the expression or statement in which this type is
199
	 * interface containing the expression or statement in which this type is
166
	 * declared. Array types, primitive types, the null type, and top-level types 
200
	 * declared. Array types, primitive types, the null type, top-level types,
167
	 * have no declaring class.
201
	 * and type variables have no declaring class.
168
	 * </p>
202
	 * </p>
169
	 * 
203
	 * 
170
	 * @return the binding of the class or interface that declares this type,
204
	 * @return the binding of the class or interface that declares this type,
Lines 190-196 Link Here
190
	 * </p>
224
	 * </p>
191
	 * <p>
225
	 * <p>
192
	 * If this type binding represents an interface, an array type, a
226
	 * If this type binding represents an interface, an array type, a
193
	 * primitive type, or the null type, then <code>null</code> is returned. 
227
	 * primitive type, the null type, or a type variable, then <code>null</code>
228
	 * is returned. 
194
	 * </p>
229
	 * </p>
195
	 *
230
	 *
196
	 * @return the superclass of the class represented by this type binding,
231
	 * @return the superclass of the class represented by this type binding,
Lines 219-225 Link Here
219
	 * <p>
254
	 * <p>
220
	 * If the class implements no interfaces, or the interface extends no 
255
	 * If the class implements no interfaces, or the interface extends no 
221
	 * interfaces, or if this type binding represents an array type, a
256
	 * interfaces, or if this type binding represents an array type, a
222
	 * primitive type, or the null type, this method returns an array of length 0.
257
	 * primitive type, the null type, or a type variable, this method returns
258
	 * an array of length 0.
223
	 * </p>
259
	 * </p>
224
	 *
260
	 *
225
	 * @return the list of type bindings for the interfaces extended by this
261
	 * @return the list of type bindings for the interfaces extended by this
Lines 365-372 Link Here
365
	 * protected, default (package-private) access, and private methods. 
401
	 * protected, default (package-private) access, and private methods. 
366
	 * Synthetic methods and constructors may or may not be included. Returns
402
	 * Synthetic methods and constructors may or may not be included. Returns
367
	 * an empty list if the class or interface declares no methods or 
403
	 * an empty list if the class or interface declares no methods or 
368
	 * constructors, or if this type binding represents an array type or a
404
	 * constructors, or if this type binding represents an array type, a
369
	 * primitive type. The resulting bindings are in no particular order.
405
	 * primitive type, the null type, or a type variable. 
406
	 * The resulting bindings are in no particular order.
370
	 * 
407
	 * 
371
	 * @return the list of method bindings for the methods and constructors
408
	 * @return the list of method bindings for the methods and constructors
372
	 *   declared by this class or interface, or the empty list if this type does
409
	 *   declared by this class or interface, or the empty list if this type does
Lines 377-384 Link Here
377
	/**
414
	/**
378
	 * Returns whether this type binding originated in source code.
415
	 * Returns whether this type binding originated in source code.
379
	 * Returns <code>false</code> for primitive types, the null type, array types,
416
	 * Returns <code>false</code> for primitive types, the null type, array types,
380
	 * and classes and interfaces whose information came from a pre-compiled binary
417
	 * and classes, interfaces, and type variables whose information came from
381
	 * class file.
418
	 * a pre-compiled binary class file.
382
	 * 
419
	 * 
383
	 * @return <code>true</code> if the type is in source code,
420
	 * @return <code>true</code> if the type is in source code,
384
	 *    and <code>false</code> otherwise
421
	 *    and <code>false</code> otherwise
Lines 409-414 Link Here
409
	 * <li>Local types (including anonymous classes) and members of local
446
	 * <li>Local types (including anonymous classes) and members of local
410
	 * types do not have a fully qualified name. For these types, and array
447
	 * types do not have a fully qualified name. For these types, and array
411
	 * types thereof, this method returns an empty string.</li>
448
	 * types thereof, this method returns an empty string.</li>
449
	 * <li>For type variables, the fully qualified name is just the name of the
450
	 * type variable.
451
	 * Example: <code>"X"</code>.</li>
412
	 * </ul>
452
	 * </ul>
413
	 * 
453
	 * 
414
	 * @return the fully qualified name of the type represented by this 
454
	 * @return the fully qualified name of the type represented by this 
(-)dom/org/eclipse/jdt/core/dom/MethodDeclaration.java (-11 / +55 lines)
Lines 20-26 Link Here
20
 *
20
 *
21
 * <pre>
21
 * <pre>
22
 * MethodDeclaration:
22
 * MethodDeclaration:
23
 *    [ Javadoc ] { Modifier } ( Type | <b>void</b> ) Identifier <b>(</b>
23
 *    [ Javadoc ] { Modifier }
24
 *		  [ <b>&lt;</b> TypeParameter { <b>,</b> TypeParameter } <b>&gt;</b> ]
25
 *        ( Type | <b>void</b> ) Identifier <b>(</b>
24
 *        [ FormalParameter 
26
 *        [ FormalParameter 
25
 * 		     { <b>,</b> FormalParameter } ] <b>)</b> {<b>[</b> <b>]</b> }
27
 * 		     { <b>,</b> FormalParameter } ] <b>)</b> {<b>[</b> <b>]</b> }
26
 *        [ <b>throws</b> TypeName { <b>,</b> TypeName } ] ( Block | <b>;</b> )
28
 *        [ <b>throws</b> TypeName { <b>,</b> TypeName } ] ( Block | <b>;</b> )
Lines 35-44 Link Here
35
 * range begins with the first character of the "/**" comment delimiter.
37
 * range begins with the first character of the "/**" comment delimiter.
36
 * When there is no Javadoc comment, the source range begins with the first
38
 * When there is no Javadoc comment, the source range begins with the first
37
 * character of the first modifier keyword (if modifiers), or the
39
 * character of the first modifier keyword (if modifiers), or the
38
 * first character of the return type (method, no modifiers), or the
40
 * first character of the "&lt;" token (method, no modifiers, type parameters), 
39
 * first character of the identifier (constructor, no modifiers).
41
 * or the first character of the return type (method, no modifiers, no type
40
 * The source range extends through the last character of the ";" token (if
42
 * parameters), or the first character of the identifier (constructor, 
41
 * no body), or the last character of the block (if body).
43
 * no modifiers). The source range extends through the last character of the
44
 * ";" token (if no body), or the last character of the block (if body).
45
 * </p>
46
 * <p>
47
 * Note: Support for generic types is an experimental language feature 
48
 * under discussion in JSR-014 and under consideration for inclusion
49
 * in the 1.5 release of J2SE. The support here is therefore tentative
50
 * and subject to change.
42
 * </p>
51
 * </p>
43
 *
52
 *
44
 * @since 2.0 
53
 * @since 2.0 
Lines 66-71 Link Here
66
	private int modifiers = Modifier.NONE;
75
	private int modifiers = Modifier.NONE;
67
	
76
	
68
	/**
77
	/**
78
	 * The type paramters (element type: <code>TypeParameter</code>). 
79
	 * Defaults to an empty list.
80
	 * @since 2.2
81
	 */
82
	private ASTNode.NodeList typeParameters =
83
		new ASTNode.NodeList(false, TypeParameter.class);
84
85
	/**
69
	 * The method name; lazily initialized; defaults to an unspecified,
86
	 * The method name; lazily initialized; defaults to an unspecified,
70
	 * legal Java identifier.
87
	 * legal Java identifier.
71
	 */
88
	 */
Lines 109-117 Link Here
109
	/**
126
	/**
110
	 * Creates a new AST node for a method declaration owned 
127
	 * Creates a new AST node for a method declaration owned 
111
	 * by the given AST. By default, the declaration is for a method of an
128
	 * by the given AST. By default, the declaration is for a method of an
112
	 * unspecified, but legal, name; no modifiers; no javadoc; no parameters; 
129
	 * unspecified, but legal, name; no modifiers; no javadoc; no type 
113
	 * void return type; no array dimensions after the parameters; no thrown
130
	 * parameters; void return type; no parameters; no array dimensions after 
114
	 * exceptions; and no body (as opposed to an empty body).
131
	 * the parameters; no thrown exceptions; and no body (as opposed to an
132
	 * empty body).
115
	 * <p>
133
	 * <p>
116
	 * N.B. This constructor is package-private; all subclasses must be 
134
	 * N.B. This constructor is package-private; all subclasses must be 
117
	 * declared in the same package; clients are unable to declare 
135
	 * declared in the same package; clients are unable to declare 
Lines 141-146 Link Here
141
			(Javadoc) ASTNode.copySubtree(target,(ASTNode) getJavadoc()));
159
			(Javadoc) ASTNode.copySubtree(target,(ASTNode) getJavadoc()));
142
		result.setModifiers(getModifiers());
160
		result.setModifiers(getModifiers());
143
		result.setConstructor(isConstructor());
161
		result.setConstructor(isConstructor());
162
		result.typeParameters().addAll(
163
			ASTNode.copySubtrees(target, typeParameters()));
144
		result.setReturnType(
164
		result.setReturnType(
145
			(Type) ASTNode.copySubtree(target, getReturnType()));
165
			(Type) ASTNode.copySubtree(target, getReturnType()));
146
		result.setExtraDimensions(getExtraDimensions());
166
		result.setExtraDimensions(getExtraDimensions());
Lines 170-175 Link Here
170
		if (visitChildren) {
190
		if (visitChildren) {
171
			// visit children in normal left to right reading order
191
			// visit children in normal left to right reading order
172
			acceptChild(visitor, getJavadoc());
192
			acceptChild(visitor, getJavadoc());
193
			acceptChildren(visitor, typeParameters);
173
			// n.b. visit return type even for constructors
194
			// n.b. visit return type even for constructors
174
			acceptChild(visitor, getReturnType());
195
			acceptChild(visitor, getReturnType());
175
			acceptChild(visitor, getName());
196
			acceptChild(visitor, getName());
Lines 234-241 Link Here
234
		this.modifiers = modifiers;
255
		this.modifiers = modifiers;
235
	}
256
	}
236
257
237
//	public List<TypeParameter> typeParameters(); // JSR-014
258
	/**
238
259
	 * Returns the live ordered list of type parameters of this method
260
	 * declaration. This list is non-empty for parameterized methods.
261
	 * <p>
262
	 * Note that these children are not relevant for constructor declarations
263
	 * (although it does still figure in subtree equality comparisons
264
	 * and visits), and is devoid of the binding information ordinarily
265
	 * available.
266
	 * </p>
267
	 * <p>
268
	 * Note: Support for generic types is an experimental language feature 
269
	 * under discussion in JSR-014 and under consideration for inclusion
270
	 * in the 1.5 release of J2SE. The support here is therefore tentative
271
	 * and subject to change.
272
	 * </p>
273
	 * 
274
	 * @return the live list of type parameters
275
	 *    (element type: <code>TypeParameter</code>)
276
	 * @since 2.2
277
	 */ 
278
	public List typeParameters() {
279
		return typeParameters;
280
	}
281
	
239
	/**
282
	/**
240
	 * Returns the name of the method declared in this method declaration.
283
	 * Returns the name of the method declared in this method declaration.
241
	 * For a constructor declaration, this should be the same as the name 
284
	 * For a constructor declaration, this should be the same as the name 
Lines 467-473 Link Here
467
	 * Method declared on ASTNode.
510
	 * Method declared on ASTNode.
468
	 */
511
	 */
469
	int memSize() {
512
	int memSize() {
470
		return super.memSize() + 8 * 4;
513
		return super.memSize() + 9 * 4;
471
	}
514
	}
472
	
515
	
473
	/* (omit javadoc for this method)
516
	/* (omit javadoc for this method)
Lines 477-482 Link Here
477
		return
520
		return
478
			memSize()
521
			memSize()
479
			+ (getJavadoc() == null ? 0 : getJavadoc().treeSize())
522
			+ (getJavadoc() == null ? 0 : getJavadoc().treeSize())
523
			+ typeParameters.listSize()
480
			+ (methodName == null ? 0 : getName().treeSize())
524
			+ (methodName == null ? 0 : getName().treeSize())
481
			+ (returnType == null ? 0 : getReturnType().treeSize())
525
			+ (returnType == null ? 0 : getReturnType().treeSize())
482
			+ parameters.listSize()
526
			+ parameters.listSize()
(-)dom/org/eclipse/jdt/core/dom/NaiveASTFlattener.java (-7 / +74 lines)
Lines 280-286 Link Here
280
			buffer.append(".");//$NON-NLS-1$
280
			buffer.append(".");//$NON-NLS-1$
281
		}
281
		}
282
		buffer.append("new ");//$NON-NLS-1$
282
		buffer.append("new ");//$NON-NLS-1$
283
		node.getName().accept(this);
283
		node.getType().accept(this);
284
		buffer.append("(");//$NON-NLS-1$
284
		buffer.append("(");//$NON-NLS-1$
285
		for (Iterator it = node.arguments().iterator(); it.hasNext(); ) {
285
		for (Iterator it = node.arguments().iterator(); it.hasNext(); ) {
286
			Expression e = (Expression) it.next();
286
			Expression e = (Expression) it.next();
Lines 610-615 Link Here
610
	}
610
	}
611
611
612
	/*
612
	/*
613
	 * Note: Support for generic types is an experimental language feature 
614
	 * under discussion in JSR-014 and under consideration for inclusion
615
	 * in the 1.5 release of J2SE. The support here is therefore tentative
616
	 * and subject to change.
617
	 * @see ASTVisitor#visit(ParameterizedType)
618
	 * @since 2.2
619
	 */
620
	public boolean visit(ParameterizedType node) {
621
		node.getName().accept(this);
622
		buffer.append("<");//$NON-NLS-1$
623
		for (Iterator it = node.typeArguments().iterator(); it.hasNext(); ) {
624
			Type t = (Type) it.next();
625
			t.accept(this);
626
			if (it.hasNext()) {
627
				buffer.append(",");//$NON-NLS-1$
628
			}
629
		}
630
		buffer.append(">");//$NON-NLS-1$
631
		return false;
632
	}
633
634
	/*
613
	 * @see ASTVisitor#visit(ParenthesizedExpression)
635
	 * @see ASTVisitor#visit(ParenthesizedExpression)
614
	 */
636
	 */
615
	public boolean visit(ParenthesizedExpression node) {
637
	public boolean visit(ParenthesizedExpression node) {
Lines 656-661 Link Here
656
	}
678
	}
657
679
658
	/*
680
	/*
681
	 * @see ASTVisitor#visit(QualifiedType)
682
	 * @since 2.2
683
	 */
684
	public boolean visit(QualifiedType node) {
685
		node.getQualifier().accept(this);
686
		buffer.append(".");//$NON-NLS-1$
687
		node.getName().accept(this);
688
		return false;
689
	}
690
691
	/*
659
	 * @see ASTVisitor#visit(ReturnStatement)
692
	 * @see ASTVisitor#visit(ReturnStatement)
660
	 */
693
	 */
661
	public boolean visit(ReturnStatement node) {
694
	public boolean visit(ReturnStatement node) {
Lines 851-867 Link Here
851
		printModifiers(node.getModifiers());
884
		printModifiers(node.getModifiers());
852
		buffer.append(node.isInterface() ? "interface " : "class ");//$NON-NLS-2$//$NON-NLS-1$
885
		buffer.append(node.isInterface() ? "interface " : "class ");//$NON-NLS-2$//$NON-NLS-1$
853
		node.getName().accept(this);
886
		node.getName().accept(this);
887
		if (!node.typeParameters().isEmpty()) {
888
			buffer.append("<");//$NON-NLS-1$
889
			for (Iterator it = node.typeParameters().iterator(); it.hasNext(); ) {
890
				TypeParameter t = (TypeParameter) it.next();
891
				t.accept(this);
892
				if (it.hasNext()) {
893
					buffer.append(",");//$NON-NLS-1$
894
				}
895
			}
896
			buffer.append(">");//$NON-NLS-1$
897
		}
854
		buffer.append(" ");//$NON-NLS-1$
898
		buffer.append(" ");//$NON-NLS-1$
855
		if (node.getSuperclass() != null) {
899
		if (node.getSuperclassType() != null) {
856
			buffer.append("extends ");//$NON-NLS-1$
900
			buffer.append("extends ");//$NON-NLS-1$
857
			node.getSuperclass().accept(this);
901
			node.getSuperclassType().accept(this);
858
			buffer.append(" ");//$NON-NLS-1$
902
			buffer.append(" ");//$NON-NLS-1$
859
		}
903
		}
860
		if (!node.superInterfaces().isEmpty()) {
904
		if (!node.superInterfaceTypes().isEmpty()) {
861
			buffer.append(node.isInterface() ? "extends " : "implements ");//$NON-NLS-2$//$NON-NLS-1$
905
			buffer.append(node.isInterface() ? "extends " : "implements ");//$NON-NLS-2$//$NON-NLS-1$
862
			for (Iterator it = node.superInterfaces().iterator(); it.hasNext(); ) {
906
			for (Iterator it = node.superInterfaceTypes().iterator(); it.hasNext(); ) {
863
				Name n = (Name) it.next();
907
				Type t = (Type) it.next();
864
				n.accept(this);
908
				t.accept(this);
865
				if (it.hasNext()) {
909
				if (it.hasNext()) {
866
					buffer.append(", ");//$NON-NLS-1$
910
					buffer.append(", ");//$NON-NLS-1$
867
				}
911
				}
Lines 892-897 Link Here
892
	public boolean visit(TypeLiteral node) {
936
	public boolean visit(TypeLiteral node) {
893
		node.getType().accept(this);
937
		node.getType().accept(this);
894
		buffer.append(".class");//$NON-NLS-1$
938
		buffer.append(".class");//$NON-NLS-1$
939
		return false;
940
	}
941
942
	/*
943
	 * Note: Support for generic types is an experimental language feature 
944
	 * under discussion in JSR-014 and under consideration for inclusion
945
	 * in the 1.5 release of J2SE. The support here is therefore tentative
946
	 * and subject to change.
947
	 * @see ASTVisitor#visit(TypeParameter)
948
	 * @since 2.2
949
	 */
950
	public boolean visit(TypeParameter node) {
951
		node.getName().accept(this);
952
		if (!node.typeBounds().isEmpty()) {
953
			buffer.append(" extends ");//$NON-NLS-1$
954
			for (Iterator it = node.typeBounds().iterator(); it.hasNext(); ) {
955
				Type t = (Type) it.next();
956
				t.accept(this);
957
				if (it.hasNext()) {
958
					buffer.append(" & ");//$NON-NLS-1$
959
				}
960
			}
961
		}
895
		return false;
962
		return false;
896
	}
963
	}
897
964
(-)dom/org/eclipse/jdt/core/dom/ParameterizedType.java (+162 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.jdt.core.dom;
13
14
import java.util.List;
15
16
/**
17
 * Type node for a parameterized type.
18
 * <pre>
19
 * ParameterizedType:
20
 *    Name <b>&lt;</b> Type { <b>,</b> Type } <b>&gt;</b>
21
 * </pre>
22
 * <p>
23
 * Note: Support for generic types is an experimental language feature 
24
 * under discussion in JSR-014 and under consideration for inclusion
25
 * in the 1.5 release of J2SE. The support here is therefore tentative
26
 * and subject to change.
27
 * </p>
28
 * 
29
 * @since 2.2
30
 */
31
public class ParameterizedType extends Type {
32
	/** 
33
	 * The type name node; lazily initialized; defaults to a type with
34
	 * an unspecfied, but legal, name.
35
	 */
36
	private Name typeName = null;
37
	
38
	/**
39
	 * The type arguments (element type: <code>Type</code>). 
40
	 * Defaults to an empty list.
41
	 */
42
	private ASTNode.NodeList typeArguments =
43
		new ASTNode.NodeList(true, Type.class);
44
	
45
	/**
46
	 * Creates a new unparented node for a parameterized type owned by the
47
	 * given AST. By default, an unspecified, but legal, name, and no type
48
	 * arguments.
49
	 * <p>
50
	 * N.B. This constructor is package-private.
51
	 * </p>
52
	 * 
53
	 * @param ast the AST that is to own this node
54
	 */
55
	ParameterizedType(AST ast) {
56
		super(ast);
57
	}
58
59
	/* (omit javadoc for this method)
60
	 * Method declared on ASTNode.
61
	 */
62
	public int getNodeType() {
63
		return PARAMETERIZED_TYPE;
64
	}
65
66
	/* (omit javadoc for this method)
67
	 * Method declared on ASTNode.
68
	 */
69
	ASTNode clone(AST target) {
70
		ParameterizedType result = new ParameterizedType(target);
71
		result.setSourceRange(this.getStartPosition(), this.getLength());
72
		result.setName((Name) ((ASTNode) getName()).clone(target));
73
		result.typeArguments().addAll(
74
			ASTNode.copySubtrees(target, typeArguments()));
75
		return result;
76
	}
77
78
	/* (omit javadoc for this method)
79
	 * Method declared on ASTNode.
80
	 */
81
	public boolean subtreeMatch(ASTMatcher matcher, Object other) {
82
		// dispatch to correct overloaded match method
83
		return matcher.match(this, other);
84
	}
85
86
	/* (omit javadoc for this method)
87
	 * Method declared on ASTNode.
88
	 */
89
	void accept0(ASTVisitor visitor) {
90
		boolean visitChildren = visitor.visit(this);
91
		if (visitChildren) {
92
			// visit children in normal left to right reading order
93
			acceptChild(visitor, getName());
94
			acceptChildren(visitor, typeArguments);
95
		}
96
		visitor.endVisit(this);
97
	}
98
	
99
	/**
100
	 * Returns the name of this parameterized type.
101
	 * 
102
	 * @return the name of this parameterized type
103
	 */ 
104
	public Name getName() {
105
		if (typeName == null) {
106
			// lazy initialize - use setter to ensure parent link set too
107
			long count = getAST().modificationCount();
108
			setName(new SimpleName(getAST()));
109
			getAST().setModificationCount(count);
110
		}
111
		return typeName;
112
	}
113
	
114
	/**
115
	 * Sets the name of this parameterized type to the given name.
116
	 * 
117
	 * @param typeName the new name of this parameterized type
118
	 * @exception IllegalArgumentException if:
119
	 * <ul>
120
	 * <li>the node belongs to a different AST</li>
121
	 * <li>the node already has a parent</li>
122
	 * </ul>
123
	 */ 
124
	public void setName(Name typeName) {
125
		if (typeName == null) {
126
			throw new IllegalArgumentException();
127
		}
128
		replaceChild((ASTNode) this.typeName, (ASTNode) typeName, false);
129
		this.typeName = typeName;
130
	}
131
132
	/**
133
	 * Returns the live ordered list of type arguments of this parameterized 
134
	 * type. For the parameterized type to be plausible, the list should contain
135
	 * at least one element and not contain primitive types.
136
	 * 
137
	 * @return the live list of type arguments
138
	 *    (element type: <code>Type</code>)
139
	 */ 
140
	public List typeArguments() {
141
		return typeArguments;
142
	}
143
	
144
	/* (omit javadoc for this method)
145
	 * Method declared on ASTNode.
146
	 */
147
	int memSize() {
148
		// treat Code as free
149
		return BASE_NODE_SIZE + 2 * 4;
150
	}
151
	
152
	/* (omit javadoc for this method)
153
	 * Method declared on ASTNode.
154
	 */
155
	int treeSize() {
156
		return 
157
			memSize()
158
			+ (typeName == null ? 0 : getName().treeSize())
159
			+ typeArguments.listSize();
160
	}
161
}
162
(-)dom/org/eclipse/jdt/core/dom/QualifiedType.java (+198 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.jdt.core.dom;
13
14
/**
15
 * Type node for a qualified type.
16
 * <pre>
17
 * QualifiedType:
18
 *    Type <b>.</b> SimpleName
19
 * </pre>
20
 * <p>
21
 * Not all node arragements will represent legal Java constructs. In particular,
22
 * it is nonsense if the type is an array type or primitive type. The normal use
23
 * is when the type is a simple or parameterized type.
24
 * </p>
25
 * <p>
26
 * A type like "A.B" can be represented either of two ways:
27
 * <ol>
28
 * <li>
29
 * <code>QualifiedType(SimpleType(SimpleName("A")),SimpleName("B"))</code>
30
 * </li>
31
 * <li>
32
 * <code>SimpleType(QualifiedName(SimpleName("A"),SimpleName("B")))</code>
33
 * </li>
34
 * </ol>
35
 * The first form is preferred when "A" is known to be a type. However, a 
36
 * parser cannot always determine this. Clients should be prepared to handle
37
 * either rather than make assumptions. (Note also that the first form
38
 * became possible as of 2.2; only the second form existed in 2.0 and 2.1.)
39
 * </p>
40
 * <p>
41
 * Note: Support for generic types is an experimental language feature 
42
 * under discussion in JSR-014 and under consideration for inclusion
43
 * in the 1.5 release of J2SE. The support here is therefore tentative
44
 * and subject to change.
45
 * </p>
46
 * 
47
 * @since 2.2
48
 */
49
public class QualifiedType extends Type {
50
	/** 
51
	 * The type node; lazily initialized; defaults to a type with
52
	 * an unspecfied, but legal, simple name.
53
	 */
54
	private Type qualifier = null;
55
	
56
	/**
57
	 * The name being qualified; lazily initialized; defaults to a unspecified,
58
	 * legal Java identifier.
59
	 */
60
	private SimpleName name = null;
61
62
	/**
63
	 * Creates a new unparented node for a qualified type owned by the
64
	 * given AST. By default, an unspecified, but legal, qualifier and name.
65
	 * <p>
66
	 * N.B. This constructor is package-private.
67
	 * </p>
68
	 * 
69
	 * @param ast the AST that is to own this node
70
	 */
71
	QualifiedType(AST ast) {
72
		super(ast);
73
	}
74
75
	/* (omit javadoc for this method)
76
	 * Method declared on ASTNode.
77
	 */
78
	public int getNodeType() {
79
		return QUALIFIED_TYPE;
80
	}
81
82
	/* (omit javadoc for this method)
83
	 * Method declared on ASTNode.
84
	 */
85
	ASTNode clone(AST target) {
86
		QualifiedType result = new QualifiedType(target);
87
		result.setSourceRange(this.getStartPosition(), this.getLength());
88
		result.setQualifier((Type) ((ASTNode) getQualifier()).clone(target));
89
		result.setName((SimpleName) ((ASTNode) getName()).clone(target));
90
		return result;
91
	}
92
93
	/* (omit javadoc for this method)
94
	 * Method declared on ASTNode.
95
	 */
96
	public boolean subtreeMatch(ASTMatcher matcher, Object other) {
97
		// dispatch to correct overloaded match method
98
		return matcher.match(this, other);
99
	}
100
101
	/* (omit javadoc for this method)
102
	 * Method declared on ASTNode.
103
	 */
104
	void accept0(ASTVisitor visitor) {
105
		boolean visitChildren = visitor.visit(this);
106
		if (visitChildren) {
107
			// visit children in normal left to right reading order
108
			acceptChild(visitor, getQualifier());
109
			acceptChild(visitor, getName());
110
		}
111
		visitor.endVisit(this);
112
	}
113
	
114
	/**
115
	 * Returns the qualifier of this qualified type.
116
	 * 
117
	 * @return the qualifier of this qualified type
118
	 */ 
119
	public Type getQualifier() {
120
		if (this.qualifier == null) {
121
			// lazy initialize - use setter to ensure parent link set too
122
			long count = getAST().modificationCount();
123
			setQualifier(new SimpleType(getAST()));
124
			getAST().setModificationCount(count);
125
		}
126
		return this.qualifier;
127
	}
128
	
129
	/**
130
	 * Sets the qualifier of this qualified type to the given type.
131
	 * 
132
	 * @param type the new qualifier of this qualified type
133
	 * @exception IllegalArgumentException if:
134
	 * <ul>
135
	 * <li>the node belongs to a different AST</li>
136
	 * <li>the node already has a parent</li>
137
	 * </ul>
138
	 */ 
139
	public void setQualifier(Type type) {
140
		if (type == null) {
141
			throw new IllegalArgumentException();
142
		}
143
		replaceChild(this.qualifier, type, true);
144
		this.qualifier = type;
145
	}
146
147
	/**
148
	 * Returns the name part of this qualified type.
149
	 * 
150
	 * @return the name being qualified 
151
	 */ 
152
	public SimpleName getName() {
153
		if (this.name == null) {
154
			// lazy initialize - use setter to ensure parent link set too
155
			long count = getAST().modificationCount();
156
			setName(new SimpleName(getAST()));
157
			getAST().setModificationCount(count);
158
		}
159
		return this.name;
160
	}
161
	
162
	/**
163
	 * Sets the name part of this qualified type to the given simple name.
164
	 * 
165
	 * @param name the identifier of this qualified name
166
	 * @exception IllegalArgumentException if:
167
	 * <ul>
168
	 * <li>the node belongs to a different AST</li>
169
	 * <li>the node already has a parent</li>
170
	 * </ul>
171
	 */ 
172
	public void setName(SimpleName name) {
173
		if (name == null) {
174
			throw new IllegalArgumentException();
175
		}
176
		replaceChild(this.name, name, false);
177
		this.name = name;
178
	}
179
	
180
	/* (omit javadoc for this method)
181
	 * Method declared on ASTNode.
182
	 */
183
	int memSize() {
184
		// treat Code as free
185
		return BASE_NODE_SIZE + 2 * 4;
186
	}
187
	
188
	/* (omit javadoc for this method)
189
	 * Method declared on ASTNode.
190
	 */
191
	int treeSize() {
192
		return 
193
			memSize()
194
			+ (qualifier == null ? 0 : getQualifier().treeSize())
195
			+ (name == null ? 0 : getName().treeSize());
196
	}
197
}
198
(-)dom/org/eclipse/jdt/core/dom/SimpleName.java (+6 lines)
Lines 140-145 Link Here
140
	 * providing <code>isConstructor</code> is <code>false</code>.</li>
140
	 * providing <code>isConstructor</code> is <code>false</code>.</li>
141
	 * <li>The variable name in any type of <code>VariableDeclaration</code>
141
	 * <li>The variable name in any type of <code>VariableDeclaration</code>
142
	 * node.</li>
142
	 * node.</li>
143
	 * <li>The type variable name in a <code>TypeParameter</code>
144
	 * node.</li>
143
	 * </ul>
145
	 * </ul>
144
	 * <p>
146
	 * <p>
145
	 * Note that this is a convenience method that simply checks whether
147
	 * Note that this is a convenience method that simply checks whether
Lines 174-179 Link Here
174
			VariableDeclarationFragment p = (VariableDeclarationFragment) parent;
176
			VariableDeclarationFragment p = (VariableDeclarationFragment) parent;
175
			// make sure its the name of the variable (not the initializer)
177
			// make sure its the name of the variable (not the initializer)
176
			return (p.getName() == this);
178
			return (p.getName() == this);
179
		}
180
		if (parent instanceof TypeParameter) {
181
			// could only be the type variable name
182
			return true;
177
		}
183
		}
178
		return false;
184
		return false;
179
	}
185
	}
(-)dom/org/eclipse/jdt/core/dom/SimpleType.java (-1 / +7 lines)
Lines 12-21 Link Here
12
package org.eclipse.jdt.core.dom;
12
package org.eclipse.jdt.core.dom;
13
13
14
/**
14
/**
15
 * Type node for a named class or interface type.
15
 * Type node for a named class type, a named interface type, or a type variable.
16
 * <p>
16
 * <p>
17
 * This kind of node is used to convert a name (<code>Name</code>) into a type
17
 * This kind of node is used to convert a name (<code>Name</code>) into a type
18
 * (<code>Type</code>) by wrapping it.
18
 * (<code>Type</code>) by wrapping it.
19
 * </p>
20
 * <p>
21
 * Note: Support for generic types is an experimental language feature 
22
 * under discussion in JSR-014 and under consideration for inclusion
23
 * in the 1.5 release of J2SE. The support here is therefore tentative
24
 * and subject to change.
19
 * </p>
25
 * </p>
20
 * 
26
 * 
21
 * @since 2.0
27
 * @since 2.0
(-)dom/org/eclipse/jdt/core/dom/Type.java (-33 / +70 lines)
Lines 13-26 Link Here
13
13
14
/**
14
/**
15
 * Abstract base class of all type AST node types. A type node represents a 
15
 * Abstract base class of all type AST node types. A type node represents a 
16
 * reference to a primitive type (including void), to a named class or 
16
 * reference to a primitive type (including void), to an array type, or to a
17
 * interface type, or to an array type.
17
 * simple named type (or type variable), to a qualified type, or to a
18
 * parameterized type.
18
 * <p>
19
 * <p>
19
 * <pre>
20
 * <pre>
20
 * Type:
21
 * Type:
21
 *    PrimitiveType
22
 *    PrimitiveType
22
 *    SimpleType
23
 *    ArrayType
23
 *    ArrayType
24
 *    SimpleType
25
 *    QualifiedType
26
 *    ParameterizedType
24
 * PrimitiveType:
27
 * PrimitiveType:
25
 *    <b>byte</b>
28
 *    <b>byte</b>
26
 *    <b>short</b>
29
 *    <b>short</b>
Lines 31-42 Link Here
31
 *    <b>double</b>
34
 *    <b>double</b>
32
 *    <b>boolean</b>
35
 *    <b>boolean</b>
33
 *    <b>void</b>
36
 *    <b>void</b>
34
 * SimpleType:
35
 *    TypeName
36
 * ArrayType:
37
 * ArrayType:
37
 *    Type <b>[</b> <b>]</b>
38
 *    Type <b>[</b> <b>]</b>
39
 * SimpleType:
40
 *    TypeName
41
 * ParameterizedType:
42
 *    Name <b>&lt;</b> Type { <b>,</b> Type } <b>&gt;</b>
43
 * QualifiedType:
44
 *    Type <b>.</b> SimpleName
38
 * </pre>
45
 * </pre>
39
 * </p>
46
 * </p>
47
 * <p>
48
 * Note: Support for generic types is an experimental language feature 
49
 * under discussion in JSR-014 and under consideration for inclusion
50
 * in the 1.5 release of J2SE. The support here is therefore tentative
51
 * and subject to change.
52
 * </p>
40
 * 
53
 * 
41
 * @since 2.0
54
 * @since 2.0
42
 */
55
 */
Lines 88-93 Link Here
88
	}
101
	}
89
102
90
	/**
103
	/**
104
	 * Returns whether this type is a parameterized type
105
	 * (<code>ParameterizedType</code>). 
106
	 * <p>
107
	 * Note: Support for generic types is an experimental language feature 
108
	 * under discussion in JSR-014 and under consideration for inclusion
109
	 * in the 1.5 release of J2SE. The support here is therefore tentative
110
	 * and subject to change.
111
	 * </p>
112
	 * 
113
	 * @return <code>true</code> if this is a parameterized type, and 
114
	 *    <code>false</code> otherwise
115
	 * @since 2.2
116
	 */
117
	public final boolean isParameterizedType() {
118
		return (this instanceof ParameterizedType);
119
	}
120
121
	/**
122
	 * Returns whether this type is a qualified type
123
	 * (<code>QualifiedType</code>). 
124
	 * <p>
125
	 * Note that a type like "A.B" can be represented either of two ways:
126
	 * <ol>
127
	 * <li>
128
	 * <code>QualifiedType(SimpleType(SimpleName("A")),SimpleName("B"))</code>
129
	 * </li>
130
	 * <li>
131
	 * <code>SimpleType(QualifiedName(SimpleName("A"),SimpleName("B")))</code>
132
	 * </li>
133
	 * </ol>
134
	 * The first form is preferred when "A" is known to be a type. However, a 
135
	 * parser cannot always determine this. Clients should be prepared to handle
136
	 * either rather than make assumptions. (Note also that the first form
137
	 * became possible as of 2.2; only the second form existed in 2.0 and 2.1.)
138
	 * </p>
139
	 * <p>
140
	 * Note: Support for generic types is an experimental language feature 
141
	 * under discussion in JSR-014 and under consideration for inclusion
142
	 * in the 1.5 release of J2SE. The support here is therefore tentative
143
	 * and subject to change.
144
	 * </p>
145
	 * 
146
	 * @return <code>true</code> if this is a qualified type, and 
147
	 *    <code>false</code> otherwise
148
	 * @since 2.2
149
	 */
150
	public final boolean isQualifiedType() {
151
		return (this instanceof QualifiedType);
152
	}
153
154
	/**
91
	 * Resolves and returns the binding for this type.
155
	 * Resolves and returns the binding for this type.
92
	 * <p>
156
	 * <p>
93
	 * Note that bindings are generally unavailable unless requested when the
157
	 * Note that bindings are generally unavailable unless requested when the
Lines 100-130 Link Here
100
	public final ITypeBinding resolveBinding() {
164
	public final ITypeBinding resolveBinding() {
101
		return getAST().getBindingResolver().resolveType(this);
165
		return getAST().getBindingResolver().resolveType(this);
102
	}
166
	}
103
	
167
}
104
// JSR-014
105
//	/**
106
//	 * Returns whether this type is a parameterized type 
107
//   * (<code>ParameterizedType</code>).
108
//	 * 
109
//	 * @return <code>true</code> if this is a parameterized type, and 
110
//	 *    <code>false</code> otherwise
111
//	 */
112
//	public final boolean isParameterizedType() {
113
//		return (this instanceof ParameterizedType);
114
//	}
115
116
//	public IBinding resolvedType();
117
}
118
119
//// JSR-014
120
//public class ParameterizedType extends Type {
121
//	public ParameterizedType(AST ast) {
122
//		super(ast);
123
//	}
124
//
125
//	public Type getGenericType();
126
//	public void setGenericType(Type genericType);
127
//
128
//	public NodeList<Type> parameters();
129
//}
130
(-)dom/org/eclipse/jdt/core/dom/TypeDeclaration.java (-28 / +263 lines)
Lines 11-16 Link Here
11
11
12
package org.eclipse.jdt.core.dom;
12
package org.eclipse.jdt.core.dom;
13
13
14
import java.util.AbstractList;
14
import java.util.Iterator;
15
import java.util.Iterator;
15
import java.util.List;
16
import java.util.List;
16
17
Lines 24-34 Link Here
24
 * 		InterfaceDeclaration
25
 * 		InterfaceDeclaration
25
 * ClassDeclaration:
26
 * ClassDeclaration:
26
 *      [ Javadoc ] { Modifier } <b>class</b> Identifier
27
 *      [ Javadoc ] { Modifier } <b>class</b> Identifier
27
 *			[ <b>extends</b> Type]
28
 *			[ <b>&lt;</b> TypeParameter { <b>,</b> TypeParameter } <b>&gt;</b> ]
29
 *			[ <b>extends</b> Type ]
28
 *			[ <b>implements</b> Type { <b>,</b> Type } ]
30
 *			[ <b>implements</b> Type { <b>,</b> Type } ]
29
 *			<b>{</b> { ClassBodyDeclaration | <b>;</b> } <b>}</b>
31
 *			<b>{</b> { ClassBodyDeclaration | <b>;</b> } <b>}</b>
30
 * InterfaceDeclaration:
32
 * InterfaceDeclaration:
31
 *      [ Javadoc ] { Modifier } <b>interface</b> Identifier
33
 *      [ Javadoc ] { Modifier } <b>interface</b> Identifier
34
 *			[ <b>&lt;</b> TypeParameter { <b>,</b> TypeParameter } <b>&gt;</b> ]
32
 *			[ <b>extends</b> Type { <b>,</b> Type } ]
35
 *			[ <b>extends</b> Type { <b>,</b> Type } ]
33
 * 			<b>{</b> { InterfaceBodyDeclaration | <b>;</b> } <b>}</b>
36
 * 			<b>{</b> { InterfaceBodyDeclaration | <b>;</b> } <b>}</b>
34
 * </pre>
37
 * </pre>
Lines 42-47 Link Here
42
 * no body), or the last character of the "}" token following the body
45
 * no body), or the last character of the "}" token following the body
43
 * declarations.
46
 * declarations.
44
 * </p>
47
 * </p>
48
 * <p>
49
 * Note: Support for generic types is an experimental language feature 
50
 * under discussion in JSR-014 and under consideration for inclusion
51
 * in the 1.5 release of J2SE. The support here is therefore tentative
52
 * and subject to change.
53
 * </p>
45
 * 
54
 * 
46
 * @since 2.0
55
 * @since 2.0
47
 */
56
 */
Lines 74-91 Link Here
74
	private SimpleName typeName = null;
83
	private SimpleName typeName = null;
75
84
76
	/**
85
	/**
77
	 * The optional superclass name; <code>null</code> if none.
86
	 * The type paramters (element type: <code>TypeParameter</code>). 
87
	 * Defaults to an empty list.
88
	 * @since 2.2
89
	 */
90
	private ASTNode.NodeList typeParameters =
91
		new ASTNode.NodeList(false, TypeParameter.class);
92
93
	/**
94
	 * The optional superclass type; <code>null</code> if none.
78
	 * Defaults to none. Note that this field is not used for
95
	 * Defaults to none. Note that this field is not used for
79
	 * interface declarations.
96
	 * interface declarations.
97
	 * @since 2.2
80
	 */
98
	 */
81
	private Name optionalSuperclassName = null;
99
	private Type optionalSuperclassType = null;
82
100
83
	/**
101
	/**
84
	 * The superinterface names (element type: <code>Name</code>). 
102
	 * The superinterface types (element type: <code>Type</code>). 
85
	 * Defaults to an empty list.
103
	 * Defaults to an empty list.
104
	 * @since 2.2
86
	 */
105
	 */
87
	private ASTNode.NodeList superInterfaceNames =
106
	private ASTNode.NodeList superInterfaceTypes =
88
		new ASTNode.NodeList(false, Name.class);
107
		new ASTNode.NodeList(false, Type.class);
89
108
90
	/**
109
	/**
91
	 * The body declarations (element type: <code>BodyDeclaration</code>).
110
	 * The body declarations (element type: <code>BodyDeclaration</code>).
Lines 98-105 Link Here
98
	 * Creates a new AST node for a type declaration owned by the given 
117
	 * Creates a new AST node for a type declaration owned by the given 
99
	 * AST. By default, the type declaration is for a class of an
118
	 * AST. By default, the type declaration is for a class of an
100
	 * unspecified, but legal, name; no modifiers; no javadoc; 
119
	 * unspecified, but legal, name; no modifiers; no javadoc; 
101
	 * no superclass or superinterfaces; and an empty list of body
120
	 * no type parameters; no superclass or superinterfaces; and an empty list
102
	 * declarations.
121
	 * of body declarations.
103
	 * <p>
122
	 * <p>
104
	 * N.B. This constructor is package-private; all subclasses must be 
123
	 * N.B. This constructor is package-private; all subclasses must be 
105
	 * declared in the same package; clients are unable to declare 
124
	 * declared in the same package; clients are unable to declare 
Lines 130-139 Link Here
130
			(Javadoc) ASTNode.copySubtree(target,(ASTNode) getJavadoc()));
149
			(Javadoc) ASTNode.copySubtree(target,(ASTNode) getJavadoc()));
131
		result.setInterface(isInterface());
150
		result.setInterface(isInterface());
132
		result.setName((SimpleName) getName().clone(target));
151
		result.setName((SimpleName) getName().clone(target));
133
		result.setSuperclass(
152
		result.typeParameters().addAll(
134
			(Name) ASTNode.copySubtree(target,(ASTNode) getSuperclass()));
153
			ASTNode.copySubtrees(target, typeParameters()));
135
		result.superInterfaces().addAll(
154
		result.setSuperclassType(
136
			ASTNode.copySubtrees(target, superInterfaces()));
155
			(Type) ASTNode.copySubtree(target,(ASTNode) getSuperclassType()));
156
		result.superInterfaceTypes().addAll(
157
			ASTNode.copySubtrees(target, superInterfaceTypes()));
137
		result.bodyDeclarations().addAll(
158
		result.bodyDeclarations().addAll(
138
			ASTNode.copySubtrees(target, bodyDeclarations()));
159
			ASTNode.copySubtrees(target, bodyDeclarations()));
139
		return result;
160
		return result;
Lines 156-163 Link Here
156
			// visit children in normal left to right reading order
177
			// visit children in normal left to right reading order
157
			acceptChild(visitor, getJavadoc());
178
			acceptChild(visitor, getJavadoc());
158
			acceptChild(visitor, getName());
179
			acceptChild(visitor, getName());
159
			acceptChild(visitor, getSuperclass());
180
			acceptChildren(visitor, typeParameters);
160
			acceptChildren(visitor, superInterfaceNames);
181
			acceptChild(visitor, getSuperclassType());
182
			acceptChildren(visitor, superInterfaceTypes);
161
			acceptChildren(visitor, bodyDeclarations);
183
			acceptChildren(visitor, bodyDeclarations);
162
		}
184
		}
163
		visitor.endVisit(this);
185
		visitor.endVisit(this);
Lines 257-267 Link Here
257
		this.typeName = typeName;
279
		this.typeName = typeName;
258
	}
280
	}
259
281
260
//	JSR-014 feature
282
	/**
261
//	public List<TypeParameter> typeParameters() {
283
	 * Returns the live ordered list of type parameters of this type 
262
//		throw RuntimeException("not implemented yet");
284
	 * declaration. This list is non-empty for parameterized types.
263
//	}
285
	 * <p>
264
286
	 * Note: Support for generic types is an experimental language feature 
287
	 * under discussion in JSR-014 and under consideration for inclusion
288
	 * in the 1.5 release of J2SE. The support here is therefore tentative
289
	 * and subject to change.
290
	 * </p>
291
	 * 
292
	 * @return the live list of type parameters
293
	 *    (element type: <code>TypeParameter</code>)
294
	 * @since 2.2
295
	 */ 
296
	public List typeParameters() {
297
		return typeParameters;
298
	}
299
	
265
	/**
300
	/**
266
	 * Returns the name of the superclass declared in this type
301
	 * Returns the name of the superclass declared in this type
267
	 * declaration, or <code>null</code> if there is none.
302
	 * declaration, or <code>null</code> if there is none.
Lines 272-280 Link Here
272
	 * 
307
	 * 
273
	 * @return the superclass name node, or <code>null</code> if 
308
	 * @return the superclass name node, or <code>null</code> if 
274
	 *    there is none
309
	 *    there is none
310
	 * @deprecated Replaced by <code>getSuperclassType</code>, which returns
311
	 * a <code>Type</code> instead of a <code>Name</code>.
275
	 */ 
312
	 */ 
276
	public Name getSuperclass() {
313
	public Name getSuperclass() {
277
		return optionalSuperclassName;
314
		// implement deprecated method in terms of get/setSuperclassType
315
		Type superclassType = getSuperclassType();
316
		if (superclassType == null) {
317
			// return null if no superclass type
318
			return null;
319
		} else if (superclassType instanceof SimpleType) {
320
			// no problem - extract name from SimpleType
321
			SimpleType t = (SimpleType) superclassType;
322
			return t.getName();
323
		} else if ((superclassType instanceof ParameterizedType)
324
			     || (superclassType instanceof QualifiedType)) {
325
			// compatibility issue
326
			// back-level clients know nothing of new node types added in 2.1
327
			// take this opportunity to inform client of problem
328
			throw new RuntimeException("Deprecated AST API method cannot handle newer node types"); //$NON-NLS-1$
329
		} else {
330
			// compatibility issue
331
			// AST is bogus - illegal for type to be array or primitive type
332
			// take this opportunity to inform client of problem
333
			throw new RuntimeException("Deprecated AST API method cannot handle malformed AST"); //$NON-NLS-1$
334
		}
278
	}
335
	}
279
	
336
	
280
	/**
337
	/**
Lines 292-303 Link Here
292
	 * <li>the node belongs to a different AST</li>
349
	 * <li>the node belongs to a different AST</li>
293
	 * <li>the node already has a parent</li>
350
	 * <li>the node already has a parent</li>
294
	 * </ul>
351
	 * </ul>
352
	 * @deprecated Replaced by <code>setSuperclassType</code>, which expects
353
	 * a <code>Type</code> instead of a <code>Name</code>.
295
	 */ 
354
	 */ 
296
	public void setSuperclass(Name superclassName) {
355
	public void setSuperclass(Name superclassName) {
297
		replaceChild(
356
		// implement deprecated method in terms of get/setSuperclassType
298
			(ASTNode) this.optionalSuperclassName,
357
		if (superclassName == null) {
299
			(ASTNode) superclassName, false);
358
			setSuperclassType(null);
300
		this.optionalSuperclassName = superclassName;
359
		} else {
360
			Type superclassType = getSuperclassType();
361
			if (superclassType instanceof SimpleType) {
362
				// if possible edit name in SimpleType
363
				SimpleType s = (SimpleType) superclassType;
364
				s.setName(superclassName);
365
				// give type node same range as name node
366
				s.setSourceRange(
367
					superclassName.getStartPosition(),
368
					superclassName.getLength());
369
				// note that only s will be modified(), not the TypeDecl node
370
			} else {
371
				// all other cases - wrap name in a SimpleType and replace superclassType
372
				Type newT = getAST().newSimpleType(superclassName);
373
				// give new type node same range as name node
374
				newT.setSourceRange(
375
					superclassName.getStartPosition(),
376
					superclassName.getLength());
377
				setSuperclassType(newT);
378
			}
379
		}
380
	}
381
382
	/**
383
	 * Returns the superclass declared in this type
384
	 * declaration, or <code>null</code> if there is none.
385
	 * <p>
386
	 * Note that this child is not relevant for interface declarations
387
	 * (although it does still figure in subtree equality comparisons).
388
	 * </p>
389
	 * 
390
	 * @return the superclass type node, or <code>null</code> if 
391
	 *    there is none
392
	 * @since 2.2
393
	 */ 
394
	public Type getSuperclassType() {
395
		return this.optionalSuperclassType;
396
	}
397
	
398
	/**
399
	 * Sets or clears the superclass declared in this type
400
	 * declaration.
401
	 * <p>
402
	 * Note that this child is not relevant for interface declarations
403
	 * (although it does still figure in subtree equality comparisons).
404
	 * </p>
405
	 * 
406
	 * @param superclassType the superclass type node, or <code>null</code> if 
407
	 *    there is none
408
	 * @exception IllegalArgumentException if:
409
	 * <ul>
410
	 * <li>the node belongs to a different AST</li>
411
	 * <li>the node already has a parent</li>
412
	 * </ul>
413
	 * @since 2.2
414
	 */ 
415
	public void setSuperclassType(Type superclassType) {
416
		replaceChild(this.optionalSuperclassType, superclassType, true);
417
		this.optionalSuperclassType = superclassType;
301
	}
418
	}
302
419
303
	/**
420
	/**
Lines 308-316 Link Here
308
	 * 
425
	 * 
309
	 * @return the live list of interface names
426
	 * @return the live list of interface names
310
	 *    (element type: <code>Name</code>)
427
	 *    (element type: <code>Name</code>)
428
	 * @deprecated Replaced by <code>superInterfaceTypes</code>, which contains
429
	 * a list of <code>Type</code>s instead of <code>Name</code>s.
311
	 */ 
430
	 */ 
312
	public List superInterfaces() {
431
	public List superInterfaces() {
313
		return superInterfaceNames;
432
		// implement deprecated method in terms of superInterfaceTypes()
433
		// return special implementation of List<Name> in terms of List<Type>
434
		return new AbstractList() {
435
			/**
436
			 * @see java.util.AbstractCollection#size()
437
			 */
438
			public int size() {
439
				return superInterfaceTypes().size();
440
			}
441
		
442
			/**
443
			 * @see AbstractList#get(int)
444
			 */
445
			public Object get(int index) {
446
				Type t = (Type) superInterfaceTypes().get(index);
447
				if (t instanceof SimpleType) {
448
					// old client reading an old style element
449
					SimpleType s = (SimpleType) t;
450
					return s.getName();
451
				} else if ((t instanceof ParameterizedType)
452
					     || (t instanceof QualifiedType)) {
453
					// compatibility issue
454
					// back-level clients know nothing of new node types added in 2.1
455
					// take this opportunity to inform client of problem
456
					throw new RuntimeException("Deprecated AST API method (TypeDeclaration.superinterfaces()) cannot handle newer node types"); //$NON-NLS-1$
457
				} else {
458
					// compatibility issue
459
					// AST is bogus - illegal for type to be array or primitive type
460
					// take this opportunity to inform client of problem
461
					throw new RuntimeException("Deprecated AST API method (TypeDeclaration.superinterfaces()) cannot handle malformed AST"); //$NON-NLS-1$
462
				}
463
			}
464
		
465
			/**
466
			 * @see List#set(int, java.lang.Object)
467
			 */
468
			public Object set(int index, Object element) {
469
				if (!(element instanceof Name)) {
470
					throw new IllegalArgumentException();
471
				}
472
				Type oldType = (Type) superInterfaceTypes().get(index);
473
				Name newName = (Name) element;
474
				if (oldType instanceof SimpleType) {
475
					// old client operating on old style element
476
					SimpleType s = (SimpleType) oldType;
477
					Name oldName = s.getName();
478
					if (oldName != element) {
479
						s.setName(newName);
480
						// give type node same range as name node
481
						s.setSourceRange(
482
							newName.getStartPosition(),
483
							newName.getLength());
484
					}
485
					return oldName;
486
				} else {
487
					// old client replaced a new-fangled element
488
					Type newType = getAST().newSimpleType(newName);
489
					// give new type node same range as name node
490
					newType.setSourceRange(
491
						newName.getStartPosition(),
492
						newName.getLength());
493
					superInterfaceTypes().set(index, newType);
494
					// no choice but to return old new-fangled element
495
					return oldType;
496
				}
497
			}
498
			
499
			/**
500
			 * @see List#add(int, java.lang.Object)
501
			 */
502
			public void add(int index, Object element) {
503
				if (!(element instanceof Name)) {
504
					throw new IllegalArgumentException();
505
				}
506
				Name newName = (Name) element;
507
				Type newType = getAST().newSimpleType(newName);
508
				// give new type node same range as name node
509
				newType.setSourceRange(
510
					newName.getStartPosition(),
511
					newName.getLength());
512
				superInterfaceTypes().add(index, newType);
513
			}
514
			
515
			/**
516
			 * @see List#remove(int)
517
			 */
518
			public Object remove(int index) {
519
				Object result = superInterfaceTypes().remove(index);
520
				if (result instanceof SimpleType) {
521
					// old client operating on old style element
522
					SimpleType s = (SimpleType) result;
523
					Name oldName = s.getName();
524
					// make sure that oldName has no parent afterwards
525
					s.setName(getAST().newSimpleName("deleted")); //$NON-NLS-1$
526
					return oldName;
527
				} else {
528
					// old client removing a new-fangled element
529
					// take a chance that they ignore result
530
					return result;
531
				}
532
			}
533
		};
534
	}
535
	
536
	/**
537
	 * Returns the live ordered list of superinterfaces of this type 
538
	 * declaration. For a class declaration, these are the interfaces
539
	 * that this class implements; for an interface declaration,
540
	 * these are the interfaces that this interface extends.
541
	 * 
542
	 * @return the live list of interface types
543
	 *    (element type: <code>Type</code>)
544
	 * @since 2.2
545
	 */ 
546
	public List superInterfaceTypes() {
547
		return superInterfaceTypes;
314
	}
548
	}
315
	
549
	
316
	/**
550
	/**
Lines 506-512 Link Here
506
	 * Method declared on ASTNode.
740
	 * Method declared on ASTNode.
507
	 */
741
	 */
508
	int memSize() {
742
	int memSize() {
509
		return super.memSize() + 6 * 4;
743
		return super.memSize() + 7 * 4;
510
	}
744
	}
511
	
745
	
512
	/* (omit javadoc for this method)
746
	/* (omit javadoc for this method)
Lines 517-524 Link Here
517
			memSize()
751
			memSize()
518
			+ (getJavadoc() == null ? 0 : getJavadoc().treeSize())
752
			+ (getJavadoc() == null ? 0 : getJavadoc().treeSize())
519
			+ (typeName == null ? 0 : getName().treeSize())
753
			+ (typeName == null ? 0 : getName().treeSize())
520
			+ (optionalSuperclassName == null ? 0 : getSuperclass().treeSize())
754
			+ typeParameters.listSize()
521
			+ superInterfaceNames.listSize()
755
			+ (optionalSuperclassType == null ? 0 : getSuperclassType().treeSize())
756
			+ superInterfaceTypes.listSize()
522
			+ bodyDeclarations.listSize();
757
			+ bodyDeclarations.listSize();
523
	}
758
	}
524
}
759
}
(-)dom/org/eclipse/jdt/core/dom/TypeParameter.java (+165 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.jdt.core.dom;
13
14
import java.util.List;
15
16
/**
17
 * Type parameter node.
18
 * <pre>
19
 * TypeParameter:
20
 *    TypeVariable [ <b>extends</b> Type { <b>&</b> Type } ]
21
 * </pre>
22
 * <p>
23
 * Note: Support for generic types is an experimental language feature 
24
 * under discussion in JSR-014 and under consideration for inclusion
25
 * in the 1.5 release of J2SE. The support here is therefore tentative
26
 * and subject to change.
27
 * </p>
28
 * 
29
 * @since 2.2
30
 */
31
public class TypeParameter extends ASTNode {
32
	/** 
33
	 * The type variable node; lazily initialized; defaults to an unspecfied, 
34
	 * but legal, name.
35
	 */
36
	private SimpleName typeVariableName = null;
37
	
38
	/**
39
	 * The type bounds (element type: <code>Type</code>). 
40
	 * Defaults to an empty list.
41
	 */
42
	private ASTNode.NodeList typeBounds =
43
		new ASTNode.NodeList(false, Type.class);
44
	
45
	/**
46
	 * Creates a new unparented node for a parameterized type owned by the
47
	 * given AST. By default, an unspecified, but legal, type variable name, 
48
	 * and no type bounds.
49
	 * <p>
50
	 * N.B. This constructor is package-private.
51
	 * </p>
52
	 * 
53
	 * @param ast the AST that is to own this node
54
	 */
55
	TypeParameter(AST ast) {
56
		super(ast);
57
	}
58
59
	/* (omit javadoc for this method)
60
	 * Method declared on ASTNode.
61
	 */
62
	public int getNodeType() {
63
		return TYPE_PARAMETER;
64
	}
65
66
	/* (omit javadoc for this method)
67
	 * Method declared on ASTNode.
68
	 */
69
	ASTNode clone(AST target) {
70
		TypeParameter result = new TypeParameter(target);
71
		result.setSourceRange(this.getStartPosition(), this.getLength());
72
		result.setName((SimpleName) ((ASTNode) getName()).clone(target));
73
		result.typeBounds().addAll(
74
			ASTNode.copySubtrees(target, typeBounds()));
75
		return result;
76
	}
77
78
	/* (omit javadoc for this method)
79
	 * Method declared on ASTNode.
80
	 */
81
	public boolean subtreeMatch(ASTMatcher matcher, Object other) {
82
		// dispatch to correct overloaded match method
83
		return matcher.match(this, other);
84
	}
85
86
	/* (omit javadoc for this method)
87
	 * Method declared on ASTNode.
88
	 */
89
	void accept0(ASTVisitor visitor) {
90
		boolean visitChildren = visitor.visit(this);
91
		if (visitChildren) {
92
			// visit children in normal left to right reading order
93
			acceptChild(visitor, getName());
94
			acceptChildren(visitor, typeBounds);
95
		}
96
		visitor.endVisit(this);
97
	}
98
	
99
	/**
100
	 * Returns the name of the type variable declared in this type parameter.
101
	 * 
102
	 * @return the name of the type variable
103
	 */ 
104
	public SimpleName getName() {
105
		if (typeVariableName == null) {
106
			// lazy initialize - use setter to ensure parent link set too
107
			long count = getAST().modificationCount();
108
			setName(new SimpleName(getAST()));
109
			getAST().setModificationCount(count);
110
		}
111
		return typeVariableName;
112
	}
113
	
114
	/**
115
	 * Sets the name of the type variable of this type parameter to the given
116
	 * name.
117
	 * 
118
	 * @param typeName the new name of this type parameter 
119
	 * @exception IllegalArgumentException if:
120
	 * <ul>
121
	 * <li>the node belongs to a different AST</li>
122
	 * <li>the node already has a parent</li>
123
	 * </ul>
124
	 */ 
125
	public void setName(SimpleName typeName) {
126
		if (typeName == null) {
127
			throw new IllegalArgumentException();
128
		}
129
		replaceChild(this.typeVariableName, typeName, false);
130
		this.typeVariableName = typeName;
131
	}
132
133
	/**
134
	 * Returns the live ordered list of type bounds of this type parameter.
135
	 * For the type parameter to be plausible, there can be at most one
136
	 * class in the list, and it must be first, and the remaining ones must be
137
	 * interfaces; the list should not contain primitive types (but array types
138
	 * and parameterized types are allowed).
139
	 * 
140
	 * @return the live list of type bounds
141
	 *    (element type: <code>Type</code>)
142
	 */ 
143
	public List typeBounds() {
144
		return typeBounds;
145
	}
146
	
147
	/* (omit javadoc for this method)
148
	 * Method declared on ASTNode.
149
	 */
150
	int memSize() {
151
		// treat Code as free
152
		return BASE_NODE_SIZE + 2 * 4;
153
	}
154
	
155
	/* (omit javadoc for this method)
156
	 * Method declared on ASTNode.
157
	 */
158
	int treeSize() {
159
		return 
160
			memSize()
161
			+ (typeVariableName == null ? 0 : getName().treeSize())
162
			+ typeBounds.listSize();
163
	}
164
}
165

Return to bug 36142