< 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.*;

 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()) {
1377                 List<RecordComponent> reversed = recordComponents.reverse();
1378                 for (RecordComponent rc : reversed) {
1379                     result = result.prepend(rc);
1380                 }
1381             }
1382             return result;
1383         }
1384 

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();

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

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

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

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

2120             case Flags.PRIVATE:
2121                 return false;
2122             case Flags.PUBLIC:
2123                 return !this.owner.isInterface() ||
2124                         (flags_field & STATIC) == 0;
2125             case Flags.PROTECTED:
2126                 return (origin.flags() & INTERFACE) == 0;
2127             case 0:
2128                 // for package private: can only override in the same
2129                 // package
2130                 return
2131                     this.packge() == origin.packge() &&
2132                     (origin.flags() & INTERFACE) == 0;
2133             default:
2134                 return false;
2135             }
2136         }
2137 
2138         @Override
2139         public boolean isInheritedIn(Symbol clazz, Types types) {

2140             switch ((int)(flags_field & Flags.AccessFlags)) {
2141                 case PUBLIC:
2142                     return !this.owner.isInterface() ||
2143                             clazz == owner ||
2144                             (flags_field & STATIC) == 0;
2145                 default:
2146                     return super.isInheritedIn(clazz, types);
2147             }
2148         }
2149 
2150         public boolean isLambdaMethod() {
2151             return (flags() & LAMBDA_METHOD) == LAMBDA_METHOD;
2152         }
2153 
2154         /** override this method to point to the original enclosing method if this method symbol represents a synthetic
2155          *  lambda method
2156          */
2157         public MethodSymbol originalEnclosingMethod() {
2158             return this;
2159         }

2426         private int accessCode = Integer.MIN_VALUE;
2427 
2428         public OperatorSymbol(Name name, Type type, int opcode, Symbol owner) {
2429             super(PUBLIC | STATIC, name, type, owner);
2430             this.opcode = opcode;
2431         }
2432 
2433         @Override
2434         public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
2435             return v.visitOperatorSymbol(this, p);
2436         }
2437 
2438         public int getAccessCode(Tag tag) {
2439             if (accessCode != Integer.MIN_VALUE && !tag.isIncOrDecUnaryOp()) {
2440                 return accessCode;
2441             }
2442             accessCode = AccessCode.from(tag, opcode);
2443             return accessCode;
2444         }
2445 
2446         /** Access codes for dereferencing, assignment,
2447          *  and pre/post increment/decrement.
2448 
2449          *  All access codes for accesses to the current class are even.
2450          *  If a member of the superclass should be accessed instead (because
2451          *  access was via a qualified super), add one to the corresponding code
2452          *  for the current class, making the number odd.
2453          *  This numbering scheme is used by the backend to decide whether
2454          *  to issue an invokevirtual or invokespecial call.
2455          *
2456          *  @see Gen#visitSelect(JCFieldAccess tree)
2457          */
2458         public enum AccessCode {
2459             UNKNOWN(-1, Tag.NO_TAG),
2460             DEREF(0, Tag.NO_TAG),
2461             ASSIGN(2, Tag.ASSIGN),
2462             PREINC(4, Tag.PREINC),
2463             PREDEC(6, Tag.PREDEC),
2464             POSTINC(8, Tag.POSTINC),
2465             POSTDEC(10, Tag.POSTDEC),
2466             FIRSTASGOP(12, Tag.NO_TAG);

2467 
2468             public final int code;
2469             public final Tag tag;
2470             public static final int numberOfAccessCodes = (lushrl - ishll + lxor + 2 - iadd) * 2 + FIRSTASGOP.code + 2;
2471 
2472             AccessCode(int code, Tag tag) {
2473                 this.code = code;
2474                 this.tag = tag;
2475             }
2476 
2477             public static AccessCode getFromCode(int code) {
2478                 for (AccessCode aCodes : AccessCode.values()) {
2479                     if (aCodes.code == code) {
2480                         return aCodes;
2481                     }
2482                 }
2483                 return UNKNOWN;
2484             }
2485 
2486             static int from(Tag tag, int opcode) {
2487                 /** Map bytecode of binary operation to access code of corresponding
2488                 *  assignment operation. This is always an even number.
2489                 */
2490                 switch (tag) {
2491                     case PREINC:
2492                         return AccessCode.PREINC.code;
2493                     case PREDEC:
2494                         return AccessCode.PREDEC.code;
2495                     case POSTINC:
2496                         return AccessCode.POSTINC.code;
2497                     case POSTDEC:
2498                         return AccessCode.POSTDEC.code;


2499                 }
2500                 if (iadd <= opcode && opcode <= lxor) {
2501                     return (opcode - iadd) * 2 + FIRSTASGOP.code;
2502                 } else if (opcode == string_add) {
2503                     return (lxor + 1 - iadd) * 2 + FIRSTASGOP.code;
2504                 } else if (ishll <= opcode && opcode <= lushrl) {
2505                     return (opcode - ishll + lxor + 2 - iadd) * 2 + FIRSTASGOP.code;
2506                 }
2507                 return -1;
2508             }
2509         }
2510     }
2511 
2512     /** Symbol completer interface.
2513      */
2514     public static interface Completer {
2515 
2516         /** Dummy completer to be used when the symbol has been completed or
2517          * does not need completion.
2518          */

  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.*;

 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 isSynthetic() {
 420         return (flags_field & SYNTHETIC) != 0;
 421     }
 422 
 423     public boolean isReferenceFavoringPrimitiveClass() {
 424         return (flags() & REFERENCE_FAVORING) != 0;  // bit set only for primitive classes
 425     }
 426 
 427     public boolean isPrimitiveClass() {
 428         return (flags() & PRIMITIVE_CLASS) != 0;
 429     }
 430 
 431     public boolean isPublic() {
 432         return (flags_field & Flags.AccessFlags) == PUBLIC;
 433     }
 434 
 435     public boolean isEnum() {
 436         return (flags() & ENUM) != 0;
 437     }
 438 
 439     public boolean isSealed() {
 440         return (flags_field & SEALED) != 0;
 441     }
 442 
 443     public boolean isNonSealed() {
 444         return (flags_field & NON_SEALED) != 0;
 445     }
 446 
 447     public boolean isFinal() {
 448         return (flags_field & FINAL) != 0;
 449     }
 450 

 452      *  to a method or variable initializer?
 453      *  Also includes fields of inner classes which are in
 454      *  turn local to a method or variable initializer.
 455      */
 456     public boolean isDirectlyOrIndirectlyLocal() {
 457         return
 458             (owner.kind.matches(KindSelector.VAL_MTH) ||
 459              (owner.kind == TYP && owner.isDirectlyOrIndirectlyLocal()));
 460     }
 461 
 462     /** Has this symbol an empty name? This includes anonymous
 463      *  inner classes.
 464      */
 465     public boolean isAnonymous() {
 466         return name.isEmpty();
 467     }
 468 
 469     /** Is this symbol a constructor?
 470      */
 471     public boolean isConstructor() {
 472         return name == name.table.names.init && (flags() & STATIC) == 0;
 473     }
 474 
 475     /** Is this symbol a primitive object factory?
 476      */
 477     public boolean isPrimitiveObjectFactory() {
 478         return ((name == name.table.names.init && this.type.getReturnType().tsym == this.owner));
 479     }
 480 
 481     public boolean isDynamic() {
 482         return false;
 483     }
 484 
 485     /** The fully qualified name of this symbol.
 486      *  This is the same as the symbol's name except for class symbols,
 487      *  which are handled separately.
 488      */
 489     public Name getQualifiedName() {
 490         return name;
 491     }
 492 
 493     /** The fully qualified name of this symbol after converting to flat
 494      *  representation. This is the same as the symbol's name except for
 495      *  class symbols, which are handled separately.
 496      */
 497     public Name flatName() {
 498         return getQualifiedName();

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

1417                         if (is.head.tsym.isSubClass(base, types)) return true;
1418             } else {
1419                 for (Type t = type; t.hasTag(CLASS); t = types.supertype(t))
1420                     if (t.tsym == base) return true;
1421             }
1422             return false;
1423         }
1424 
1425         /** Complete the elaboration of this symbol's definition.
1426          */
1427         public void complete() throws CompletionFailure {
1428             Completer origCompleter = completer;
1429             try {
1430                 super.complete();
1431             } catch (CompletionFailure ex) {
1432                 ex.dcfh.classSymbolCompleteFailed(this, origCompleter);
1433                 // quiet error recovery
1434                 flags_field |= (PUBLIC|STATIC);
1435                 this.type = new ErrorType(this, Type.noType);
1436                 throw ex;
1437             } finally {
1438                 if (this.type != null && this.type.hasTag(CLASS)) {
1439                     ClassType ct = (ClassType) this.type;
1440                     ct.flavor = ct.flavor.metamorphose(this.flags_field);
1441                     if (!this.type.isIntersection() && this.erasure_field != null && this.erasure_field.hasTag(CLASS)) {
1442                         ((ClassType) this.erasure_field).flavor = ct.flavor;
1443                     }
1444                 }
1445             }
1446         }
1447 
1448         @DefinedBy(Api.LANGUAGE_MODEL)
1449         public List<Type> getInterfaces() {
1450             apiComplete();
1451             if (type instanceof ClassType classType) {
1452                 if (classType.interfaces_field == null) // FIXME: shouldn't be null
1453                     classType.interfaces_field = List.nil();
1454                 if (classType.all_interfaces_field != null)
1455                     return Type.getModelTypes(classType.all_interfaces_field);
1456                 return classType.interfaces_field;
1457             } else {
1458                 return List.nil();
1459             }
1460         }
1461 
1462         @DefinedBy(Api.LANGUAGE_MODEL)
1463         public Type getSuperclass() {
1464             apiComplete();

1614                 if (types.firstUnimplementedAbstract(this) != null)
1615                     // add the ABSTRACT flag to an enum
1616                     flags_field |= ABSTRACT;
1617             }
1618         }
1619 
1620         /**Resets the Symbol into the state good for next round of annotation processing.*/
1621         public void reset() {
1622             kind = TYP;
1623             erasure_field = null;
1624             members_field = null;
1625             flags_field = 0;
1626             if (type instanceof ClassType classType) {
1627                 classType.setEnclosingType(Type.noType);
1628                 classType.rank_field = -1;
1629                 classType.typarams_field = null;
1630                 classType.allparams_field = null;
1631                 classType.supertype_field = null;
1632                 classType.interfaces_field = null;
1633                 classType.all_interfaces_field = null;
1634                 classType.flavor = Flavor.X_Typeof_X;
1635             }
1636             clearAnnotationMetadata();
1637         }
1638 
1639         public void clearAnnotationMetadata() {
1640             metadata = null;
1641             annotationTypeMetadata = AnnotationTypeMetadata.notAnAnnotationType();
1642         }
1643 
1644         @Override
1645         public AnnotationTypeMetadata getAnnotationTypeMetadata() {
1646             return annotationTypeMetadata;
1647         }
1648 
1649         @Override
1650         public boolean isAnnotationType() {
1651             return (flags_field & Flags.ANNOTATION) != 0;
1652         }
1653 
1654         public void setAnnotationTypeMetadata(AnnotationTypeMetadata a) {

2031                     // subst() for a parametric return type.
2032                     types.isSameType(type.getReturnType(),
2033                                      types.memberType(owner.type, sym).getReturnType())) {
2034                     impl = sym;
2035                 }
2036             }
2037             return impl;
2038         }
2039 
2040         /** Will the erasure of this method be considered by the VM to
2041          *  override the erasure of the other when seen from class `origin'?
2042          */
2043         public boolean binaryOverrides(Symbol _other, TypeSymbol origin, Types types) {
2044             if (isConstructor() || _other.kind != MTH) return false;
2045 
2046             if (this == _other) return true;
2047             MethodSymbol other = (MethodSymbol)_other;
2048 
2049             // check for a direct implementation
2050             if (other.isOverridableIn((TypeSymbol)owner) &&
2051                 types.asSuper(owner.type.referenceProjectionOrSelf(), other.owner) != null &&
2052                 types.isSameType(erasure(types), other.erasure(types)))
2053                 return true;
2054 
2055             // check for an inherited implementation
2056             return
2057                 (flags() & ABSTRACT) == 0 &&
2058                 other.isOverridableIn(origin) &&
2059                 this.isMemberOf(origin, types) &&
2060                 types.isSameType(erasure(types), other.erasure(types));
2061         }
2062 
2063         /** The implementation of this (abstract) symbol in class origin,
2064          *  from the VM's point of view, null if method does not have an
2065          *  implementation in class.
2066          *  @param origin   The class of which the implementation is a member.
2067          */
2068         public MethodSymbol binaryImplementation(ClassSymbol origin, Types types) {
2069             for (TypeSymbol c = origin; c != null; c = types.supertype(c.type).tsym) {
2070                 for (Symbol sym : c.members().getSymbolsByName(name)) {
2071                     if (sym.kind == MTH &&

2100          *  of origin.
2101          *
2102          *  Caveat: If `this' is an abstract inherited member of origin, it is
2103          *  deemed to override `other' only when `requireConcreteIfInherited'
2104          *  is false.
2105          *
2106          *  It is assumed that both symbols have the same name.  The static
2107          *  modifier is ignored for this test.
2108          *
2109          *  See JLS 8.4.6.1 (without transitivity) and 8.4.6.4
2110          */
2111         public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult,
2112                                             boolean requireConcreteIfInherited) {
2113             if (isConstructor() || _other.kind != MTH) return false;
2114 
2115             if (this == _other) return true;
2116             MethodSymbol other = (MethodSymbol)_other;
2117 
2118             // check for a direct implementation
2119             if (other.isOverridableIn((TypeSymbol)owner) &&
2120                 types.asSuper(owner.type.referenceProjectionOrSelf(), other.owner) != null) {
2121                 Type mt = types.memberType(owner.type, this);
2122                 Type ot = types.memberType(owner.type, other);
2123                 if (types.isSubSignature(mt, ot)) {
2124                     if (!checkResult)
2125                         return true;
2126                     if (types.returnTypeSubstitutable(mt, ot))
2127                         return true;
2128                 }
2129             }
2130 
2131             // check for an inherited implementation
2132             if (((flags() & ABSTRACT) != 0 && requireConcreteIfInherited) ||
2133                     ((other.flags() & ABSTRACT) == 0 && (other.flags() & DEFAULT) == 0) ||
2134                     !other.isOverridableIn(origin) ||
2135                     !this.isMemberOf(origin, types))
2136                 return false;
2137 
2138             // assert types.asSuper(origin.type, other.owner) != null;
2139             Type mt = types.memberType(origin.type, this);
2140             Type ot = types.memberType(origin.type, other);

2149             case Flags.PRIVATE:
2150                 return false;
2151             case Flags.PUBLIC:
2152                 return !this.owner.isInterface() ||
2153                         (flags_field & STATIC) == 0;
2154             case Flags.PROTECTED:
2155                 return (origin.flags() & INTERFACE) == 0;
2156             case 0:
2157                 // for package private: can only override in the same
2158                 // package
2159                 return
2160                     this.packge() == origin.packge() &&
2161                     (origin.flags() & INTERFACE) == 0;
2162             default:
2163                 return false;
2164             }
2165         }
2166 
2167         @Override
2168         public boolean isInheritedIn(Symbol clazz, Types types) {
2169 
2170             switch ((int)(flags_field & Flags.AccessFlags)) {
2171                 case PUBLIC:
2172                     return !this.owner.isInterface() ||
2173                             clazz == owner ||
2174                             (flags_field & STATIC) == 0;
2175                 default:
2176                     return super.isInheritedIn(clazz, types);
2177             }
2178         }
2179 
2180         public boolean isLambdaMethod() {
2181             return (flags() & LAMBDA_METHOD) == LAMBDA_METHOD;
2182         }
2183 
2184         /** override this method to point to the original enclosing method if this method symbol represents a synthetic
2185          *  lambda method
2186          */
2187         public MethodSymbol originalEnclosingMethod() {
2188             return this;
2189         }

2456         private int accessCode = Integer.MIN_VALUE;
2457 
2458         public OperatorSymbol(Name name, Type type, int opcode, Symbol owner) {
2459             super(PUBLIC | STATIC, name, type, owner);
2460             this.opcode = opcode;
2461         }
2462 
2463         @Override
2464         public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
2465             return v.visitOperatorSymbol(this, p);
2466         }
2467 
2468         public int getAccessCode(Tag tag) {
2469             if (accessCode != Integer.MIN_VALUE && !tag.isIncOrDecUnaryOp()) {
2470                 return accessCode;
2471             }
2472             accessCode = AccessCode.from(tag, opcode);
2473             return accessCode;
2474         }
2475 
2476         /** Access codes for dereferencing, assignment, withfield
2477          *  and pre/post increment/decrement.
2478 
2479          *  All access codes for accesses to the current class are even.
2480          *  If a member of the superclass should be accessed instead (because
2481          *  access was via a qualified super), add one to the corresponding code
2482          *  for the current class, making the number odd.
2483          *  This numbering scheme is used by the backend to decide whether
2484          *  to issue an invokevirtual or invokespecial call.
2485          *
2486          *  @see Gen#visitSelect(JCFieldAccess tree)
2487          */
2488         public enum AccessCode {
2489             UNKNOWN(-1, Tag.NO_TAG),
2490             DEREF(0, Tag.NO_TAG),
2491             ASSIGN(2, Tag.ASSIGN),
2492             PREINC(4, Tag.PREINC),
2493             PREDEC(6, Tag.PREDEC),
2494             POSTINC(8, Tag.POSTINC),
2495             POSTDEC(10, Tag.POSTDEC),
2496             WITHFIELD(12, Tag.WITHFIELD),
2497             FIRSTASGOP(14, Tag.NO_TAG);
2498 
2499             public final int code;
2500             public final Tag tag;
2501             public static final int numberOfAccessCodes = (lushrl - ishll + lxor + 2 - iadd) * 2 + FIRSTASGOP.code + 2;
2502 
2503             AccessCode(int code, Tag tag) {
2504                 this.code = code;
2505                 this.tag = tag;
2506             }
2507 
2508             public static AccessCode getFromCode(int code) {
2509                 for (AccessCode aCodes : AccessCode.values()) {
2510                     if (aCodes.code == code) {
2511                         return aCodes;
2512                     }
2513                 }
2514                 return UNKNOWN;
2515             }
2516 
2517             static int from(Tag tag, int opcode) {
2518                 /** Map bytecode of binary operation to access code of corresponding
2519                 *  assignment operation. This is always an even number.
2520                 */
2521                 switch (tag) {
2522                     case PREINC:
2523                         return AccessCode.PREINC.code;
2524                     case PREDEC:
2525                         return AccessCode.PREDEC.code;
2526                     case POSTINC:
2527                         return AccessCode.POSTINC.code;
2528                     case POSTDEC:
2529                         return AccessCode.POSTDEC.code;
2530                     case WITHFIELD:
2531                         return AccessCode.WITHFIELD.code;
2532                 }
2533                 if (iadd <= opcode && opcode <= lxor) {
2534                     return (opcode - iadd) * 2 + FIRSTASGOP.code;
2535                 } else if (opcode == string_add) {
2536                     return (lxor + 1 - iadd) * 2 + FIRSTASGOP.code;
2537                 } else if (ishll <= opcode && opcode <= lushrl) {
2538                     return (opcode - ishll + lxor + 2 - iadd) * 2 + FIRSTASGOP.code;
2539                 }
2540                 return -1;
2541             }
2542         }
2543     }
2544 
2545     /** Symbol completer interface.
2546      */
2547     public static interface Completer {
2548 
2549         /** Dummy completer to be used when the symbol has been completed or
2550          * does not need completion.
2551          */
< prev index next >