src/share/classes/com/sun/tools/javac/code/Type.java

changeset 1644
40adaf938847
parent 1628
5ddecb91d843
child 1645
97f6839673d6
equal deleted inserted replaced
1643:1f8c28134ffc 1644:40adaf938847
242 * If this is a constant type, return its underlying type. 242 * If this is a constant type, return its underlying type.
243 * Otherwise, return the type itself. 243 * Otherwise, return the type itself.
244 */ 244 */
245 public Type baseType() { 245 public Type baseType() {
246 return this; 246 return this;
247 }
248
249 public boolean isAnnotated() {
250 return false;
247 } 251 }
248 252
249 /** 253 /**
250 * If this is an annotated type, return the underlying type. 254 * If this is an annotated type, return the underlying type.
251 * Otherwise, return the type itself. 255 * Otherwise, return the type itself.
1537 return v.visitError(this, p); 1541 return v.visitError(this, p);
1538 } 1542 }
1539 } 1543 }
1540 1544
1541 public static class AnnotatedType extends Type 1545 public static class AnnotatedType extends Type
1542 implements javax.lang.model.type.AnnotatedType { 1546 implements
1547 javax.lang.model.type.ArrayType,
1548 javax.lang.model.type.DeclaredType,
1549 javax.lang.model.type.PrimitiveType,
1550 javax.lang.model.type.TypeVariable,
1551 javax.lang.model.type.WildcardType {
1543 /** The type annotations on this type. 1552 /** The type annotations on this type.
1544 */ 1553 */
1545 public List<Attribute.TypeCompound> typeAnnotations; 1554 public List<Attribute.TypeCompound> typeAnnotations;
1546 1555
1547 /** The underlying type that is annotated. 1556 /** The underlying type that is annotated.
1550 1559
1551 public AnnotatedType(Type underlyingType) { 1560 public AnnotatedType(Type underlyingType) {
1552 super(underlyingType.tag, underlyingType.tsym); 1561 super(underlyingType.tag, underlyingType.tsym);
1553 this.typeAnnotations = List.nil(); 1562 this.typeAnnotations = List.nil();
1554 this.underlyingType = underlyingType; 1563 this.underlyingType = underlyingType;
1555 Assert.check(underlyingType.getKind() != TypeKind.ANNOTATED, 1564 Assert.check(!underlyingType.isAnnotated(),
1556 "Can't annotate already annotated type: " + underlyingType); 1565 "Can't annotate already annotated type: " + underlyingType);
1557 } 1566 }
1558 1567
1559 public AnnotatedType(List<Attribute.TypeCompound> typeAnnotations, 1568 public AnnotatedType(List<Attribute.TypeCompound> typeAnnotations,
1560 Type underlyingType) { 1569 Type underlyingType) {
1561 super(underlyingType.tag, underlyingType.tsym); 1570 super(underlyingType.tag, underlyingType.tsym);
1562 this.typeAnnotations = typeAnnotations; 1571 this.typeAnnotations = typeAnnotations;
1563 this.underlyingType = underlyingType; 1572 this.underlyingType = underlyingType;
1564 Assert.check(underlyingType.getKind() != TypeKind.ANNOTATED, 1573 Assert.check(!underlyingType.isAnnotated(),
1565 "Can't annotate already annotated type: " + underlyingType + 1574 "Can't annotate already annotated type: " + underlyingType +
1566 "; adding: " + typeAnnotations); 1575 "; adding: " + typeAnnotations);
1567 } 1576 }
1568 1577
1569 @Override 1578 @Override
1579 public boolean isAnnotated() {
1580 return true;
1581 }
1582
1583 @Override
1570 public TypeKind getKind() { 1584 public TypeKind getKind() {
1571 return TypeKind.ANNOTATED; 1585 return underlyingType.getKind();
1572 } 1586 }
1573 1587
1574 @Override 1588 @Override
1575 public List<? extends AnnotationMirror> getAnnotations() { 1589 public List<? extends AnnotationMirror> getAnnotations() {
1576 return typeAnnotations; 1590 return typeAnnotations;
1577 } 1591 }
1578 1592
1579 @Override 1593 @Override
1580 public TypeMirror getUnderlyingType() {
1581 return underlyingType;
1582 }
1583
1584 @Override
1585 public Type unannotatedType() { 1594 public Type unannotatedType() {
1586 return underlyingType; 1595 return underlyingType;
1587 } 1596 }
1588 1597
1589 @Override 1598 @Override
1591 return v.visitAnnotatedType(this, s); 1600 return v.visitAnnotatedType(this, s);
1592 } 1601 }
1593 1602
1594 @Override 1603 @Override
1595 public <R, P> R accept(TypeVisitor<R, P> v, P p) { 1604 public <R, P> R accept(TypeVisitor<R, P> v, P p) {
1596 return v.visitAnnotated(this, p); 1605 return underlyingType.accept(v, p);
1597 } 1606 }
1598 1607
1599 @Override 1608 @Override
1600 public Type map(Mapping f) { 1609 public Type map(Mapping f) {
1601 underlyingType.map(f); 1610 underlyingType.map(f);

mercurial