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();
1302 */
1303 public List<Symbol> permitted;
1304
1305 public boolean isPermittedExplicit = false;
1306
1307 public ClassSymbol(long flags, Name name, Type type, Symbol owner) {
1308 super(TYP, flags, name, type, owner);
1309 this.members_field = null;
1310 this.fullname = formFullName(name, owner);
1311 this.flatname = formFlatName(name, owner);
1312 this.sourcefile = null;
1313 this.classfile = null;
1314 this.annotationTypeMetadata = AnnotationTypeMetadata.notAnAnnotationType();
1315 this.permitted = List.nil();
1316 }
1317
1318 public ClassSymbol(long flags, Name name, Symbol owner) {
1319 this(
1320 flags,
1321 name,
1322 new ClassType(Type.noType, null, null),
1323 owner);
1324 this.type.tsym = this;
1325 }
1326
1327 /** The Java source which this symbol represents.
1328 */
1329 public String toString() {
1330 return className();
1331 }
1332
1333 public long flags() {
1334 complete();
1335 return flags_field;
1336 }
1337
1338 public WriteableScope members() {
1339 complete();
1340 return members_field;
1341 }
1342
1343 @Override
1344 public List<Attribute.Compound> getRawAttributes() {
1345 complete();
1346 return super.getRawAttributes();
1347 }
1348
1349 @Override
1350 public List<Attribute.TypeCompound> getRawTypeAttributes() {
1351 complete();
1352 return super.getRawTypeAttributes();
1353 }
1354
1355 public Type erasure(Types types) {
1356 if (erasure_field == null)
1357 erasure_field = new ClassType(types.erasure(type.getEnclosingType()),
1358 List.nil(), this,
1359 type.getMetadata());
1360 return erasure_field;
1361 }
1362
1363 public String className() {
1364 if (name.isEmpty())
1365 return
1366 Log.getLocalizedString("anonymous.class", flatname);
1367 else
1368 return fullname.toString();
1369 }
1370
1371 @Override @DefinedBy(Api.LANGUAGE_MODEL)
1372 public Name getQualifiedName() {
1373 return isUnnamed() ? fullname.subName(0, 0) /* empty name */ : fullname;
1374 }
1375
1376 @Override @DefinedBy(Api.LANGUAGE_MODEL)
1377 public Name getSimpleName() {
1378 return name;
1379 }
1405 if (is.head.tsym.isSubClass(base, types)) return true;
1406 } else {
1407 for (Type t = type; t.hasTag(CLASS); t = types.supertype(t))
1408 if (t.tsym == base) return true;
1409 }
1410 return false;
1411 }
1412
1413 /** Complete the elaboration of this symbol's definition.
1414 */
1415 public void complete() throws CompletionFailure {
1416 Completer origCompleter = completer;
1417 try {
1418 super.complete();
1419 } catch (CompletionFailure ex) {
1420 ex.dcfh.classSymbolCompleteFailed(this, origCompleter);
1421 // quiet error recovery
1422 flags_field |= (PUBLIC|STATIC);
1423 this.type = new ErrorType(this, Type.noType);
1424 throw ex;
1425 }
1426 }
1427
1428 @DefinedBy(Api.LANGUAGE_MODEL)
1429 public List<Type> getInterfaces() {
1430 apiComplete();
1431 if (type instanceof ClassType classType) {
1432 if (classType.interfaces_field == null) // FIXME: shouldn't be null
1433 classType.interfaces_field = List.nil();
1434 if (classType.all_interfaces_field != null)
1435 return Type.getModelTypes(classType.all_interfaces_field);
1436 return classType.interfaces_field;
1437 } else {
1438 return List.nil();
1439 }
1440 }
1441
1442 @DefinedBy(Api.LANGUAGE_MODEL)
1443 public Type getSuperclass() {
1444 apiComplete();
1592 if (types.firstUnimplementedAbstract(this) != null)
1593 // add the ABSTRACT flag to an enum
1594 flags_field |= ABSTRACT;
1595 }
1596 }
1597
1598 /**Resets the Symbol into the state good for next round of annotation processing.*/
1599 public void reset() {
1600 kind = TYP;
1601 erasure_field = null;
1602 members_field = null;
1603 flags_field = 0;
1604 if (type instanceof ClassType classType) {
1605 classType.setEnclosingType(Type.noType);
1606 classType.rank_field = -1;
1607 classType.typarams_field = null;
1608 classType.allparams_field = null;
1609 classType.supertype_field = null;
1610 classType.interfaces_field = null;
1611 classType.all_interfaces_field = null;
1612 }
1613 clearAnnotationMetadata();
1614 }
1615
1616 public void clearAnnotationMetadata() {
1617 metadata = null;
1618 annotationTypeMetadata = AnnotationTypeMetadata.notAnAnnotationType();
1619 }
1620
1621 @Override
1622 public AnnotationTypeMetadata getAnnotationTypeMetadata() {
1623 return annotationTypeMetadata;
1624 }
1625
1626 @Override
1627 public boolean isAnnotationType() {
1628 return (flags_field & Flags.ANNOTATION) != 0;
1629 }
1630
1631 public void setAnnotationTypeMetadata(AnnotationTypeMetadata a) {
1955 public Object poolKey(Types types) {
1956 return new Pair<>(newOwner, baseSymbol());
1957 }
1958 };
1959 m.code = code;
1960 return m;
1961 }
1962
1963 @Override @DefinedBy(Api.LANGUAGE_MODEL)
1964 public Set<Modifier> getModifiers() {
1965 long flags = flags();
1966 return Flags.asModifierSet((flags & DEFAULT) != 0 ? flags & ~ABSTRACT : flags);
1967 }
1968
1969 /** The Java source which this symbol represents.
1970 */
1971 public String toString() {
1972 if ((flags() & BLOCK) != 0) {
1973 return owner.name.toString();
1974 } else {
1975 String s = (name == name.table.names.init)
1976 ? owner.name.toString()
1977 : name.toString();
1978 if (type != null) {
1979 if (type.hasTag(FORALL))
1980 s = "<" + ((ForAll)type).getTypeArguments() + ">" + s;
1981 s += "(" + type.argtypes((flags() & VARARGS) != 0) + ")";
1982 }
1983 return s;
1984 }
1985 }
1986
1987 @Override
1988 public int poolTag() {
1989 return owner.isInterface() ?
1990 ClassFile.CONSTANT_InterfaceMethodref : ClassFile.CONSTANT_Methodref;
1991 }
1992
1993 public boolean isHandle() {
1994 return false;
1995 }
2017 }
2018
2019 public Symbol implementedIn(TypeSymbol c, Types types) {
2020 Symbol impl = null;
2021 for (Symbol sym : c.members().getSymbolsByName(name)) {
2022 if (this.overrides(sym, (TypeSymbol)owner, types, true) &&
2023 // FIXME: I suspect the following requires a
2024 // subst() for a parametric return type.
2025 types.isSameType(type.getReturnType(),
2026 types.memberType(owner.type, sym).getReturnType())) {
2027 impl = sym;
2028 }
2029 }
2030 return impl;
2031 }
2032
2033 /** Will the erasure of this method be considered by the VM to
2034 * override the erasure of the other when seen from class `origin'?
2035 */
2036 public boolean binaryOverrides(Symbol _other, TypeSymbol origin, Types types) {
2037 if (isConstructor() || _other.kind != MTH) return false;
2038
2039 if (this == _other) return true;
2040 MethodSymbol other = (MethodSymbol)_other;
2041
2042 // check for a direct implementation
2043 if (other.isOverridableIn((TypeSymbol)owner) &&
2044 types.asSuper(owner.type, other.owner) != null &&
2045 types.isSameType(erasure(types), other.erasure(types)))
2046 return true;
2047
2048 // check for an inherited implementation
2049 return
2050 (flags() & ABSTRACT) == 0 &&
2051 other.isOverridableIn(origin) &&
2052 this.isMemberOf(origin, types) &&
2053 types.isSameType(erasure(types), other.erasure(types));
2054 }
2055
2056 /** The implementation of this (abstract) symbol in class origin,
2057 * from the VM's point of view, null if method does not have an
2058 * implementation in class.
2059 * @param origin The class of which the implementation is a member.
2060 */
2061 public MethodSymbol binaryImplementation(ClassSymbol origin, Types types) {
2062 for (TypeSymbol c = origin; c != null; c = types.supertype(c.type).tsym) {
2063 for (Symbol sym : c.members().getSymbolsByName(name)) {
2064 if (sym.kind == MTH &&
2086 */
2087 public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult) {
2088 return overrides(_other, origin, types, checkResult, true);
2089 }
2090
2091 /** Does this symbol override `other' symbol, when both are seen as
2092 * members of class `origin'? It is assumed that _other is a member
2093 * of origin.
2094 *
2095 * Caveat: If `this' is an abstract inherited member of origin, it is
2096 * deemed to override `other' only when `requireConcreteIfInherited'
2097 * is false.
2098 *
2099 * It is assumed that both symbols have the same name. The static
2100 * modifier is ignored for this test.
2101 *
2102 * See JLS 8.4.8.1 (without transitivity) and 8.4.8.4
2103 */
2104 public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult,
2105 boolean requireConcreteIfInherited) {
2106 if (isConstructor() || _other.kind != MTH) return false;
2107
2108 if (this == _other) return true;
2109 MethodSymbol other = (MethodSymbol)_other;
2110
2111 // check for a direct implementation
2112 if (other.isOverridableIn((TypeSymbol)owner) &&
2113 types.asSuper(owner.type, other.owner) != null) {
2114 Type mt = types.memberType(owner.type, this);
2115 Type ot = types.memberType(owner.type, other);
2116 if (types.isSubSignature(mt, ot)) {
2117 if (!checkResult)
2118 return true;
2119 if (types.returnTypeSubstitutable(mt, ot))
2120 return true;
2121 }
2122 }
2123
2124 // check for an inherited implementation
2125 if (((flags() & ABSTRACT) != 0 && requireConcreteIfInherited) ||
2126 ((other.flags() & ABSTRACT) == 0 && (other.flags() & DEFAULT) == 0) ||
2127 !other.isOverridableIn(origin) ||
2128 !this.isMemberOf(origin, types))
2129 return false;
2130
2131 // assert types.asSuper(origin.type, other.owner) != null;
2132 Type mt = types.memberType(origin.type, this);
2133 Type ot = types.memberType(origin.type, other);
2210 ListBuffer<VarSymbol> newParams = new ListBuffer<>();
2211 int i = 0;
2212 for (Type t : type.getParameterTypes()) {
2213 Name paramName = name.table.fromString("arg" + i);
2214 VarSymbol param = new VarSymbol(PARAMETER, paramName, t, this);
2215 newParams.append(param);
2216 i++;
2217 }
2218 params = newParams.toList();
2219 }
2220 Assert.checkNonNull(params);
2221 return params;
2222 }
2223
2224 public Symbol asMemberOf(Type site, Types types) {
2225 return new MethodSymbol(flags_field, name, types.memberType(site, this), owner);
2226 }
2227
2228 @DefinedBy(Api.LANGUAGE_MODEL)
2229 public ElementKind getKind() {
2230 if (name == name.table.names.init)
2231 return ElementKind.CONSTRUCTOR;
2232 else if (name == name.table.names.clinit)
2233 return ElementKind.STATIC_INIT;
2234 else if ((flags() & BLOCK) != 0)
2235 return isStatic() ? ElementKind.STATIC_INIT : ElementKind.INSTANCE_INIT;
2236 else
2237 return ElementKind.METHOD;
2238 }
2239
2240 public boolean isStaticOrInstanceInit() {
2241 return getKind() == ElementKind.STATIC_INIT ||
2242 getKind() == ElementKind.INSTANCE_INIT;
2243 }
2244
2245 @DefinedBy(Api.LANGUAGE_MODEL)
2246 public Attribute getDefaultValue() {
2247 return defaultValue;
2248 }
2249
2250 @DefinedBy(Api.LANGUAGE_MODEL)
2383
2384 public MethodHandleSymbol(Symbol msym) {
2385 this(msym, false);
2386 }
2387
2388 public MethodHandleSymbol(Symbol msym, boolean getter) {
2389 super(msym.flags_field, msym.name, msym.type, msym.owner);
2390 this.refSym = msym;
2391 this.getter = getter;
2392 }
2393
2394 /**
2395 * Returns the kind associated with this method handle.
2396 */
2397 public int referenceKind() {
2398 if (refSym.kind == VAR) {
2399 return getter ?
2400 refSym.isStatic() ? ClassFile.REF_getStatic : ClassFile.REF_getField :
2401 refSym.isStatic() ? ClassFile.REF_putStatic : ClassFile.REF_putField;
2402 } else {
2403 if (refSym.isConstructor()) {
2404 return ClassFile.REF_newInvokeSpecial;
2405 } else {
2406 if (refSym.isStatic()) {
2407 return ClassFile.REF_invokeStatic;
2408 } else if ((refSym.flags() & PRIVATE) != 0 && !allowPrivateInvokeVirtual()) {
2409 return ClassFile.REF_invokeSpecial;
2410 } else if (refSym.enclClass().isInterface()) {
2411 return ClassFile.REF_invokeInterface;
2412 } else {
2413 return ClassFile.REF_invokeVirtual;
2414 }
2415 }
2416 }
2417 }
2418
2419 private boolean allowPrivateInvokeVirtual() {
2420 Symbol rootPack = this;
2421 while (rootPack != null && !(rootPack instanceof RootPackageSymbol)) {
2422 rootPack = rootPack.owner;
2423 }
|
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();
1339 */
1340 public List<Symbol> permitted;
1341
1342 public boolean isPermittedExplicit = false;
1343
1344 public ClassSymbol(long flags, Name name, Type type, Symbol owner) {
1345 super(TYP, flags, name, type, owner);
1346 this.members_field = null;
1347 this.fullname = formFullName(name, owner);
1348 this.flatname = formFlatName(name, owner);
1349 this.sourcefile = null;
1350 this.classfile = null;
1351 this.annotationTypeMetadata = AnnotationTypeMetadata.notAnAnnotationType();
1352 this.permitted = List.nil();
1353 }
1354
1355 public ClassSymbol(long flags, Name name, Symbol owner) {
1356 this(
1357 flags,
1358 name,
1359 new ClassType(Type.noType, null, null, List.nil(), Flavor.X_Typeof_X),
1360 owner);
1361 this.type.tsym = this;
1362 }
1363
1364 /** The Java source which this symbol represents.
1365 */
1366 public String toString() {
1367 return className();
1368 }
1369
1370 public long flags() {
1371 complete();
1372 return flags_field;
1373 }
1374
1375 public WriteableScope members() {
1376 complete();
1377 return members_field;
1378 }
1379
1380 @Override
1381 public List<Attribute.Compound> getRawAttributes() {
1382 complete();
1383 return super.getRawAttributes();
1384 }
1385
1386 @Override
1387 public List<Attribute.TypeCompound> getRawTypeAttributes() {
1388 complete();
1389 return super.getRawTypeAttributes();
1390 }
1391
1392 public Type erasure(Types types) {
1393 if (erasure_field == null)
1394 erasure_field = new ClassType(types.erasure(type.getEnclosingType()),
1395 List.nil(), this,
1396 type.getMetadata(),
1397 type.getFlavor());
1398 return erasure_field;
1399 }
1400
1401 public String className() {
1402 if (name.isEmpty())
1403 return
1404 Log.getLocalizedString("anonymous.class", flatname);
1405 else
1406 return fullname.toString();
1407 }
1408
1409 @Override @DefinedBy(Api.LANGUAGE_MODEL)
1410 public Name getQualifiedName() {
1411 return isUnnamed() ? fullname.subName(0, 0) /* empty name */ : fullname;
1412 }
1413
1414 @Override @DefinedBy(Api.LANGUAGE_MODEL)
1415 public Name getSimpleName() {
1416 return name;
1417 }
1443 if (is.head.tsym.isSubClass(base, types)) return true;
1444 } else {
1445 for (Type t = type; t.hasTag(CLASS); t = types.supertype(t))
1446 if (t.tsym == base) return true;
1447 }
1448 return false;
1449 }
1450
1451 /** Complete the elaboration of this symbol's definition.
1452 */
1453 public void complete() throws CompletionFailure {
1454 Completer origCompleter = completer;
1455 try {
1456 super.complete();
1457 } catch (CompletionFailure ex) {
1458 ex.dcfh.classSymbolCompleteFailed(this, origCompleter);
1459 // quiet error recovery
1460 flags_field |= (PUBLIC|STATIC);
1461 this.type = new ErrorType(this, Type.noType);
1462 throw ex;
1463 } finally {
1464 if (this.type != null && this.type.hasTag(CLASS)) {
1465 ClassType ct = (ClassType) this.type;
1466 ct.flavor = ct.flavor.metamorphose((this.flags_field & PRIMITIVE_CLASS) != 0);
1467 if (!this.type.isIntersection() && this.erasure_field != null && this.erasure_field.hasTag(CLASS)) {
1468 ((ClassType) this.erasure_field).flavor = ct.flavor;
1469 }
1470 }
1471 }
1472 }
1473
1474 @DefinedBy(Api.LANGUAGE_MODEL)
1475 public List<Type> getInterfaces() {
1476 apiComplete();
1477 if (type instanceof ClassType classType) {
1478 if (classType.interfaces_field == null) // FIXME: shouldn't be null
1479 classType.interfaces_field = List.nil();
1480 if (classType.all_interfaces_field != null)
1481 return Type.getModelTypes(classType.all_interfaces_field);
1482 return classType.interfaces_field;
1483 } else {
1484 return List.nil();
1485 }
1486 }
1487
1488 @DefinedBy(Api.LANGUAGE_MODEL)
1489 public Type getSuperclass() {
1490 apiComplete();
1638 if (types.firstUnimplementedAbstract(this) != null)
1639 // add the ABSTRACT flag to an enum
1640 flags_field |= ABSTRACT;
1641 }
1642 }
1643
1644 /**Resets the Symbol into the state good for next round of annotation processing.*/
1645 public void reset() {
1646 kind = TYP;
1647 erasure_field = null;
1648 members_field = null;
1649 flags_field = 0;
1650 if (type instanceof ClassType classType) {
1651 classType.setEnclosingType(Type.noType);
1652 classType.rank_field = -1;
1653 classType.typarams_field = null;
1654 classType.allparams_field = null;
1655 classType.supertype_field = null;
1656 classType.interfaces_field = null;
1657 classType.all_interfaces_field = null;
1658 classType.flavor = Flavor.X_Typeof_X;
1659 }
1660 clearAnnotationMetadata();
1661 }
1662
1663 public void clearAnnotationMetadata() {
1664 metadata = null;
1665 annotationTypeMetadata = AnnotationTypeMetadata.notAnAnnotationType();
1666 }
1667
1668 @Override
1669 public AnnotationTypeMetadata getAnnotationTypeMetadata() {
1670 return annotationTypeMetadata;
1671 }
1672
1673 @Override
1674 public boolean isAnnotationType() {
1675 return (flags_field & Flags.ANNOTATION) != 0;
1676 }
1677
1678 public void setAnnotationTypeMetadata(AnnotationTypeMetadata a) {
2002 public Object poolKey(Types types) {
2003 return new Pair<>(newOwner, baseSymbol());
2004 }
2005 };
2006 m.code = code;
2007 return m;
2008 }
2009
2010 @Override @DefinedBy(Api.LANGUAGE_MODEL)
2011 public Set<Modifier> getModifiers() {
2012 long flags = flags();
2013 return Flags.asModifierSet((flags & DEFAULT) != 0 ? flags & ~ABSTRACT : flags);
2014 }
2015
2016 /** The Java source which this symbol represents.
2017 */
2018 public String toString() {
2019 if ((flags() & BLOCK) != 0) {
2020 return owner.name.toString();
2021 } else {
2022 String s = isInitOrVNew()
2023 ? owner.name.toString()
2024 : name.toString();
2025 if (type != null) {
2026 if (type.hasTag(FORALL))
2027 s = "<" + ((ForAll)type).getTypeArguments() + ">" + s;
2028 s += "(" + type.argtypes((flags() & VARARGS) != 0) + ")";
2029 }
2030 return s;
2031 }
2032 }
2033
2034 @Override
2035 public int poolTag() {
2036 return owner.isInterface() ?
2037 ClassFile.CONSTANT_InterfaceMethodref : ClassFile.CONSTANT_Methodref;
2038 }
2039
2040 public boolean isHandle() {
2041 return false;
2042 }
2064 }
2065
2066 public Symbol implementedIn(TypeSymbol c, Types types) {
2067 Symbol impl = null;
2068 for (Symbol sym : c.members().getSymbolsByName(name)) {
2069 if (this.overrides(sym, (TypeSymbol)owner, types, true) &&
2070 // FIXME: I suspect the following requires a
2071 // subst() for a parametric return type.
2072 types.isSameType(type.getReturnType(),
2073 types.memberType(owner.type, sym).getReturnType())) {
2074 impl = sym;
2075 }
2076 }
2077 return impl;
2078 }
2079
2080 /** Will the erasure of this method be considered by the VM to
2081 * override the erasure of the other when seen from class `origin'?
2082 */
2083 public boolean binaryOverrides(Symbol _other, TypeSymbol origin, Types types) {
2084 if (isInitOrVNew() || _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.referenceProjectionOrSelf(), other.owner) != null &&
2092 types.isSameType(erasure(types), other.erasure(types)))
2093 return true;
2094
2095 // check for an inherited implementation
2096 return
2097 (flags() & ABSTRACT) == 0 &&
2098 other.isOverridableIn(origin) &&
2099 this.isMemberOf(origin, types) &&
2100 types.isSameType(erasure(types), other.erasure(types));
2101 }
2102
2103 /** The implementation of this (abstract) symbol in class origin,
2104 * from the VM's point of view, null if method does not have an
2105 * implementation in class.
2106 * @param origin The class of which the implementation is a member.
2107 */
2108 public MethodSymbol binaryImplementation(ClassSymbol origin, Types types) {
2109 for (TypeSymbol c = origin; c != null; c = types.supertype(c.type).tsym) {
2110 for (Symbol sym : c.members().getSymbolsByName(name)) {
2111 if (sym.kind == MTH &&
2133 */
2134 public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult) {
2135 return overrides(_other, origin, types, checkResult, true);
2136 }
2137
2138 /** Does this symbol override `other' symbol, when both are seen as
2139 * members of class `origin'? It is assumed that _other is a member
2140 * of origin.
2141 *
2142 * Caveat: If `this' is an abstract inherited member of origin, it is
2143 * deemed to override `other' only when `requireConcreteIfInherited'
2144 * is false.
2145 *
2146 * It is assumed that both symbols have the same name. The static
2147 * modifier is ignored for this test.
2148 *
2149 * See JLS 8.4.8.1 (without transitivity) and 8.4.8.4
2150 */
2151 public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult,
2152 boolean requireConcreteIfInherited) {
2153 if (isInitOrVNew() || _other.kind != MTH) return false;
2154
2155 if (this == _other) return true;
2156 MethodSymbol other = (MethodSymbol)_other;
2157
2158 // check for a direct implementation
2159 if (other.isOverridableIn((TypeSymbol)owner) &&
2160 types.asSuper(owner.type.referenceProjectionOrSelf(), other.owner) != null) {
2161 Type mt = types.memberType(owner.type, this);
2162 Type ot = types.memberType(owner.type, other);
2163 if (types.isSubSignature(mt, ot)) {
2164 if (!checkResult)
2165 return true;
2166 if (types.returnTypeSubstitutable(mt, ot))
2167 return true;
2168 }
2169 }
2170
2171 // check for an inherited implementation
2172 if (((flags() & ABSTRACT) != 0 && requireConcreteIfInherited) ||
2173 ((other.flags() & ABSTRACT) == 0 && (other.flags() & DEFAULT) == 0) ||
2174 !other.isOverridableIn(origin) ||
2175 !this.isMemberOf(origin, types))
2176 return false;
2177
2178 // assert types.asSuper(origin.type, other.owner) != null;
2179 Type mt = types.memberType(origin.type, this);
2180 Type ot = types.memberType(origin.type, other);
2257 ListBuffer<VarSymbol> newParams = new ListBuffer<>();
2258 int i = 0;
2259 for (Type t : type.getParameterTypes()) {
2260 Name paramName = name.table.fromString("arg" + i);
2261 VarSymbol param = new VarSymbol(PARAMETER, paramName, t, this);
2262 newParams.append(param);
2263 i++;
2264 }
2265 params = newParams.toList();
2266 }
2267 Assert.checkNonNull(params);
2268 return params;
2269 }
2270
2271 public Symbol asMemberOf(Type site, Types types) {
2272 return new MethodSymbol(flags_field, name, types.memberType(site, this), owner);
2273 }
2274
2275 @DefinedBy(Api.LANGUAGE_MODEL)
2276 public ElementKind getKind() {
2277 if (isInitOrVNew())
2278 return ElementKind.CONSTRUCTOR;
2279 else if (name == name.table.names.clinit)
2280 return ElementKind.STATIC_INIT;
2281 else if ((flags() & BLOCK) != 0)
2282 return isStatic() ? ElementKind.STATIC_INIT : ElementKind.INSTANCE_INIT;
2283 else
2284 return ElementKind.METHOD;
2285 }
2286
2287 public boolean isStaticOrInstanceInit() {
2288 return getKind() == ElementKind.STATIC_INIT ||
2289 getKind() == ElementKind.INSTANCE_INIT;
2290 }
2291
2292 @DefinedBy(Api.LANGUAGE_MODEL)
2293 public Attribute getDefaultValue() {
2294 return defaultValue;
2295 }
2296
2297 @DefinedBy(Api.LANGUAGE_MODEL)
2430
2431 public MethodHandleSymbol(Symbol msym) {
2432 this(msym, false);
2433 }
2434
2435 public MethodHandleSymbol(Symbol msym, boolean getter) {
2436 super(msym.flags_field, msym.name, msym.type, msym.owner);
2437 this.refSym = msym;
2438 this.getter = getter;
2439 }
2440
2441 /**
2442 * Returns the kind associated with this method handle.
2443 */
2444 public int referenceKind() {
2445 if (refSym.kind == VAR) {
2446 return getter ?
2447 refSym.isStatic() ? ClassFile.REF_getStatic : ClassFile.REF_getField :
2448 refSym.isStatic() ? ClassFile.REF_putStatic : ClassFile.REF_putField;
2449 } else {
2450 if (refSym.isInitOrVNew()) {
2451 return ClassFile.REF_newInvokeSpecial;
2452 } else {
2453 if (refSym.isStatic()) {
2454 return ClassFile.REF_invokeStatic;
2455 } else if ((refSym.flags() & PRIVATE) != 0 && !allowPrivateInvokeVirtual()) {
2456 return ClassFile.REF_invokeSpecial;
2457 } else if (refSym.enclClass().isInterface()) {
2458 return ClassFile.REF_invokeInterface;
2459 } else {
2460 return ClassFile.REF_invokeVirtual;
2461 }
2462 }
2463 }
2464 }
2465
2466 private boolean allowPrivateInvokeVirtual() {
2467 Symbol rootPack = this;
2468 while (rootPack != null && !(rootPack instanceof RootPackageSymbol)) {
2469 rootPack = rootPack.owner;
2470 }
|