< prev index next >

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

Print this page

  35 import java.util.concurrent.Callable;
  36 import java.util.function.Supplier;
  37 import java.util.function.Predicate;
  38 
  39 import javax.lang.model.element.Element;
  40 import javax.lang.model.element.ElementKind;
  41 import javax.lang.model.element.ElementVisitor;
  42 import javax.lang.model.element.ExecutableElement;
  43 import javax.lang.model.element.Modifier;
  44 import javax.lang.model.element.ModuleElement;
  45 import javax.lang.model.element.NestingKind;
  46 import javax.lang.model.element.PackageElement;
  47 import javax.lang.model.element.RecordComponentElement;
  48 import javax.lang.model.element.TypeElement;
  49 import javax.lang.model.element.TypeParameterElement;
  50 import javax.lang.model.element.VariableElement;
  51 import javax.tools.JavaFileManager;
  52 import javax.tools.JavaFileObject;
  53 
  54 import com.sun.tools.javac.code.Kinds.Kind;

  55 import com.sun.tools.javac.comp.Annotate.AnnotationTypeMetadata;
  56 import com.sun.tools.javac.code.Type.*;
  57 import com.sun.tools.javac.comp.Attr;
  58 import com.sun.tools.javac.comp.AttrContext;
  59 import com.sun.tools.javac.comp.Env;
  60 import com.sun.tools.javac.jvm.*;
  61 import com.sun.tools.javac.jvm.PoolConstant;
  62 import com.sun.tools.javac.tree.JCTree;
  63 import com.sun.tools.javac.tree.JCTree.JCAnnotation;
  64 import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
  65 import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
  66 import com.sun.tools.javac.tree.JCTree.Tag;
  67 import com.sun.tools.javac.util.*;
  68 import com.sun.tools.javac.util.DefinedBy.Api;
  69 import com.sun.tools.javac.util.List;
  70 import com.sun.tools.javac.util.Name;
  71 
  72 import static com.sun.tools.javac.code.Flags.*;
  73 import static com.sun.tools.javac.code.Kinds.*;
  74 import static com.sun.tools.javac.code.Kinds.Kind.*;

 339     }
 340 
 341     public Symbol baseSymbol() {
 342         return this;
 343     }
 344 
 345     /** The symbol's erased type.
 346      */
 347     public Type erasure(Types types) {
 348         if (erasure_field == null)
 349             erasure_field = types.erasure(type);
 350         return erasure_field;
 351     }
 352 
 353     /** The external type of a symbol. This is the symbol's erased type
 354      *  except for constructors of inner classes which get the enclosing
 355      *  instance class added as first argument.
 356      */
 357     public Type externalType(Types types) {
 358         Type t = erasure(types);
 359         if (name == name.table.names.init && owner.hasOuterInstance()) {
 360             Type outerThisType = types.erasure(owner.type.getEnclosingType());
 361             return new MethodType(t.getParameterTypes().prepend(outerThisType),
 362                                   t.getReturnType(),
 363                                   t.getThrownTypes(),
 364                                   t.tsym);
 365         } else {
 366             return t;
 367         }
 368     }
 369 
 370     public boolean isDeprecated() {
 371         return (flags_field & DEPRECATED) != 0;
 372     }
 373 
 374     public boolean hasDeprecatedAnnotation() {
 375         return (flags_field & DEPRECATED_ANNOTATION) != 0;
 376     }
 377 
 378     public boolean isDeprecatedForRemoval() {
 379         return (flags_field & DEPRECATED_REMOVAL) != 0;

 398 
 399     public boolean isStatic() {
 400         return
 401             (flags() & STATIC) != 0 ||
 402             (owner.flags() & INTERFACE) != 0 && kind != MTH &&
 403              name != name.table.names._this;
 404     }
 405 
 406     public boolean isInterface() {
 407         return (flags() & INTERFACE) != 0;
 408     }
 409 
 410     public boolean isAbstract() {
 411         return (flags_field & ABSTRACT) != 0;
 412     }
 413 
 414     public boolean isPrivate() {
 415         return (flags_field & Flags.AccessFlags) == PRIVATE;
 416     }
 417 
























 418     public boolean isPublic() {
 419         return (flags_field & Flags.AccessFlags) == PUBLIC;
 420     }
 421 
 422     public boolean isEnum() {
 423         return (flags() & ENUM) != 0;
 424     }
 425 
 426     public boolean isSealed() {
 427         return (flags_field & SEALED) != 0;
 428     }
 429 
 430     public boolean isNonSealed() {
 431         return (flags_field & NON_SEALED) != 0;
 432     }
 433 
 434     public boolean isFinal() {
 435         return (flags_field & FINAL) != 0;
 436     }
 437 

 439      *  to a method or variable initializer?
 440      *  Also includes fields of inner classes which are in
 441      *  turn local to a method or variable initializer.
 442      */
 443     public boolean isDirectlyOrIndirectlyLocal() {
 444         return
 445             (owner.kind.matches(KindSelector.VAL_MTH) ||
 446              (owner.kind == TYP && owner.isDirectlyOrIndirectlyLocal()));
 447     }
 448 
 449     /** Has this symbol an empty name? This includes anonymous
 450      *  inner classes.
 451      */
 452     public boolean isAnonymous() {
 453         return name.isEmpty();
 454     }
 455 
 456     /** Is this symbol a constructor?
 457      */
 458     public boolean isConstructor() {
 459         return name == name.table.names.init;












 460     }
 461 
 462     public boolean isDynamic() {
 463         return false;
 464     }
 465 
 466     /** The fully qualified name of this symbol.
 467      *  This is the same as the symbol's name except for class symbols,
 468      *  which are handled separately.
 469      */
 470     public Name getQualifiedName() {
 471         return name;
 472     }
 473 
 474     /** The fully qualified name of this symbol after converting to flat
 475      *  representation. This is the same as the symbol's name except for
 476      *  class symbols, which are handled separately.
 477      */
 478     public Name flatName() {
 479         return getQualifiedName();

1299          */
1300         public List<Symbol> permitted;
1301 
1302         public boolean isPermittedExplicit = false;
1303 
1304         public ClassSymbol(long flags, Name name, Type type, Symbol owner) {
1305             super(TYP, flags, name, type, owner);
1306             this.members_field = null;
1307             this.fullname = formFullName(name, owner);
1308             this.flatname = formFlatName(name, owner);
1309             this.sourcefile = null;
1310             this.classfile = null;
1311             this.annotationTypeMetadata = AnnotationTypeMetadata.notAnAnnotationType();
1312             this.permitted = List.nil();
1313         }
1314 
1315         public ClassSymbol(long flags, Name name, Symbol owner) {
1316             this(
1317                 flags,
1318                 name,
1319                 new ClassType(Type.noType, null, null),
1320                 owner);
1321             this.type.tsym = this;
1322         }
1323 
1324         /** The Java source which this symbol represents.
1325          */
1326         public String toString() {
1327             return className();
1328         }
1329 
1330         public long flags() {
1331             complete();
1332             return flags_field;
1333         }
1334 
1335         public WriteableScope members() {
1336             complete();
1337             return members_field;
1338         }
1339 
1340         @Override
1341         public List<Attribute.Compound> getRawAttributes() {
1342             complete();
1343             return super.getRawAttributes();
1344         }
1345 
1346         @Override
1347         public List<Attribute.TypeCompound> getRawTypeAttributes() {
1348             complete();
1349             return super.getRawTypeAttributes();
1350         }
1351 
1352         public Type erasure(Types types) {
1353             if (erasure_field == null)
1354                 erasure_field = new ClassType(types.erasure(type.getEnclosingType()),
1355                                               List.nil(), this,
1356                                               type.getMetadata());

1357             return erasure_field;
1358         }
1359 
1360         public String className() {
1361             if (name.isEmpty())
1362                 return
1363                     Log.getLocalizedString("anonymous.class", flatname);
1364             else
1365                 return fullname.toString();
1366         }
1367 
1368         @DefinedBy(Api.LANGUAGE_MODEL)
1369         public Name getQualifiedName() {
1370             return fullname;
1371         }
1372 
1373         @Override @DefinedBy(Api.LANGUAGE_MODEL)
1374         public List<Symbol> getEnclosedElements() {
1375             List<Symbol> result = super.getEnclosedElements();
1376             if (!recordComponents.isEmpty()) {

1397                         if (is.head.tsym.isSubClass(base, types)) return true;
1398             } else {
1399                 for (Type t = type; t.hasTag(CLASS); t = types.supertype(t))
1400                     if (t.tsym == base) return true;
1401             }
1402             return false;
1403         }
1404 
1405         /** Complete the elaboration of this symbol's definition.
1406          */
1407         public void complete() throws CompletionFailure {
1408             Completer origCompleter = completer;
1409             try {
1410                 super.complete();
1411             } catch (CompletionFailure ex) {
1412                 ex.dcfh.classSymbolCompleteFailed(this, origCompleter);
1413                 // quiet error recovery
1414                 flags_field |= (PUBLIC|STATIC);
1415                 this.type = new ErrorType(this, Type.noType);
1416                 throw ex;








1417             }
1418         }
1419 
1420         @DefinedBy(Api.LANGUAGE_MODEL)
1421         public List<Type> getInterfaces() {
1422             apiComplete();
1423             if (type instanceof ClassType classType) {
1424                 if (classType.interfaces_field == null) // FIXME: shouldn't be null
1425                     classType.interfaces_field = List.nil();
1426                 if (classType.all_interfaces_field != null)
1427                     return Type.getModelTypes(classType.all_interfaces_field);
1428                 return classType.interfaces_field;
1429             } else {
1430                 return List.nil();
1431             }
1432         }
1433 
1434         @DefinedBy(Api.LANGUAGE_MODEL)
1435         public Type getSuperclass() {
1436             apiComplete();

1584                 if (types.firstUnimplementedAbstract(this) != null)
1585                     // add the ABSTRACT flag to an enum
1586                     flags_field |= ABSTRACT;
1587             }
1588         }
1589 
1590         /**Resets the Symbol into the state good for next round of annotation processing.*/
1591         public void reset() {
1592             kind = TYP;
1593             erasure_field = null;
1594             members_field = null;
1595             flags_field = 0;
1596             if (type instanceof ClassType classType) {
1597                 classType.setEnclosingType(Type.noType);
1598                 classType.rank_field = -1;
1599                 classType.typarams_field = null;
1600                 classType.allparams_field = null;
1601                 classType.supertype_field = null;
1602                 classType.interfaces_field = null;
1603                 classType.all_interfaces_field = null;

1604             }
1605             clearAnnotationMetadata();
1606         }
1607 
1608         public void clearAnnotationMetadata() {
1609             metadata = null;
1610             annotationTypeMetadata = AnnotationTypeMetadata.notAnAnnotationType();
1611         }
1612 
1613         @Override
1614         public AnnotationTypeMetadata getAnnotationTypeMetadata() {
1615             return annotationTypeMetadata;
1616         }
1617 
1618         @Override
1619         public boolean isAnnotationType() {
1620             return (flags_field & Flags.ANNOTATION) != 0;
1621         }
1622 
1623         public void setAnnotationTypeMetadata(AnnotationTypeMetadata a) {

1937                 public Object poolKey(Types types) {
1938                     return new Pair<>(newOwner, baseSymbol());
1939                 }
1940             };
1941             m.code = code;
1942             return m;
1943         }
1944 
1945         @Override @DefinedBy(Api.LANGUAGE_MODEL)
1946         public Set<Modifier> getModifiers() {
1947             long flags = flags();
1948             return Flags.asModifierSet((flags & DEFAULT) != 0 ? flags & ~ABSTRACT : flags);
1949         }
1950 
1951         /** The Java source which this symbol represents.
1952          */
1953         public String toString() {
1954             if ((flags() & BLOCK) != 0) {
1955                 return owner.name.toString();
1956             } else {
1957                 String s = (name == name.table.names.init)
1958                     ? owner.name.toString()
1959                     : name.toString();
1960                 if (type != null) {
1961                     if (type.hasTag(FORALL))
1962                         s = "<" + ((ForAll)type).getTypeArguments() + ">" + s;
1963                     s += "(" + type.argtypes((flags() & VARARGS) != 0) + ")";
1964                 }
1965                 return s;
1966             }
1967         }
1968 
1969         @Override
1970         public int poolTag() {
1971             return owner.isInterface() ?
1972                     ClassFile.CONSTANT_InterfaceMethodref : ClassFile.CONSTANT_Methodref;
1973         }
1974 
1975         public boolean isHandle() {
1976             return false;
1977         }

1999         }
2000 
2001         public Symbol implementedIn(TypeSymbol c, Types types) {
2002             Symbol impl = null;
2003             for (Symbol sym : c.members().getSymbolsByName(name)) {
2004                 if (this.overrides(sym, (TypeSymbol)owner, types, true) &&
2005                     // FIXME: I suspect the following requires a
2006                     // subst() for a parametric return type.
2007                     types.isSameType(type.getReturnType(),
2008                                      types.memberType(owner.type, sym).getReturnType())) {
2009                     impl = sym;
2010                 }
2011             }
2012             return impl;
2013         }
2014 
2015         /** Will the erasure of this method be considered by the VM to
2016          *  override the erasure of the other when seen from class `origin'?
2017          */
2018         public boolean binaryOverrides(Symbol _other, TypeSymbol origin, Types types) {
2019             if (isConstructor() || _other.kind != MTH) return false;
2020 
2021             if (this == _other) return true;
2022             MethodSymbol other = (MethodSymbol)_other;
2023 
2024             // check for a direct implementation
2025             if (other.isOverridableIn((TypeSymbol)owner) &&
2026                 types.asSuper(owner.type, other.owner) != null &&
2027                 types.isSameType(erasure(types), other.erasure(types)))
2028                 return true;
2029 
2030             // check for an inherited implementation
2031             return
2032                 (flags() & ABSTRACT) == 0 &&
2033                 other.isOverridableIn(origin) &&
2034                 this.isMemberOf(origin, types) &&
2035                 types.isSameType(erasure(types), other.erasure(types));
2036         }
2037 
2038         /** The implementation of this (abstract) symbol in class origin,
2039          *  from the VM's point of view, null if method does not have an
2040          *  implementation in class.
2041          *  @param origin   The class of which the implementation is a member.
2042          */
2043         public MethodSymbol binaryImplementation(ClassSymbol origin, Types types) {
2044             for (TypeSymbol c = origin; c != null; c = types.supertype(c.type).tsym) {
2045                 for (Symbol sym : c.members().getSymbolsByName(name)) {
2046                     if (sym.kind == MTH &&

2068          */
2069         public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult) {
2070             return overrides(_other, origin, types, checkResult, true);
2071         }
2072 
2073         /** Does this symbol override `other' symbol, when both are seen as
2074          *  members of class `origin'?  It is assumed that _other is a member
2075          *  of origin.
2076          *
2077          *  Caveat: If `this' is an abstract inherited member of origin, it is
2078          *  deemed to override `other' only when `requireConcreteIfInherited'
2079          *  is false.
2080          *
2081          *  It is assumed that both symbols have the same name.  The static
2082          *  modifier is ignored for this test.
2083          *
2084          *  See JLS 8.4.8.1 (without transitivity) and 8.4.8.4
2085          */
2086         public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult,
2087                                             boolean requireConcreteIfInherited) {
2088             if (isConstructor() || _other.kind != MTH) return false;
2089 
2090             if (this == _other) return true;
2091             MethodSymbol other = (MethodSymbol)_other;
2092 
2093             // check for a direct implementation
2094             if (other.isOverridableIn((TypeSymbol)owner) &&
2095                 types.asSuper(owner.type, other.owner) != null) {
2096                 Type mt = types.memberType(owner.type, this);
2097                 Type ot = types.memberType(owner.type, other);
2098                 if (types.isSubSignature(mt, ot)) {
2099                     if (!checkResult)
2100                         return true;
2101                     if (types.returnTypeSubstitutable(mt, ot))
2102                         return true;
2103                 }
2104             }
2105 
2106             // check for an inherited implementation
2107             if (((flags() & ABSTRACT) != 0 && requireConcreteIfInherited) ||
2108                     ((other.flags() & ABSTRACT) == 0 && (other.flags() & DEFAULT) == 0) ||
2109                     !other.isOverridableIn(origin) ||
2110                     !this.isMemberOf(origin, types))
2111                 return false;
2112 
2113             // assert types.asSuper(origin.type, other.owner) != null;
2114             Type mt = types.memberType(origin.type, this);
2115             Type ot = types.memberType(origin.type, other);

2192                 ListBuffer<VarSymbol> newParams = new ListBuffer<>();
2193                 int i = 0;
2194                 for (Type t : type.getParameterTypes()) {
2195                     Name paramName = name.table.fromString("arg" + i);
2196                     VarSymbol param = new VarSymbol(PARAMETER, paramName, t, this);
2197                     newParams.append(param);
2198                     i++;
2199                 }
2200                 params = newParams.toList();
2201             }
2202             Assert.checkNonNull(params);
2203             return params;
2204         }
2205 
2206         public Symbol asMemberOf(Type site, Types types) {
2207             return new MethodSymbol(flags_field, name, types.memberType(site, this), owner);
2208         }
2209 
2210         @DefinedBy(Api.LANGUAGE_MODEL)
2211         public ElementKind getKind() {
2212             if (name == name.table.names.init)
2213                 return ElementKind.CONSTRUCTOR;
2214             else if (name == name.table.names.clinit)
2215                 return ElementKind.STATIC_INIT;
2216             else if ((flags() & BLOCK) != 0)
2217                 return isStatic() ? ElementKind.STATIC_INIT : ElementKind.INSTANCE_INIT;
2218             else
2219                 return ElementKind.METHOD;
2220         }
2221 
2222         public boolean isStaticOrInstanceInit() {
2223             return getKind() == ElementKind.STATIC_INIT ||
2224                     getKind() == ElementKind.INSTANCE_INIT;
2225         }
2226 
2227         @DefinedBy(Api.LANGUAGE_MODEL)
2228         public Attribute getDefaultValue() {
2229             return defaultValue;
2230         }
2231 
2232         @DefinedBy(Api.LANGUAGE_MODEL)

2365 
2366         public MethodHandleSymbol(Symbol msym) {
2367             this(msym, false);
2368         }
2369 
2370         public MethodHandleSymbol(Symbol msym, boolean getter) {
2371             super(msym.flags_field, msym.name, msym.type, msym.owner);
2372             this.refSym = msym;
2373             this.getter = getter;
2374         }
2375 
2376         /**
2377          * Returns the kind associated with this method handle.
2378          */
2379         public int referenceKind() {
2380             if (refSym.kind == VAR) {
2381                 return getter ?
2382                         refSym.isStatic() ? ClassFile.REF_getStatic : ClassFile.REF_getField :
2383                         refSym.isStatic() ? ClassFile.REF_putStatic : ClassFile.REF_putField;
2384             } else {
2385                 if (refSym.isConstructor()) {
2386                     return ClassFile.REF_newInvokeSpecial;
2387                 } else {
2388                     if (refSym.isStatic()) {
2389                         return ClassFile.REF_invokeStatic;
2390                     } else if ((refSym.flags() & PRIVATE) != 0 && !allowPrivateInvokeVirtual()) {
2391                         return ClassFile.REF_invokeSpecial;
2392                     } else if (refSym.enclClass().isInterface()) {
2393                         return ClassFile.REF_invokeInterface;
2394                     } else {
2395                         return ClassFile.REF_invokeVirtual;
2396                     }
2397                 }
2398             }
2399         }
2400 
2401         private boolean allowPrivateInvokeVirtual() {
2402             Symbol rootPack = this;
2403             while (rootPack != null && !(rootPack instanceof RootPackageSymbol)) {
2404                 rootPack = rootPack.owner;
2405             }

  35 import java.util.concurrent.Callable;
  36 import java.util.function.Supplier;
  37 import java.util.function.Predicate;
  38 
  39 import javax.lang.model.element.Element;
  40 import javax.lang.model.element.ElementKind;
  41 import javax.lang.model.element.ElementVisitor;
  42 import javax.lang.model.element.ExecutableElement;
  43 import javax.lang.model.element.Modifier;
  44 import javax.lang.model.element.ModuleElement;
  45 import javax.lang.model.element.NestingKind;
  46 import javax.lang.model.element.PackageElement;
  47 import javax.lang.model.element.RecordComponentElement;
  48 import javax.lang.model.element.TypeElement;
  49 import javax.lang.model.element.TypeParameterElement;
  50 import javax.lang.model.element.VariableElement;
  51 import javax.tools.JavaFileManager;
  52 import javax.tools.JavaFileObject;
  53 
  54 import com.sun.tools.javac.code.Kinds.Kind;
  55 import com.sun.tools.javac.code.Type.ClassType.Flavor;
  56 import com.sun.tools.javac.comp.Annotate.AnnotationTypeMetadata;
  57 import com.sun.tools.javac.code.Type.*;
  58 import com.sun.tools.javac.comp.Attr;
  59 import com.sun.tools.javac.comp.AttrContext;
  60 import com.sun.tools.javac.comp.Env;
  61 import com.sun.tools.javac.jvm.*;
  62 import com.sun.tools.javac.jvm.PoolConstant;
  63 import com.sun.tools.javac.tree.JCTree;
  64 import com.sun.tools.javac.tree.JCTree.JCAnnotation;
  65 import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
  66 import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
  67 import com.sun.tools.javac.tree.JCTree.Tag;
  68 import com.sun.tools.javac.util.*;
  69 import com.sun.tools.javac.util.DefinedBy.Api;
  70 import com.sun.tools.javac.util.List;
  71 import com.sun.tools.javac.util.Name;
  72 
  73 import static com.sun.tools.javac.code.Flags.*;
  74 import static com.sun.tools.javac.code.Kinds.*;
  75 import static com.sun.tools.javac.code.Kinds.Kind.*;

 340     }
 341 
 342     public Symbol baseSymbol() {
 343         return this;
 344     }
 345 
 346     /** The symbol's erased type.
 347      */
 348     public Type erasure(Types types) {
 349         if (erasure_field == null)
 350             erasure_field = types.erasure(type);
 351         return erasure_field;
 352     }
 353 
 354     /** The external type of a symbol. This is the symbol's erased type
 355      *  except for constructors of inner classes which get the enclosing
 356      *  instance class added as first argument.
 357      */
 358     public Type externalType(Types types) {
 359         Type t = erasure(types);
 360         if (isInitOrVNew() && owner.hasOuterInstance()) {
 361             Type outerThisType = types.erasure(owner.type.getEnclosingType());
 362             return new MethodType(t.getParameterTypes().prepend(outerThisType),
 363                                   t.getReturnType(),
 364                                   t.getThrownTypes(),
 365                                   t.tsym);
 366         } else {
 367             return t;
 368         }
 369     }
 370 
 371     public boolean isDeprecated() {
 372         return (flags_field & DEPRECATED) != 0;
 373     }
 374 
 375     public boolean hasDeprecatedAnnotation() {
 376         return (flags_field & DEPRECATED_ANNOTATION) != 0;
 377     }
 378 
 379     public boolean isDeprecatedForRemoval() {
 380         return (flags_field & DEPRECATED_REMOVAL) != 0;

 399 
 400     public boolean isStatic() {
 401         return
 402             (flags() & STATIC) != 0 ||
 403             (owner.flags() & INTERFACE) != 0 && kind != MTH &&
 404              name != name.table.names._this;
 405     }
 406 
 407     public boolean isInterface() {
 408         return (flags() & INTERFACE) != 0;
 409     }
 410 
 411     public boolean isAbstract() {
 412         return (flags_field & ABSTRACT) != 0;
 413     }
 414 
 415     public boolean isPrivate() {
 416         return (flags_field & Flags.AccessFlags) == PRIVATE;
 417     }
 418 
 419     public boolean isPrimitiveClass() {
 420         return (flags() & PRIMITIVE_CLASS) != 0;
 421     }
 422 
 423     public boolean isValueClass() {
 424         return !isInterface() && (flags() & VALUE_CLASS) != 0;
 425     }
 426 
 427     public boolean isConcreteValueClass() {
 428         return isValueClass() && !isAbstract();
 429     }
 430 
 431     public boolean isIdentityClass() {
 432         return !isInterface() && (flags() & IDENTITY_TYPE) != 0;
 433     }
 434 
 435     public boolean isValueInterface() {
 436         return isInterface() && (flags() & VALUE_CLASS) != 0;
 437     }
 438 
 439     public boolean isIdentityInterface() {
 440         return isInterface() && (flags() & IDENTITY_TYPE) != 0;
 441     }
 442 
 443     public boolean isPublic() {
 444         return (flags_field & Flags.AccessFlags) == PUBLIC;
 445     }
 446 
 447     public boolean isEnum() {
 448         return (flags() & ENUM) != 0;
 449     }
 450 
 451     public boolean isSealed() {
 452         return (flags_field & SEALED) != 0;
 453     }
 454 
 455     public boolean isNonSealed() {
 456         return (flags_field & NON_SEALED) != 0;
 457     }
 458 
 459     public boolean isFinal() {
 460         return (flags_field & FINAL) != 0;
 461     }
 462 

 464      *  to a method or variable initializer?
 465      *  Also includes fields of inner classes which are in
 466      *  turn local to a method or variable initializer.
 467      */
 468     public boolean isDirectlyOrIndirectlyLocal() {
 469         return
 470             (owner.kind.matches(KindSelector.VAL_MTH) ||
 471              (owner.kind == TYP && owner.isDirectlyOrIndirectlyLocal()));
 472     }
 473 
 474     /** Has this symbol an empty name? This includes anonymous
 475      *  inner classes.
 476      */
 477     public boolean isAnonymous() {
 478         return name.isEmpty();
 479     }
 480 
 481     /** Is this symbol a constructor?
 482      */
 483     public boolean isConstructor() {
 484         return name == name.table.names.init && (flags() & STATIC) == 0;
 485     }
 486 
 487     /** Is this symbol a value object factory?
 488      */
 489     public boolean isValueObjectFactory() {
 490         return name == name.table.names.vnew && this.type.getReturnType().tsym == this.owner;
 491     }
 492 
 493     /** Is this symbol a constructor or value factory?
 494      */
 495     public boolean isInitOrVNew() {
 496         return name.table.names.isInitOrVNew(name);
 497     }
 498 
 499     public boolean isDynamic() {
 500         return false;
 501     }
 502 
 503     /** The fully qualified name of this symbol.
 504      *  This is the same as the symbol's name except for class symbols,
 505      *  which are handled separately.
 506      */
 507     public Name getQualifiedName() {
 508         return name;
 509     }
 510 
 511     /** The fully qualified name of this symbol after converting to flat
 512      *  representation. This is the same as the symbol's name except for
 513      *  class symbols, which are handled separately.
 514      */
 515     public Name flatName() {
 516         return getQualifiedName();

1336          */
1337         public List<Symbol> permitted;
1338 
1339         public boolean isPermittedExplicit = false;
1340 
1341         public ClassSymbol(long flags, Name name, Type type, Symbol owner) {
1342             super(TYP, flags, name, type, owner);
1343             this.members_field = null;
1344             this.fullname = formFullName(name, owner);
1345             this.flatname = formFlatName(name, owner);
1346             this.sourcefile = null;
1347             this.classfile = null;
1348             this.annotationTypeMetadata = AnnotationTypeMetadata.notAnAnnotationType();
1349             this.permitted = List.nil();
1350         }
1351 
1352         public ClassSymbol(long flags, Name name, Symbol owner) {
1353             this(
1354                 flags,
1355                 name,
1356                 new ClassType(Type.noType, null, null, TypeMetadata.EMPTY, Flavor.X_Typeof_X),
1357                 owner);
1358             this.type.tsym = this;
1359         }
1360 
1361         /** The Java source which this symbol represents.
1362          */
1363         public String toString() {
1364             return className();
1365         }
1366 
1367         public long flags() {
1368             complete();
1369             return flags_field;
1370         }
1371 
1372         public WriteableScope members() {
1373             complete();
1374             return members_field;
1375         }
1376 
1377         @Override
1378         public List<Attribute.Compound> getRawAttributes() {
1379             complete();
1380             return super.getRawAttributes();
1381         }
1382 
1383         @Override
1384         public List<Attribute.TypeCompound> getRawTypeAttributes() {
1385             complete();
1386             return super.getRawTypeAttributes();
1387         }
1388 
1389         public Type erasure(Types types) {
1390             if (erasure_field == null)
1391                 erasure_field = new ClassType(types.erasure(type.getEnclosingType()),
1392                                               List.nil(), this,
1393                                               type.getMetadata(),
1394                                               type.getFlavor());
1395             return erasure_field;
1396         }
1397 
1398         public String className() {
1399             if (name.isEmpty())
1400                 return
1401                     Log.getLocalizedString("anonymous.class", flatname);
1402             else
1403                 return fullname.toString();
1404         }
1405 
1406         @DefinedBy(Api.LANGUAGE_MODEL)
1407         public Name getQualifiedName() {
1408             return fullname;
1409         }
1410 
1411         @Override @DefinedBy(Api.LANGUAGE_MODEL)
1412         public List<Symbol> getEnclosedElements() {
1413             List<Symbol> result = super.getEnclosedElements();
1414             if (!recordComponents.isEmpty()) {

1435                         if (is.head.tsym.isSubClass(base, types)) return true;
1436             } else {
1437                 for (Type t = type; t.hasTag(CLASS); t = types.supertype(t))
1438                     if (t.tsym == base) return true;
1439             }
1440             return false;
1441         }
1442 
1443         /** Complete the elaboration of this symbol's definition.
1444          */
1445         public void complete() throws CompletionFailure {
1446             Completer origCompleter = completer;
1447             try {
1448                 super.complete();
1449             } catch (CompletionFailure ex) {
1450                 ex.dcfh.classSymbolCompleteFailed(this, origCompleter);
1451                 // quiet error recovery
1452                 flags_field |= (PUBLIC|STATIC);
1453                 this.type = new ErrorType(this, Type.noType);
1454                 throw ex;
1455             } finally {
1456                 if (this.type != null && this.type.hasTag(CLASS)) {
1457                     ClassType ct = (ClassType) this.type;
1458                     ct.flavor = ct.flavor.metamorphose((this.flags_field & PRIMITIVE_CLASS) != 0);
1459                     if (!this.type.isIntersection() && this.erasure_field != null && this.erasure_field.hasTag(CLASS)) {
1460                         ((ClassType) this.erasure_field).flavor = ct.flavor;
1461                     }
1462                 }
1463             }
1464         }
1465 
1466         @DefinedBy(Api.LANGUAGE_MODEL)
1467         public List<Type> getInterfaces() {
1468             apiComplete();
1469             if (type instanceof ClassType classType) {
1470                 if (classType.interfaces_field == null) // FIXME: shouldn't be null
1471                     classType.interfaces_field = List.nil();
1472                 if (classType.all_interfaces_field != null)
1473                     return Type.getModelTypes(classType.all_interfaces_field);
1474                 return classType.interfaces_field;
1475             } else {
1476                 return List.nil();
1477             }
1478         }
1479 
1480         @DefinedBy(Api.LANGUAGE_MODEL)
1481         public Type getSuperclass() {
1482             apiComplete();

1630                 if (types.firstUnimplementedAbstract(this) != null)
1631                     // add the ABSTRACT flag to an enum
1632                     flags_field |= ABSTRACT;
1633             }
1634         }
1635 
1636         /**Resets the Symbol into the state good for next round of annotation processing.*/
1637         public void reset() {
1638             kind = TYP;
1639             erasure_field = null;
1640             members_field = null;
1641             flags_field = 0;
1642             if (type instanceof ClassType classType) {
1643                 classType.setEnclosingType(Type.noType);
1644                 classType.rank_field = -1;
1645                 classType.typarams_field = null;
1646                 classType.allparams_field = null;
1647                 classType.supertype_field = null;
1648                 classType.interfaces_field = null;
1649                 classType.all_interfaces_field = null;
1650                 classType.flavor = Flavor.X_Typeof_X;
1651             }
1652             clearAnnotationMetadata();
1653         }
1654 
1655         public void clearAnnotationMetadata() {
1656             metadata = null;
1657             annotationTypeMetadata = AnnotationTypeMetadata.notAnAnnotationType();
1658         }
1659 
1660         @Override
1661         public AnnotationTypeMetadata getAnnotationTypeMetadata() {
1662             return annotationTypeMetadata;
1663         }
1664 
1665         @Override
1666         public boolean isAnnotationType() {
1667             return (flags_field & Flags.ANNOTATION) != 0;
1668         }
1669 
1670         public void setAnnotationTypeMetadata(AnnotationTypeMetadata a) {

1984                 public Object poolKey(Types types) {
1985                     return new Pair<>(newOwner, baseSymbol());
1986                 }
1987             };
1988             m.code = code;
1989             return m;
1990         }
1991 
1992         @Override @DefinedBy(Api.LANGUAGE_MODEL)
1993         public Set<Modifier> getModifiers() {
1994             long flags = flags();
1995             return Flags.asModifierSet((flags & DEFAULT) != 0 ? flags & ~ABSTRACT : flags);
1996         }
1997 
1998         /** The Java source which this symbol represents.
1999          */
2000         public String toString() {
2001             if ((flags() & BLOCK) != 0) {
2002                 return owner.name.toString();
2003             } else {
2004                 String s = isInitOrVNew()
2005                     ? owner.name.toString()
2006                     : name.toString();
2007                 if (type != null) {
2008                     if (type.hasTag(FORALL))
2009                         s = "<" + ((ForAll)type).getTypeArguments() + ">" + s;
2010                     s += "(" + type.argtypes((flags() & VARARGS) != 0) + ")";
2011                 }
2012                 return s;
2013             }
2014         }
2015 
2016         @Override
2017         public int poolTag() {
2018             return owner.isInterface() ?
2019                     ClassFile.CONSTANT_InterfaceMethodref : ClassFile.CONSTANT_Methodref;
2020         }
2021 
2022         public boolean isHandle() {
2023             return false;
2024         }

2046         }
2047 
2048         public Symbol implementedIn(TypeSymbol c, Types types) {
2049             Symbol impl = null;
2050             for (Symbol sym : c.members().getSymbolsByName(name)) {
2051                 if (this.overrides(sym, (TypeSymbol)owner, types, true) &&
2052                     // FIXME: I suspect the following requires a
2053                     // subst() for a parametric return type.
2054                     types.isSameType(type.getReturnType(),
2055                                      types.memberType(owner.type, sym).getReturnType())) {
2056                     impl = sym;
2057                 }
2058             }
2059             return impl;
2060         }
2061 
2062         /** Will the erasure of this method be considered by the VM to
2063          *  override the erasure of the other when seen from class `origin'?
2064          */
2065         public boolean binaryOverrides(Symbol _other, TypeSymbol origin, Types types) {
2066             if (isInitOrVNew() || _other.kind != MTH) return false;
2067 
2068             if (this == _other) return true;
2069             MethodSymbol other = (MethodSymbol)_other;
2070 
2071             // check for a direct implementation
2072             if (other.isOverridableIn((TypeSymbol)owner) &&
2073                 types.asSuper(owner.type.referenceProjectionOrSelf(), other.owner) != null &&
2074                 types.isSameType(erasure(types), other.erasure(types)))
2075                 return true;
2076 
2077             // check for an inherited implementation
2078             return
2079                 (flags() & ABSTRACT) == 0 &&
2080                 other.isOverridableIn(origin) &&
2081                 this.isMemberOf(origin, types) &&
2082                 types.isSameType(erasure(types), other.erasure(types));
2083         }
2084 
2085         /** The implementation of this (abstract) symbol in class origin,
2086          *  from the VM's point of view, null if method does not have an
2087          *  implementation in class.
2088          *  @param origin   The class of which the implementation is a member.
2089          */
2090         public MethodSymbol binaryImplementation(ClassSymbol origin, Types types) {
2091             for (TypeSymbol c = origin; c != null; c = types.supertype(c.type).tsym) {
2092                 for (Symbol sym : c.members().getSymbolsByName(name)) {
2093                     if (sym.kind == MTH &&

2115          */
2116         public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult) {
2117             return overrides(_other, origin, types, checkResult, true);
2118         }
2119 
2120         /** Does this symbol override `other' symbol, when both are seen as
2121          *  members of class `origin'?  It is assumed that _other is a member
2122          *  of origin.
2123          *
2124          *  Caveat: If `this' is an abstract inherited member of origin, it is
2125          *  deemed to override `other' only when `requireConcreteIfInherited'
2126          *  is false.
2127          *
2128          *  It is assumed that both symbols have the same name.  The static
2129          *  modifier is ignored for this test.
2130          *
2131          *  See JLS 8.4.8.1 (without transitivity) and 8.4.8.4
2132          */
2133         public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult,
2134                                             boolean requireConcreteIfInherited) {
2135             if (isInitOrVNew() || _other.kind != MTH) return false;
2136 
2137             if (this == _other) return true;
2138             MethodSymbol other = (MethodSymbol)_other;
2139 
2140             // check for a direct implementation
2141             if (other.isOverridableIn((TypeSymbol)owner) &&
2142                 types.asSuper(owner.type.referenceProjectionOrSelf(), other.owner) != null) {
2143                 Type mt = types.memberType(owner.type, this);
2144                 Type ot = types.memberType(owner.type, other);
2145                 if (types.isSubSignature(mt, ot)) {
2146                     if (!checkResult)
2147                         return true;
2148                     if (types.returnTypeSubstitutable(mt, ot))
2149                         return true;
2150                 }
2151             }
2152 
2153             // check for an inherited implementation
2154             if (((flags() & ABSTRACT) != 0 && requireConcreteIfInherited) ||
2155                     ((other.flags() & ABSTRACT) == 0 && (other.flags() & DEFAULT) == 0) ||
2156                     !other.isOverridableIn(origin) ||
2157                     !this.isMemberOf(origin, types))
2158                 return false;
2159 
2160             // assert types.asSuper(origin.type, other.owner) != null;
2161             Type mt = types.memberType(origin.type, this);
2162             Type ot = types.memberType(origin.type, other);

2239                 ListBuffer<VarSymbol> newParams = new ListBuffer<>();
2240                 int i = 0;
2241                 for (Type t : type.getParameterTypes()) {
2242                     Name paramName = name.table.fromString("arg" + i);
2243                     VarSymbol param = new VarSymbol(PARAMETER, paramName, t, this);
2244                     newParams.append(param);
2245                     i++;
2246                 }
2247                 params = newParams.toList();
2248             }
2249             Assert.checkNonNull(params);
2250             return params;
2251         }
2252 
2253         public Symbol asMemberOf(Type site, Types types) {
2254             return new MethodSymbol(flags_field, name, types.memberType(site, this), owner);
2255         }
2256 
2257         @DefinedBy(Api.LANGUAGE_MODEL)
2258         public ElementKind getKind() {
2259             if (isInitOrVNew())
2260                 return ElementKind.CONSTRUCTOR;
2261             else if (name == name.table.names.clinit)
2262                 return ElementKind.STATIC_INIT;
2263             else if ((flags() & BLOCK) != 0)
2264                 return isStatic() ? ElementKind.STATIC_INIT : ElementKind.INSTANCE_INIT;
2265             else
2266                 return ElementKind.METHOD;
2267         }
2268 
2269         public boolean isStaticOrInstanceInit() {
2270             return getKind() == ElementKind.STATIC_INIT ||
2271                     getKind() == ElementKind.INSTANCE_INIT;
2272         }
2273 
2274         @DefinedBy(Api.LANGUAGE_MODEL)
2275         public Attribute getDefaultValue() {
2276             return defaultValue;
2277         }
2278 
2279         @DefinedBy(Api.LANGUAGE_MODEL)

2412 
2413         public MethodHandleSymbol(Symbol msym) {
2414             this(msym, false);
2415         }
2416 
2417         public MethodHandleSymbol(Symbol msym, boolean getter) {
2418             super(msym.flags_field, msym.name, msym.type, msym.owner);
2419             this.refSym = msym;
2420             this.getter = getter;
2421         }
2422 
2423         /**
2424          * Returns the kind associated with this method handle.
2425          */
2426         public int referenceKind() {
2427             if (refSym.kind == VAR) {
2428                 return getter ?
2429                         refSym.isStatic() ? ClassFile.REF_getStatic : ClassFile.REF_getField :
2430                         refSym.isStatic() ? ClassFile.REF_putStatic : ClassFile.REF_putField;
2431             } else {
2432                 if (refSym.isInitOrVNew()) {
2433                     return ClassFile.REF_newInvokeSpecial;
2434                 } else {
2435                     if (refSym.isStatic()) {
2436                         return ClassFile.REF_invokeStatic;
2437                     } else if ((refSym.flags() & PRIVATE) != 0 && !allowPrivateInvokeVirtual()) {
2438                         return ClassFile.REF_invokeSpecial;
2439                     } else if (refSym.enclClass().isInterface()) {
2440                         return ClassFile.REF_invokeInterface;
2441                     } else {
2442                         return ClassFile.REF_invokeVirtual;
2443                     }
2444                 }
2445             }
2446         }
2447 
2448         private boolean allowPrivateInvokeVirtual() {
2449             Symbol rootPack = this;
2450             while (rootPack != null && !(rootPack instanceof RootPackageSymbol)) {
2451                 rootPack = rootPack.owner;
2452             }
< prev index next >