< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java

Print this page
rev 48841 : imported patch 8187950


  30 import java.util.Collections;
  31 import java.util.EnumSet;
  32 import java.util.Map;
  33 import java.util.Set;
  34 import java.util.concurrent.Callable;
  35 
  36 import javax.lang.model.element.Element;
  37 import javax.lang.model.element.ElementKind;
  38 import javax.lang.model.element.ElementVisitor;
  39 import javax.lang.model.element.ExecutableElement;
  40 import javax.lang.model.element.Modifier;
  41 import javax.lang.model.element.ModuleElement;
  42 import javax.lang.model.element.NestingKind;
  43 import javax.lang.model.element.PackageElement;
  44 import javax.lang.model.element.TypeElement;
  45 import javax.lang.model.element.TypeParameterElement;
  46 import javax.lang.model.element.VariableElement;
  47 import javax.tools.JavaFileManager;
  48 import javax.tools.JavaFileObject;
  49 
  50 import com.sun.tools.javac.code.ClassFinder.BadEnclosingMethodAttr;
  51 import com.sun.tools.javac.code.Directive.RequiresFlag;
  52 import com.sun.tools.javac.code.Kinds.Kind;
  53 import com.sun.tools.javac.comp.Annotate.AnnotationTypeMetadata;
  54 import com.sun.tools.javac.code.Scope.WriteableScope;
  55 import com.sun.tools.javac.code.Type.*;
  56 import com.sun.tools.javac.comp.Attr;
  57 import com.sun.tools.javac.comp.AttrContext;
  58 import com.sun.tools.javac.comp.Env;
  59 import com.sun.tools.javac.jvm.*;
  60 import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
  61 import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
  62 import com.sun.tools.javac.tree.JCTree.Tag;
  63 import com.sun.tools.javac.util.*;
  64 import com.sun.tools.javac.util.DefinedBy.Api;
  65 import com.sun.tools.javac.util.Name;
  66 
  67 import static com.sun.tools.javac.code.Flags.*;
  68 import static com.sun.tools.javac.code.Kinds.*;
  69 import static com.sun.tools.javac.code.Kinds.Kind.*;
  70 import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;

  71 import static com.sun.tools.javac.code.Symbol.OperatorSymbol.AccessCode.FIRSTASGOP;
  72 import static com.sun.tools.javac.code.TypeTag.CLASS;
  73 import static com.sun.tools.javac.code.TypeTag.FORALL;
  74 import static com.sun.tools.javac.code.TypeTag.TYPEVAR;
  75 import static com.sun.tools.javac.jvm.ByteCodes.iadd;
  76 import static com.sun.tools.javac.jvm.ByteCodes.ishll;
  77 import static com.sun.tools.javac.jvm.ByteCodes.lushrl;
  78 import static com.sun.tools.javac.jvm.ByteCodes.lxor;
  79 import static com.sun.tools.javac.jvm.ByteCodes.string_add;
  80 
  81 /** Root class for Java symbols. It contains subclasses
  82  *  for specific sorts of symbols, such as variables, methods and operators,
  83  *  types, packages. Each subclass is represented as a static inner class
  84  *  inside Symbol.
  85  *
  86  *  <p><b>This is NOT part of any supported API.
  87  *  If you write code that depends on this, you do so at your own risk.
  88  *  This code and its internal interfaces are subject to change or
  89  *  deletion without notice.</b>
  90  */


 617      *
 618      *  It is assumed that both symbols have the same name.  The static
 619      *  modifier is ignored for this test.
 620      *
 621      *  See JLS 8.4.6.1 (without transitivity) and 8.4.6.4
 622      */
 623     public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult) {
 624         return false;
 625     }
 626 
 627     /** Complete the elaboration of this symbol's definition.
 628      */
 629     public void complete() throws CompletionFailure {
 630         if (completer != Completer.NULL_COMPLETER) {
 631             Completer c = completer;
 632             completer = Completer.NULL_COMPLETER;
 633             c.complete(this);
 634         }
 635     }
 636 








 637     /** True if the symbol represents an entity that exists.
 638      */
 639     public boolean exists() {
 640         return true;
 641     }
 642 
 643     @DefinedBy(Api.LANGUAGE_MODEL)
 644     public Type asType() {
 645         return type;
 646     }
 647 
 648     @DefinedBy(Api.LANGUAGE_MODEL)
 649     public Symbol getEnclosingElement() {
 650         return owner;
 651     }
 652 
 653     @DefinedBy(Api.LANGUAGE_MODEL)
 654     public ElementKind getKind() {
 655         return ElementKind.OTHER;       // most unkind
 656     }
 657 
 658     @DefinedBy(Api.LANGUAGE_MODEL)
 659     public Set<Modifier> getModifiers() {

 660         return Flags.asModifierSet(flags());
 661     }
 662 
 663     @DefinedBy(Api.LANGUAGE_MODEL)
 664     public Name getSimpleName() {
 665         return name;
 666     }
 667 
 668     /**
 669      * This is the implementation for {@code
 670      * javax.lang.model.element.Element.getAnnotationMirrors()}.
 671      */
 672     @Override @DefinedBy(Api.LANGUAGE_MODEL)
 673     public List<Attribute.Compound> getAnnotationMirrors() {

 674         return getRawAttributes();
 675     }
 676 
 677 
 678     // TODO: getEnclosedElements should return a javac List, fix in FilteredMemberList
 679     @DefinedBy(Api.LANGUAGE_MODEL)
 680     public java.util.List<Symbol> getEnclosedElements() {
 681         return List.nil();
 682     }
 683 
 684     public List<TypeVariableSymbol> getTypeParameters() {
 685         ListBuffer<TypeVariableSymbol> l = new ListBuffer<>();
 686         for (Type t : type.getTypeArguments()) {
 687             Assert.check(t.tsym.getKind() == ElementKind.TYPE_PARAMETER);
 688             l.append((TypeVariableSymbol)t.tsym);
 689         }
 690         return l.toList();
 691     }
 692 
 693     public static class DelegatedSymbol<T extends Symbol> extends Symbol {


 778                 return false;
 779             if (type.hasTag(that.type.getTag())) {
 780                 if (type.hasTag(CLASS)) {
 781                     return
 782                         types.rank(that.type) < types.rank(this.type) ||
 783                         types.rank(that.type) == types.rank(this.type) &&
 784                         that.getQualifiedName().compareTo(this.getQualifiedName()) < 0;
 785                 } else if (type.hasTag(TYPEVAR)) {
 786                     return types.isSubtype(this.type, that.type);
 787                 }
 788             }
 789             return type.hasTag(TYPEVAR);
 790         }
 791 
 792         @Override @DefinedBy(Api.LANGUAGE_MODEL)
 793         public java.util.List<Symbol> getEnclosedElements() {
 794             List<Symbol> list = List.nil();
 795             if (kind == TYP && type.hasTag(TYPEVAR)) {
 796                 return list;
 797             }

 798             for (Symbol sym : members().getSymbols(NON_RECURSIVE)) {
 799                 try {
 800                     if (sym != null && (sym.flags() & SYNTHETIC) == 0 && sym.owner == this) {
 801                         list = list.prepend(sym);
 802                     }
 803                 } catch (BadEnclosingMethodAttr badEnclosingMethod) {
 804                     // ignore the exception
 805                 }
 806             }
 807             return list;
 808         }
 809 
 810         public AnnotationTypeMetadata getAnnotationTypeMetadata() {
 811             Assert.error("Only on ClassSymbol");
 812             return null; //unreachable
 813         }
 814 
 815         public boolean isAnnotationType() { return false; }
 816 
 817         @Override
 818         public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
 819             return v.visitTypeSymbol(this, p);
 820         }
 821     }
 822 
 823     /**
 824      * Type variables are represented by instances of this class.
 825      */


 963         public boolean isUnnamed() {
 964             return name.isEmpty() && owner == null;
 965         }
 966 
 967         @Override
 968         public boolean isDeprecated() {
 969             return hasDeprecatedAnnotation();
 970         }
 971 
 972         public boolean isNoModule() {
 973             return false;
 974         }
 975 
 976         @Override @DefinedBy(Api.LANGUAGE_MODEL)
 977         public ElementKind getKind() {
 978             return ElementKind.MODULE;
 979         }
 980 
 981         @Override @DefinedBy(Api.LANGUAGE_MODEL)
 982         public java.util.List<Directive> getDirectives() {
 983             complete();
 984             completeUsesProvides();
 985             return Collections.unmodifiableList(directives);
 986         }
 987 
 988         public void completeUsesProvides() {
 989             if (usesProvidesCompleter != Completer.NULL_COMPLETER) {
 990                 Completer c = usesProvidesCompleter;
 991                 usesProvidesCompleter = Completer.NULL_COMPLETER;
 992                 c.complete(this);
 993             }
 994         }
 995 
 996         @Override
 997         public ClassSymbol outermostClass() {
 998             return null;
 999         }
1000 
1001         @Override
1002         public String toString() {
1003             // TODO: the following strings should be localized


1287 
1288         public boolean isSubClass(Symbol base, Types types) {
1289             if (this == base) {
1290                 return true;
1291             } else if ((base.flags() & INTERFACE) != 0) {
1292                 for (Type t = type; t.hasTag(CLASS); t = types.supertype(t))
1293                     for (List<Type> is = types.interfaces(t);
1294                          is.nonEmpty();
1295                          is = is.tail)
1296                         if (is.head.tsym.isSubClass(base, types)) return true;
1297             } else {
1298                 for (Type t = type; t.hasTag(CLASS); t = types.supertype(t))
1299                     if (t.tsym == base) return true;
1300             }
1301             return false;
1302         }
1303 
1304         /** Complete the elaboration of this symbol's definition.
1305          */
1306         public void complete() throws CompletionFailure {

1307             try {
1308                 super.complete();
1309             } catch (CompletionFailure ex) {

1310                 // quiet error recovery
1311                 flags_field |= (PUBLIC|STATIC);
1312                 this.type = new ErrorType(this, Type.noType);
1313                 throw ex;
1314             }
1315         }
1316 
1317         @DefinedBy(Api.LANGUAGE_MODEL)
1318         public List<Type> getInterfaces() {
1319             complete();
1320             if (type instanceof ClassType) {
1321                 ClassType t = (ClassType)type;
1322                 if (t.interfaces_field == null) // FIXME: shouldn't be null
1323                     t.interfaces_field = List.nil();
1324                 if (t.all_interfaces_field != null)
1325                     return Type.getModelTypes(t.all_interfaces_field);
1326                 return t.interfaces_field;
1327             } else {
1328                 return List.nil();
1329             }
1330         }
1331 
1332         @DefinedBy(Api.LANGUAGE_MODEL)
1333         public Type getSuperclass() {
1334             complete();
1335             if (type instanceof ClassType) {
1336                 ClassType t = (ClassType)type;
1337                 if (t.supertype_field == null) // FIXME: shouldn't be null
1338                     t.supertype_field = Type.noType;
1339                 // An interface has no superclass; its supertype is Object.
1340                 return t.isInterface()
1341                     ? Type.noType
1342                     : t.supertype_field.getModelType();
1343             } else {
1344                 return Type.noType;
1345             }
1346         }
1347 
1348         /**
1349          * Returns the next class to search for inherited annotations or {@code null}
1350          * if the next class can't be found.
1351          */
1352         private ClassSymbol getSuperClassToSearchForAnnotations() {
1353 
1354             Type sup = getSuperclass();
1355 
1356             if (!sup.hasTag(CLASS) || sup.isErroneous())
1357                 return null;
1358 
1359             return (ClassSymbol) sup.tsym;
1360         }
1361 
1362 
1363         @Override
1364         protected <A extends Annotation> A[] getInheritedAnnotations(Class<A> annoType) {
1365 
1366             ClassSymbol sup = getSuperClassToSearchForAnnotations();
1367 
1368             return sup == null ? super.getInheritedAnnotations(annoType)
1369                                : sup.getAnnotationsByType(annoType);
1370         }
1371 
1372 
1373         @DefinedBy(Api.LANGUAGE_MODEL)
1374         public ElementKind getKind() {

1375             long flags = flags();
1376             if ((flags & ANNOTATION) != 0)
1377                 return ElementKind.ANNOTATION_TYPE;
1378             else if ((flags & INTERFACE) != 0)
1379                 return ElementKind.INTERFACE;
1380             else if ((flags & ENUM) != 0)
1381                 return ElementKind.ENUM;
1382             else
1383                 return ElementKind.CLASS;
1384         }
1385 
1386         @Override @DefinedBy(Api.LANGUAGE_MODEL)
1387         public Set<Modifier> getModifiers() {

1388             long flags = flags();
1389             return Flags.asModifierSet(flags & ~DEFAULT);
1390         }
1391 
1392         @DefinedBy(Api.LANGUAGE_MODEL)
1393         public NestingKind getNestingKind() {
1394             complete();
1395             if (owner.kind == PCK)
1396                 return NestingKind.TOP_LEVEL;
1397             else if (name.isEmpty())
1398                 return NestingKind.ANONYMOUS;
1399             else if (owner.kind == MTH)
1400                 return NestingKind.LOCAL;
1401             else
1402                 return NestingKind.MEMBER;
1403         }
1404 
1405 
1406         @Override
1407         protected <A extends Annotation> Attribute.Compound getAttribute(final Class<A> annoType) {
1408 
1409             Attribute.Compound attrib = super.getAttribute(annoType);
1410 
1411             boolean inherited = annoType.isAnnotationPresent(Inherited.class);
1412             if (attrib != null || !inherited)
1413                 return attrib;
1414 


2088         };
2089 
2090         void complete(Symbol sym) throws CompletionFailure;
2091 
2092         /** Returns true if this completer is <em>terminal</em>. A terminal
2093          * completer is used as a place holder when the symbol is completed.
2094          * Calling complete on a terminal completer will not affect the symbol.
2095          *
2096          * The dummy NULL_COMPLETER and the GraphDependencies completer are
2097          * examples of terminal completers.
2098          *
2099          * @return true iff this completer is terminal
2100          */
2101         default boolean isTerminal() {
2102             return false;
2103         }
2104     }
2105 
2106     public static class CompletionFailure extends RuntimeException {
2107         private static final long serialVersionUID = 0;

2108         public Symbol sym;
2109 
2110         /** A diagnostic object describing the failure
2111          */
2112         public JCDiagnostic diag;
2113 
2114         public CompletionFailure(Symbol sym, JCDiagnostic diag) {

2115             this.sym = sym;
2116             this.diag = diag;
2117 //          this.printStackTrace();//DEBUG
2118         }
2119 
2120         public JCDiagnostic getDiagnostic() {
2121             return diag;
2122         }
2123 
2124         @Override
2125         public String getMessage() {
2126             return diag.getMessage(null);
2127         }
2128 
2129         public JCDiagnostic getDetailValue() {
2130             return diag;
2131         }
2132 
2133         @Override
2134         public CompletionFailure initCause(Throwable cause) {




  30 import java.util.Collections;
  31 import java.util.EnumSet;
  32 import java.util.Map;
  33 import java.util.Set;
  34 import java.util.concurrent.Callable;
  35 
  36 import javax.lang.model.element.Element;
  37 import javax.lang.model.element.ElementKind;
  38 import javax.lang.model.element.ElementVisitor;
  39 import javax.lang.model.element.ExecutableElement;
  40 import javax.lang.model.element.Modifier;
  41 import javax.lang.model.element.ModuleElement;
  42 import javax.lang.model.element.NestingKind;
  43 import javax.lang.model.element.PackageElement;
  44 import javax.lang.model.element.TypeElement;
  45 import javax.lang.model.element.TypeParameterElement;
  46 import javax.lang.model.element.VariableElement;
  47 import javax.tools.JavaFileManager;
  48 import javax.tools.JavaFileObject;
  49 


  50 import com.sun.tools.javac.code.Kinds.Kind;
  51 import com.sun.tools.javac.comp.Annotate.AnnotationTypeMetadata;

  52 import com.sun.tools.javac.code.Type.*;
  53 import com.sun.tools.javac.comp.Attr;
  54 import com.sun.tools.javac.comp.AttrContext;
  55 import com.sun.tools.javac.comp.Env;
  56 import com.sun.tools.javac.jvm.*;
  57 import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
  58 import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
  59 import com.sun.tools.javac.tree.JCTree.Tag;
  60 import com.sun.tools.javac.util.*;
  61 import com.sun.tools.javac.util.DefinedBy.Api;
  62 import com.sun.tools.javac.util.Name;
  63 
  64 import static com.sun.tools.javac.code.Flags.*;
  65 import static com.sun.tools.javac.code.Kinds.*;
  66 import static com.sun.tools.javac.code.Kinds.Kind.*;
  67 import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
  68 import com.sun.tools.javac.code.Scope.WriteableScope;
  69 import static com.sun.tools.javac.code.Symbol.OperatorSymbol.AccessCode.FIRSTASGOP;
  70 import static com.sun.tools.javac.code.TypeTag.CLASS;
  71 import static com.sun.tools.javac.code.TypeTag.FORALL;
  72 import static com.sun.tools.javac.code.TypeTag.TYPEVAR;
  73 import static com.sun.tools.javac.jvm.ByteCodes.iadd;
  74 import static com.sun.tools.javac.jvm.ByteCodes.ishll;
  75 import static com.sun.tools.javac.jvm.ByteCodes.lushrl;
  76 import static com.sun.tools.javac.jvm.ByteCodes.lxor;
  77 import static com.sun.tools.javac.jvm.ByteCodes.string_add;
  78 
  79 /** Root class for Java symbols. It contains subclasses
  80  *  for specific sorts of symbols, such as variables, methods and operators,
  81  *  types, packages. Each subclass is represented as a static inner class
  82  *  inside Symbol.
  83  *
  84  *  <p><b>This is NOT part of any supported API.
  85  *  If you write code that depends on this, you do so at your own risk.
  86  *  This code and its internal interfaces are subject to change or
  87  *  deletion without notice.</b>
  88  */


 615      *
 616      *  It is assumed that both symbols have the same name.  The static
 617      *  modifier is ignored for this test.
 618      *
 619      *  See JLS 8.4.6.1 (without transitivity) and 8.4.6.4
 620      */
 621     public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult) {
 622         return false;
 623     }
 624 
 625     /** Complete the elaboration of this symbol's definition.
 626      */
 627     public void complete() throws CompletionFailure {
 628         if (completer != Completer.NULL_COMPLETER) {
 629             Completer c = completer;
 630             completer = Completer.NULL_COMPLETER;
 631             c.complete(this);
 632         }
 633     }
 634 
 635     public void apiComplete() throws CompletionFailure {
 636         try {
 637             complete();
 638         } catch (CompletionFailure cf) {
 639             cf.dcfh.handleAPICompletionFailure(cf);
 640         }
 641     }
 642 
 643     /** True if the symbol represents an entity that exists.
 644      */
 645     public boolean exists() {
 646         return true;
 647     }
 648 
 649     @DefinedBy(Api.LANGUAGE_MODEL)
 650     public Type asType() {
 651         return type;
 652     }
 653 
 654     @DefinedBy(Api.LANGUAGE_MODEL)
 655     public Symbol getEnclosingElement() {
 656         return owner;
 657     }
 658 
 659     @DefinedBy(Api.LANGUAGE_MODEL)
 660     public ElementKind getKind() {
 661         return ElementKind.OTHER;       // most unkind
 662     }
 663 
 664     @DefinedBy(Api.LANGUAGE_MODEL)
 665     public Set<Modifier> getModifiers() {
 666         apiComplete();
 667         return Flags.asModifierSet(flags());
 668     }
 669 
 670     @DefinedBy(Api.LANGUAGE_MODEL)
 671     public Name getSimpleName() {
 672         return name;
 673     }
 674 
 675     /**
 676      * This is the implementation for {@code
 677      * javax.lang.model.element.Element.getAnnotationMirrors()}.
 678      */
 679     @Override @DefinedBy(Api.LANGUAGE_MODEL)
 680     public List<Attribute.Compound> getAnnotationMirrors() {
 681         apiComplete();
 682         return getRawAttributes();
 683     }
 684 
 685 
 686     // TODO: getEnclosedElements should return a javac List, fix in FilteredMemberList
 687     @DefinedBy(Api.LANGUAGE_MODEL)
 688     public java.util.List<Symbol> getEnclosedElements() {
 689         return List.nil();
 690     }
 691 
 692     public List<TypeVariableSymbol> getTypeParameters() {
 693         ListBuffer<TypeVariableSymbol> l = new ListBuffer<>();
 694         for (Type t : type.getTypeArguments()) {
 695             Assert.check(t.tsym.getKind() == ElementKind.TYPE_PARAMETER);
 696             l.append((TypeVariableSymbol)t.tsym);
 697         }
 698         return l.toList();
 699     }
 700 
 701     public static class DelegatedSymbol<T extends Symbol> extends Symbol {


 786                 return false;
 787             if (type.hasTag(that.type.getTag())) {
 788                 if (type.hasTag(CLASS)) {
 789                     return
 790                         types.rank(that.type) < types.rank(this.type) ||
 791                         types.rank(that.type) == types.rank(this.type) &&
 792                         that.getQualifiedName().compareTo(this.getQualifiedName()) < 0;
 793                 } else if (type.hasTag(TYPEVAR)) {
 794                     return types.isSubtype(this.type, that.type);
 795                 }
 796             }
 797             return type.hasTag(TYPEVAR);
 798         }
 799 
 800         @Override @DefinedBy(Api.LANGUAGE_MODEL)
 801         public java.util.List<Symbol> getEnclosedElements() {
 802             List<Symbol> list = List.nil();
 803             if (kind == TYP && type.hasTag(TYPEVAR)) {
 804                 return list;
 805             }
 806             apiComplete();
 807             for (Symbol sym : members().getSymbols(NON_RECURSIVE)) {
 808                 sym.apiComplete();
 809                 if ((sym.flags() & SYNTHETIC) == 0 && sym.owner == this && sym.kind != ERR) {
 810                     list = list.prepend(sym);
 811                 }



 812             }
 813             return list;
 814         }
 815 
 816         public AnnotationTypeMetadata getAnnotationTypeMetadata() {
 817             Assert.error("Only on ClassSymbol");
 818             return null; //unreachable
 819         }
 820 
 821         public boolean isAnnotationType() { return false; }
 822 
 823         @Override
 824         public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
 825             return v.visitTypeSymbol(this, p);
 826         }
 827     }
 828 
 829     /**
 830      * Type variables are represented by instances of this class.
 831      */


 969         public boolean isUnnamed() {
 970             return name.isEmpty() && owner == null;
 971         }
 972 
 973         @Override
 974         public boolean isDeprecated() {
 975             return hasDeprecatedAnnotation();
 976         }
 977 
 978         public boolean isNoModule() {
 979             return false;
 980         }
 981 
 982         @Override @DefinedBy(Api.LANGUAGE_MODEL)
 983         public ElementKind getKind() {
 984             return ElementKind.MODULE;
 985         }
 986 
 987         @Override @DefinedBy(Api.LANGUAGE_MODEL)
 988         public java.util.List<Directive> getDirectives() {
 989             apiComplete();
 990             completeUsesProvides();
 991             return Collections.unmodifiableList(directives);
 992         }
 993 
 994         public void completeUsesProvides() {
 995             if (usesProvidesCompleter != Completer.NULL_COMPLETER) {
 996                 Completer c = usesProvidesCompleter;
 997                 usesProvidesCompleter = Completer.NULL_COMPLETER;
 998                 c.complete(this);
 999             }
1000         }
1001 
1002         @Override
1003         public ClassSymbol outermostClass() {
1004             return null;
1005         }
1006 
1007         @Override
1008         public String toString() {
1009             // TODO: the following strings should be localized


1293 
1294         public boolean isSubClass(Symbol base, Types types) {
1295             if (this == base) {
1296                 return true;
1297             } else if ((base.flags() & INTERFACE) != 0) {
1298                 for (Type t = type; t.hasTag(CLASS); t = types.supertype(t))
1299                     for (List<Type> is = types.interfaces(t);
1300                          is.nonEmpty();
1301                          is = is.tail)
1302                         if (is.head.tsym.isSubClass(base, types)) return true;
1303             } else {
1304                 for (Type t = type; t.hasTag(CLASS); t = types.supertype(t))
1305                     if (t.tsym == base) return true;
1306             }
1307             return false;
1308         }
1309 
1310         /** Complete the elaboration of this symbol's definition.
1311          */
1312         public void complete() throws CompletionFailure {
1313             Completer origCompleter = completer;
1314             try {
1315                 super.complete();
1316             } catch (CompletionFailure ex) {
1317                 ex.dcfh.classSymbolCompleteFailed(this, origCompleter);
1318                 // quiet error recovery
1319                 flags_field |= (PUBLIC|STATIC);
1320                 this.type = new ErrorType(this, Type.noType);
1321                 throw ex;
1322             }
1323         }
1324 
1325         @DefinedBy(Api.LANGUAGE_MODEL)
1326         public List<Type> getInterfaces() {
1327             apiComplete();
1328             if (type instanceof ClassType) {
1329                 ClassType t = (ClassType)type;
1330                 if (t.interfaces_field == null) // FIXME: shouldn't be null
1331                     t.interfaces_field = List.nil();
1332                 if (t.all_interfaces_field != null)
1333                     return Type.getModelTypes(t.all_interfaces_field);
1334                 return t.interfaces_field;
1335             } else {
1336                 return List.nil();
1337             }
1338         }
1339 
1340         @DefinedBy(Api.LANGUAGE_MODEL)
1341         public Type getSuperclass() {
1342             apiComplete();
1343             if (type instanceof ClassType) {
1344                 ClassType t = (ClassType)type;
1345                 if (t.supertype_field == null) // FIXME: shouldn't be null
1346                     t.supertype_field = Type.noType;
1347                 // An interface has no superclass; its supertype is Object.
1348                 return t.isInterface()
1349                     ? Type.noType
1350                     : t.supertype_field.getModelType();
1351             } else {
1352                 return Type.noType;
1353             }
1354         }
1355 
1356         /**
1357          * Returns the next class to search for inherited annotations or {@code null}
1358          * if the next class can't be found.
1359          */
1360         private ClassSymbol getSuperClassToSearchForAnnotations() {
1361 
1362             Type sup = getSuperclass();
1363 
1364             if (!sup.hasTag(CLASS) || sup.isErroneous())
1365                 return null;
1366 
1367             return (ClassSymbol) sup.tsym;
1368         }
1369 
1370 
1371         @Override
1372         protected <A extends Annotation> A[] getInheritedAnnotations(Class<A> annoType) {
1373 
1374             ClassSymbol sup = getSuperClassToSearchForAnnotations();
1375 
1376             return sup == null ? super.getInheritedAnnotations(annoType)
1377                                : sup.getAnnotationsByType(annoType);
1378         }
1379 
1380 
1381         @DefinedBy(Api.LANGUAGE_MODEL)
1382         public ElementKind getKind() {
1383             apiComplete();
1384             long flags = flags();
1385             if ((flags & ANNOTATION) != 0)
1386                 return ElementKind.ANNOTATION_TYPE;
1387             else if ((flags & INTERFACE) != 0)
1388                 return ElementKind.INTERFACE;
1389             else if ((flags & ENUM) != 0)
1390                 return ElementKind.ENUM;
1391             else
1392                 return ElementKind.CLASS;
1393         }
1394 
1395         @Override @DefinedBy(Api.LANGUAGE_MODEL)
1396         public Set<Modifier> getModifiers() {
1397             apiComplete();
1398             long flags = flags();
1399             return Flags.asModifierSet(flags & ~DEFAULT);
1400         }
1401 
1402         @DefinedBy(Api.LANGUAGE_MODEL)
1403         public NestingKind getNestingKind() {
1404             apiComplete();
1405             if (owner.kind == PCK)
1406                 return NestingKind.TOP_LEVEL;
1407             else if (name.isEmpty())
1408                 return NestingKind.ANONYMOUS;
1409             else if (owner.kind == MTH)
1410                 return NestingKind.LOCAL;
1411             else
1412                 return NestingKind.MEMBER;
1413         }
1414 
1415 
1416         @Override
1417         protected <A extends Annotation> Attribute.Compound getAttribute(final Class<A> annoType) {
1418 
1419             Attribute.Compound attrib = super.getAttribute(annoType);
1420 
1421             boolean inherited = annoType.isAnnotationPresent(Inherited.class);
1422             if (attrib != null || !inherited)
1423                 return attrib;
1424 


2098         };
2099 
2100         void complete(Symbol sym) throws CompletionFailure;
2101 
2102         /** Returns true if this completer is <em>terminal</em>. A terminal
2103          * completer is used as a place holder when the symbol is completed.
2104          * Calling complete on a terminal completer will not affect the symbol.
2105          *
2106          * The dummy NULL_COMPLETER and the GraphDependencies completer are
2107          * examples of terminal completers.
2108          *
2109          * @return true iff this completer is terminal
2110          */
2111         default boolean isTerminal() {
2112             return false;
2113         }
2114     }
2115 
2116     public static class CompletionFailure extends RuntimeException {
2117         private static final long serialVersionUID = 0;
2118         public final DeferredCompletionFailureHandler dcfh;
2119         public Symbol sym;
2120 
2121         /** A diagnostic object describing the failure
2122          */
2123         public JCDiagnostic diag;
2124 
2125         public CompletionFailure(Symbol sym, JCDiagnostic diag, DeferredCompletionFailureHandler dcfh) {
2126             this.dcfh = dcfh;
2127             this.sym = sym;
2128             this.diag = diag;
2129 //          this.printStackTrace();//DEBUG
2130         }
2131 
2132         public JCDiagnostic getDiagnostic() {
2133             return diag;
2134         }
2135 
2136         @Override
2137         public String getMessage() {
2138             return diag.getMessage(null);
2139         }
2140 
2141         public JCDiagnostic getDetailValue() {
2142             return diag;
2143         }
2144 
2145         @Override
2146         public CompletionFailure initCause(Throwable cause) {


< prev index next >