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