39 import com.sun.tools.javac.comp.AttrContext; |
39 import com.sun.tools.javac.comp.AttrContext; |
40 import com.sun.tools.javac.comp.Env; |
40 import com.sun.tools.javac.comp.Env; |
41 import com.sun.tools.javac.jvm.*; |
41 import com.sun.tools.javac.jvm.*; |
42 import com.sun.tools.javac.tree.JCTree.JCVariableDecl; |
42 import com.sun.tools.javac.tree.JCTree.JCVariableDecl; |
43 import com.sun.tools.javac.util.*; |
43 import com.sun.tools.javac.util.*; |
|
44 import com.sun.tools.javac.util.DefinedBy.Api; |
44 import com.sun.tools.javac.util.Name; |
45 import com.sun.tools.javac.util.Name; |
45 import static com.sun.tools.javac.code.Flags.*; |
46 import static com.sun.tools.javac.code.Flags.*; |
46 import static com.sun.tools.javac.code.Kinds.*; |
47 import static com.sun.tools.javac.code.Kinds.*; |
47 import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE; |
48 import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE; |
48 import static com.sun.tools.javac.code.TypeTag.CLASS; |
49 import static com.sun.tools.javac.code.TypeTag.CLASS; |
570 */ |
571 */ |
571 public boolean exists() { |
572 public boolean exists() { |
572 return true; |
573 return true; |
573 } |
574 } |
574 |
575 |
|
576 @DefinedBy(Api.LANGUAGE_MODEL) |
575 public Type asType() { |
577 public Type asType() { |
576 return type; |
578 return type; |
577 } |
579 } |
578 |
580 |
|
581 @DefinedBy(Api.LANGUAGE_MODEL) |
579 public Symbol getEnclosingElement() { |
582 public Symbol getEnclosingElement() { |
580 return owner; |
583 return owner; |
581 } |
584 } |
582 |
585 |
|
586 @DefinedBy(Api.LANGUAGE_MODEL) |
583 public ElementKind getKind() { |
587 public ElementKind getKind() { |
584 return ElementKind.OTHER; // most unkind |
588 return ElementKind.OTHER; // most unkind |
585 } |
589 } |
586 |
590 |
|
591 @DefinedBy(Api.LANGUAGE_MODEL) |
587 public Set<Modifier> getModifiers() { |
592 public Set<Modifier> getModifiers() { |
588 return Flags.asModifierSet(flags()); |
593 return Flags.asModifierSet(flags()); |
589 } |
594 } |
590 |
595 |
|
596 @DefinedBy(Api.LANGUAGE_MODEL) |
591 public Name getSimpleName() { |
597 public Name getSimpleName() { |
592 return name; |
598 return name; |
593 } |
599 } |
594 |
600 |
595 /** |
601 /** |
596 * This is the implementation for {@code |
602 * This is the implementation for {@code |
597 * javax.lang.model.element.Element.getAnnotationMirrors()}. |
603 * javax.lang.model.element.Element.getAnnotationMirrors()}. |
598 */ |
604 */ |
599 @Override |
605 @Override @DefinedBy(Api.LANGUAGE_MODEL) |
600 public List<Attribute.Compound> getAnnotationMirrors() { |
606 public List<Attribute.Compound> getAnnotationMirrors() { |
601 return getRawAttributes(); |
607 return getRawAttributes(); |
602 } |
608 } |
603 |
609 |
604 |
610 |
605 // TODO: getEnclosedElements should return a javac List, fix in FilteredMemberList |
611 // TODO: getEnclosedElements should return a javac List, fix in FilteredMemberList |
|
612 @DefinedBy(Api.LANGUAGE_MODEL) |
606 public java.util.List<Symbol> getEnclosedElements() { |
613 public java.util.List<Symbol> getEnclosedElements() { |
607 return List.nil(); |
614 return List.nil(); |
608 } |
615 } |
609 |
616 |
610 public List<TypeVariableSymbol> getTypeParameters() { |
617 public List<TypeVariableSymbol> getTypeParameters() { |
643 public boolean isEnclosedBy(ClassSymbol clazz) { return other.isEnclosedBy(clazz); } |
650 public boolean isEnclosedBy(ClassSymbol clazz) { return other.isEnclosedBy(clazz); } |
644 public boolean isInheritedIn(Symbol clazz, Types types) { return other.isInheritedIn(clazz, types); } |
651 public boolean isInheritedIn(Symbol clazz, Types types) { return other.isInheritedIn(clazz, types); } |
645 public Symbol asMemberOf(Type site, Types types) { return other.asMemberOf(site, types); } |
652 public Symbol asMemberOf(Type site, Types types) { return other.asMemberOf(site, types); } |
646 public void complete() throws CompletionFailure { other.complete(); } |
653 public void complete() throws CompletionFailure { other.complete(); } |
647 |
654 |
|
655 @DefinedBy(Api.LANGUAGE_MODEL) |
648 public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
656 public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
649 return other.accept(v, p); |
657 return other.accept(v, p); |
650 } |
658 } |
651 |
659 |
652 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
660 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
742 |
750 |
743 public TypeVariableSymbol(long flags, Name name, Type type, Symbol owner) { |
751 public TypeVariableSymbol(long flags, Name name, Type type, Symbol owner) { |
744 super(TYP, flags, name, type, owner); |
752 super(TYP, flags, name, type, owner); |
745 } |
753 } |
746 |
754 |
|
755 @DefinedBy(Api.LANGUAGE_MODEL) |
747 public ElementKind getKind() { |
756 public ElementKind getKind() { |
748 return ElementKind.TYPE_PARAMETER; |
757 return ElementKind.TYPE_PARAMETER; |
749 } |
758 } |
750 |
759 |
751 @Override |
760 @Override @DefinedBy(Api.LANGUAGE_MODEL) |
752 public Symbol getGenericElement() { |
761 public Symbol getGenericElement() { |
753 return owner; |
762 return owner; |
754 } |
763 } |
755 |
764 |
|
765 @DefinedBy(Api.LANGUAGE_MODEL) |
756 public List<Type> getBounds() { |
766 public List<Type> getBounds() { |
757 TypeVar t = (TypeVar)type; |
767 TypeVar t = (TypeVar)type; |
758 Type bound = t.getUpperBound(); |
768 Type bound = t.getUpperBound(); |
759 if (!bound.isCompound()) |
769 if (!bound.isCompound()) |
760 return List.of(bound); |
770 return List.of(bound); |
766 // In this case, supertype is Object, erasure is first interface. |
776 // In this case, supertype is Object, erasure is first interface. |
767 return ct.interfaces_field; |
777 return ct.interfaces_field; |
768 } |
778 } |
769 } |
779 } |
770 |
780 |
771 @Override |
781 @Override @DefinedBy(Api.LANGUAGE_MODEL) |
772 public List<Attribute.Compound> getAnnotationMirrors() { |
782 public List<Attribute.Compound> getAnnotationMirrors() { |
773 // Declaration annotations on type variables are stored in type attributes |
783 // Declaration annotations on type variables are stored in type attributes |
774 // on the owner of the TypeVariableSymbol |
784 // on the owner of the TypeVariableSymbol |
775 List<Attribute.TypeCompound> candidates = owner.getRawTypeAttributes(); |
785 List<Attribute.TypeCompound> candidates = owner.getRawTypeAttributes(); |
776 int index = owner.getTypeParameters().indexOf(this); |
786 int index = owner.getTypeParameters().indexOf(this); |
805 anno.position.type == TargetType.METHOD_TYPE_PARAMETER) && |
815 anno.position.type == TargetType.METHOD_TYPE_PARAMETER) && |
806 anno.position.parameter_index == index; |
816 anno.position.parameter_index == index; |
807 } |
817 } |
808 |
818 |
809 |
819 |
810 @Override |
820 @Override @DefinedBy(Api.LANGUAGE_MODEL) |
811 public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
821 public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
812 return v.visitTypeParameter(this, p); |
822 return v.visitTypeParameter(this, p); |
813 } |
823 } |
814 } |
824 } |
815 |
825 |
835 |
845 |
836 public String toString() { |
846 public String toString() { |
837 return fullname.toString(); |
847 return fullname.toString(); |
838 } |
848 } |
839 |
849 |
|
850 @DefinedBy(Api.LANGUAGE_MODEL) |
840 public Name getQualifiedName() { |
851 public Name getQualifiedName() { |
841 return fullname; |
852 return fullname; |
842 } |
853 } |
843 |
854 |
|
855 @DefinedBy(Api.LANGUAGE_MODEL) |
844 public boolean isUnnamed() { |
856 public boolean isUnnamed() { |
845 return name.isEmpty() && owner != null; |
857 return name.isEmpty() && owner != null; |
846 } |
858 } |
847 |
859 |
848 public WriteableScope members() { |
860 public WriteableScope members() { |
878 */ |
890 */ |
879 public boolean exists() { |
891 public boolean exists() { |
880 return (flags_field & EXISTS) != 0; |
892 return (flags_field & EXISTS) != 0; |
881 } |
893 } |
882 |
894 |
|
895 @DefinedBy(Api.LANGUAGE_MODEL) |
883 public ElementKind getKind() { |
896 public ElementKind getKind() { |
884 return ElementKind.PACKAGE; |
897 return ElementKind.PACKAGE; |
885 } |
898 } |
886 |
899 |
|
900 @DefinedBy(Api.LANGUAGE_MODEL) |
887 public Symbol getEnclosingElement() { |
901 public Symbol getEnclosingElement() { |
888 return null; |
902 return null; |
889 } |
903 } |
890 |
904 |
|
905 @DefinedBy(Api.LANGUAGE_MODEL) |
891 public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
906 public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
892 return v.visitPackage(this, p); |
907 return v.visitPackage(this, p); |
893 } |
908 } |
894 |
909 |
895 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
910 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
1039 this.type = new ErrorType(this, Type.noType); |
1055 this.type = new ErrorType(this, Type.noType); |
1040 throw ex; |
1056 throw ex; |
1041 } |
1057 } |
1042 } |
1058 } |
1043 |
1059 |
|
1060 @DefinedBy(Api.LANGUAGE_MODEL) |
1044 public List<Type> getInterfaces() { |
1061 public List<Type> getInterfaces() { |
1045 complete(); |
1062 complete(); |
1046 if (type instanceof ClassType) { |
1063 if (type instanceof ClassType) { |
1047 ClassType t = (ClassType)type; |
1064 ClassType t = (ClassType)type; |
1048 if (t.interfaces_field == null) // FIXME: shouldn't be null |
1065 if (t.interfaces_field == null) // FIXME: shouldn't be null |
1093 return sup == null ? super.getInheritedAnnotations(annoType) |
1111 return sup == null ? super.getInheritedAnnotations(annoType) |
1094 : sup.getAnnotationsByType(annoType); |
1112 : sup.getAnnotationsByType(annoType); |
1095 } |
1113 } |
1096 |
1114 |
1097 |
1115 |
|
1116 @DefinedBy(Api.LANGUAGE_MODEL) |
1098 public ElementKind getKind() { |
1117 public ElementKind getKind() { |
1099 long flags = flags(); |
1118 long flags = flags(); |
1100 if ((flags & ANNOTATION) != 0) |
1119 if ((flags & ANNOTATION) != 0) |
1101 return ElementKind.ANNOTATION_TYPE; |
1120 return ElementKind.ANNOTATION_TYPE; |
1102 else if ((flags & INTERFACE) != 0) |
1121 else if ((flags & INTERFACE) != 0) |
1105 return ElementKind.ENUM; |
1124 return ElementKind.ENUM; |
1106 else |
1125 else |
1107 return ElementKind.CLASS; |
1126 return ElementKind.CLASS; |
1108 } |
1127 } |
1109 |
1128 |
1110 @Override |
1129 @Override @DefinedBy(Api.LANGUAGE_MODEL) |
1111 public Set<Modifier> getModifiers() { |
1130 public Set<Modifier> getModifiers() { |
1112 long flags = flags(); |
1131 long flags = flags(); |
1113 return Flags.asModifierSet(flags & ~DEFAULT); |
1132 return Flags.asModifierSet(flags & ~DEFAULT); |
1114 } |
1133 } |
1115 |
1134 |
|
1135 @DefinedBy(Api.LANGUAGE_MODEL) |
1116 public NestingKind getNestingKind() { |
1136 public NestingKind getNestingKind() { |
1117 complete(); |
1137 complete(); |
1118 if (owner.kind == PCK) |
1138 if (owner.kind == PCK) |
1119 return NestingKind.TOP_LEVEL; |
1139 return NestingKind.TOP_LEVEL; |
1120 else if (name.isEmpty()) |
1140 else if (name.isEmpty()) |
1142 } |
1162 } |
1143 |
1163 |
1144 |
1164 |
1145 |
1165 |
1146 |
1166 |
|
1167 @DefinedBy(Api.LANGUAGE_MODEL) |
1147 public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
1168 public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
1148 return v.visitType(this, p); |
1169 return v.visitType(this, p); |
1149 } |
1170 } |
1150 |
1171 |
1151 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
1172 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
1221 |
1242 |
1222 public Symbol asMemberOf(Type site, Types types) { |
1243 public Symbol asMemberOf(Type site, Types types) { |
1223 return new VarSymbol(flags_field, name, types.memberType(site, this), owner); |
1244 return new VarSymbol(flags_field, name, types.memberType(site, this), owner); |
1224 } |
1245 } |
1225 |
1246 |
|
1247 @DefinedBy(Api.LANGUAGE_MODEL) |
1226 public ElementKind getKind() { |
1248 public ElementKind getKind() { |
1227 long flags = flags(); |
1249 long flags = flags(); |
1228 if ((flags & PARAMETER) != 0) { |
1250 if ((flags & PARAMETER) != 0) { |
1229 if (isExceptionParameter()) |
1251 if (isExceptionParameter()) |
1230 return ElementKind.EXCEPTION_PARAMETER; |
1252 return ElementKind.EXCEPTION_PARAMETER; |
1239 } else { |
1261 } else { |
1240 return ElementKind.LOCAL_VARIABLE; |
1262 return ElementKind.LOCAL_VARIABLE; |
1241 } |
1263 } |
1242 } |
1264 } |
1243 |
1265 |
|
1266 @DefinedBy(Api.LANGUAGE_MODEL) |
1244 public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
1267 public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
1245 return v.visitVariable(this, p); |
1268 return v.visitVariable(this, p); |
1246 } |
1269 } |
1247 |
1270 |
|
1271 @DefinedBy(Api.LANGUAGE_MODEL) |
1248 public Object getConstantValue() { // Mirror API |
1272 public Object getConstantValue() { // Mirror API |
1249 return Constants.decode(getConstValue(), type); |
1273 return Constants.decode(getConstValue(), type); |
1250 } |
1274 } |
1251 |
1275 |
1252 public void setLazyConstValue(final Env<AttrContext> env, |
1276 public void setLazyConstValue(final Env<AttrContext> env, |
1610 |
1634 |
1611 public Symbol asMemberOf(Type site, Types types) { |
1635 public Symbol asMemberOf(Type site, Types types) { |
1612 return new MethodSymbol(flags_field, name, types.memberType(site, this), owner); |
1636 return new MethodSymbol(flags_field, name, types.memberType(site, this), owner); |
1613 } |
1637 } |
1614 |
1638 |
|
1639 @DefinedBy(Api.LANGUAGE_MODEL) |
1615 public ElementKind getKind() { |
1640 public ElementKind getKind() { |
1616 if (name == name.table.names.init) |
1641 if (name == name.table.names.init) |
1617 return ElementKind.CONSTRUCTOR; |
1642 return ElementKind.CONSTRUCTOR; |
1618 else if (name == name.table.names.clinit) |
1643 else if (name == name.table.names.clinit) |
1619 return ElementKind.STATIC_INIT; |
1644 return ElementKind.STATIC_INIT; |
1626 public boolean isStaticOrInstanceInit() { |
1651 public boolean isStaticOrInstanceInit() { |
1627 return getKind() == ElementKind.STATIC_INIT || |
1652 return getKind() == ElementKind.STATIC_INIT || |
1628 getKind() == ElementKind.INSTANCE_INIT; |
1653 getKind() == ElementKind.INSTANCE_INIT; |
1629 } |
1654 } |
1630 |
1655 |
|
1656 @DefinedBy(Api.LANGUAGE_MODEL) |
1631 public Attribute getDefaultValue() { |
1657 public Attribute getDefaultValue() { |
1632 return defaultValue; |
1658 return defaultValue; |
1633 } |
1659 } |
1634 |
1660 |
|
1661 @DefinedBy(Api.LANGUAGE_MODEL) |
1635 public List<VarSymbol> getParameters() { |
1662 public List<VarSymbol> getParameters() { |
1636 return params(); |
1663 return params(); |
1637 } |
1664 } |
1638 |
1665 |
|
1666 @DefinedBy(Api.LANGUAGE_MODEL) |
1639 public boolean isVarArgs() { |
1667 public boolean isVarArgs() { |
1640 return (flags() & VARARGS) != 0; |
1668 return (flags() & VARARGS) != 0; |
1641 } |
1669 } |
1642 |
1670 |
|
1671 @DefinedBy(Api.LANGUAGE_MODEL) |
1643 public boolean isDefault() { |
1672 public boolean isDefault() { |
1644 return (flags() & DEFAULT) != 0; |
1673 return (flags() & DEFAULT) != 0; |
1645 } |
1674 } |
1646 |
1675 |
|
1676 @DefinedBy(Api.LANGUAGE_MODEL) |
1647 public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
1677 public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
1648 return v.visitExecutable(this, p); |
1678 return v.visitExecutable(this, p); |
1649 } |
1679 } |
1650 |
1680 |
1651 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
1681 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { |
1652 return v.visitMethodSymbol(this, p); |
1682 return v.visitMethodSymbol(this, p); |
1653 } |
1683 } |
1654 |
1684 |
|
1685 @DefinedBy(Api.LANGUAGE_MODEL) |
1655 public Type getReceiverType() { |
1686 public Type getReceiverType() { |
1656 return asType().getReceiverType(); |
1687 return asType().getReceiverType(); |
1657 } |
1688 } |
1658 |
1689 |
|
1690 @DefinedBy(Api.LANGUAGE_MODEL) |
1659 public Type getReturnType() { |
1691 public Type getReturnType() { |
1660 return asType().getReturnType(); |
1692 return asType().getReturnType(); |
1661 } |
1693 } |
1662 |
1694 |
|
1695 @DefinedBy(Api.LANGUAGE_MODEL) |
1663 public List<Type> getThrownTypes() { |
1696 public List<Type> getThrownTypes() { |
1664 return asType().getThrownTypes(); |
1697 return asType().getThrownTypes(); |
1665 } |
1698 } |
1666 } |
1699 } |
1667 |
1700 |