< prev index next >

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

Print this page




1439             Type sup = getSuperclass();
1440 
1441             if (!sup.hasTag(CLASS) || sup.isErroneous())
1442                 return null;
1443 
1444             return (ClassSymbol) sup.tsym;
1445         }
1446 
1447 
1448         @Override
1449         protected <A extends Annotation> A[] getInheritedAnnotations(Class<A> annoType) {
1450 
1451             ClassSymbol sup = getSuperClassToSearchForAnnotations();
1452 
1453             return sup == null ? super.getInheritedAnnotations(annoType)
1454                                : sup.getAnnotationsByType(annoType);
1455         }
1456 
1457 
1458         @DefinedBy(Api.LANGUAGE_MODEL)
1459         @SuppressWarnings("removal")
1460         public ElementKind getKind() {
1461             apiComplete();
1462             long flags = flags();
1463             if ((flags & ANNOTATION) != 0)
1464                 return ElementKind.ANNOTATION_TYPE;
1465             else if ((flags & INTERFACE) != 0)
1466                 return ElementKind.INTERFACE;
1467             else if ((flags & ENUM) != 0)
1468                 return ElementKind.ENUM;
1469             else if ((flags & RECORD) != 0)
1470                 return ElementKind.RECORD;
1471             else
1472                 return ElementKind.CLASS;
1473         }
1474 
1475         @Override @DefinedBy(Api.LANGUAGE_MODEL)
1476         public Set<Modifier> getModifiers() {
1477             apiComplete();
1478             long flags = flags();
1479             return Flags.asModifierSet(flags & ~DEFAULT);
1480         }
1481 
1482         public RecordComponent getRecordComponent(VarSymbol field, boolean addIfMissing) {
1483             for (RecordComponent rc : recordComponents) {
1484                 if (rc.name == field.name) {
1485                     return rc;
1486                 }
1487             }
1488             RecordComponent rc = null;
1489             if (addIfMissing) {
1490                 recordComponents = recordComponents.append(rc = new RecordComponent(PUBLIC, field.name, field.type, field.owner));
1491             }
1492             return rc;
1493         }
1494 
1495         @Override @DefinedBy(Api.LANGUAGE_MODEL)
1496         @SuppressWarnings("removal")
1497         public List<? extends RecordComponent> getRecordComponents() {
1498             return recordComponents;
1499         }
1500 
1501         @DefinedBy(Api.LANGUAGE_MODEL)
1502         public NestingKind getNestingKind() {
1503             apiComplete();
1504             if (owner.kind == PCK)
1505                 return NestingKind.TOP_LEVEL;
1506             else if (name.isEmpty())
1507                 return NestingKind.ANONYMOUS;
1508             else if (owner.kind == MTH)
1509                 return NestingKind.LOCAL;
1510             else
1511                 return NestingKind.MEMBER;
1512         }
1513 
1514         @Override
1515         protected <A extends Annotation> Attribute.Compound getAttribute(final Class<A> annoType) {
1516 


1716                 data = null; // to make sure we don't evaluate this twice.
1717                 try {
1718                     data = eval.call();
1719                 } catch (Exception ex) {
1720                     throw new AssertionError(ex);
1721                 }
1722             }
1723             return data;
1724         }
1725 
1726         public void setData(Object data) {
1727             Assert.check(!(data instanceof Env<?>), this);
1728             this.data = data;
1729         }
1730 
1731         public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
1732             return v.visitVarSymbol(this, p);
1733         }
1734     }
1735 
1736     @SuppressWarnings("removal")
1737     public static class RecordComponent extends VarSymbol implements RecordComponentElement {
1738 
1739         /**
1740          * Construct a record component, given its flags, name, type and owner.
1741          */
1742         public RecordComponent(long flags, Name name, Type type, Symbol owner) {
1743             super(flags, name, type, owner);
1744         }
1745 
1746         @Override @DefinedBy(Api.LANGUAGE_MODEL)
1747         @SuppressWarnings("removal")
1748         public ElementKind getKind() {
1749             return ElementKind.RECORD_COMPONENT;
1750         }
1751 
1752         @Override @DefinedBy(Api.LANGUAGE_MODEL)
1753         public ExecutableElement getAccessor() {
1754             return accessor;
1755         }
1756 
1757         @Override @DefinedBy(Api.LANGUAGE_MODEL)
1758         @SuppressWarnings("removal")
1759         public <R, P> R accept(ElementVisitor<R, P> v, P p) {
1760             return v.visitRecordComponent(this, p);
1761         }
1762     }
1763 
1764     public static class ParamSymbol extends VarSymbol {
1765         public ParamSymbol(long flags, Name name, Type type, Symbol owner) {
1766             super(flags, name, type, owner);
1767         }
1768 
1769         @Override
1770         public Name getSimpleName() {
1771             if ((flags_field & NAME_FILLED) == 0) {
1772                 flags_field |= NAME_FILLED;
1773                 Symbol rootPack = this;
1774                 while (rootPack != null && !(rootPack instanceof RootPackageSymbol)) {
1775                     rootPack = rootPack.owner;
1776                 }
1777                 if (rootPack != null) {
1778                     Name inferredName =




1439             Type sup = getSuperclass();
1440 
1441             if (!sup.hasTag(CLASS) || sup.isErroneous())
1442                 return null;
1443 
1444             return (ClassSymbol) sup.tsym;
1445         }
1446 
1447 
1448         @Override
1449         protected <A extends Annotation> A[] getInheritedAnnotations(Class<A> annoType) {
1450 
1451             ClassSymbol sup = getSuperClassToSearchForAnnotations();
1452 
1453             return sup == null ? super.getInheritedAnnotations(annoType)
1454                                : sup.getAnnotationsByType(annoType);
1455         }
1456 
1457 
1458         @DefinedBy(Api.LANGUAGE_MODEL)
1459         @SuppressWarnings("preview")
1460         public ElementKind getKind() {
1461             apiComplete();
1462             long flags = flags();
1463             if ((flags & ANNOTATION) != 0)
1464                 return ElementKind.ANNOTATION_TYPE;
1465             else if ((flags & INTERFACE) != 0)
1466                 return ElementKind.INTERFACE;
1467             else if ((flags & ENUM) != 0)
1468                 return ElementKind.ENUM;
1469             else if ((flags & RECORD) != 0)
1470                 return ElementKind.RECORD;
1471             else
1472                 return ElementKind.CLASS;
1473         }
1474 
1475         @Override @DefinedBy(Api.LANGUAGE_MODEL)
1476         public Set<Modifier> getModifiers() {
1477             apiComplete();
1478             long flags = flags();
1479             return Flags.asModifierSet(flags & ~DEFAULT);
1480         }
1481 
1482         public RecordComponent getRecordComponent(VarSymbol field, boolean addIfMissing) {
1483             for (RecordComponent rc : recordComponents) {
1484                 if (rc.name == field.name) {
1485                     return rc;
1486                 }
1487             }
1488             RecordComponent rc = null;
1489             if (addIfMissing) {
1490                 recordComponents = recordComponents.append(rc = new RecordComponent(PUBLIC, field.name, field.type, field.owner));
1491             }
1492             return rc;
1493         }
1494 
1495         @Override @DefinedBy(Api.LANGUAGE_MODEL)
1496         @SuppressWarnings("preview")
1497         public List<? extends RecordComponent> getRecordComponents() {
1498             return recordComponents;
1499         }
1500 
1501         @DefinedBy(Api.LANGUAGE_MODEL)
1502         public NestingKind getNestingKind() {
1503             apiComplete();
1504             if (owner.kind == PCK)
1505                 return NestingKind.TOP_LEVEL;
1506             else if (name.isEmpty())
1507                 return NestingKind.ANONYMOUS;
1508             else if (owner.kind == MTH)
1509                 return NestingKind.LOCAL;
1510             else
1511                 return NestingKind.MEMBER;
1512         }
1513 
1514         @Override
1515         protected <A extends Annotation> Attribute.Compound getAttribute(final Class<A> annoType) {
1516 


1716                 data = null; // to make sure we don't evaluate this twice.
1717                 try {
1718                     data = eval.call();
1719                 } catch (Exception ex) {
1720                     throw new AssertionError(ex);
1721                 }
1722             }
1723             return data;
1724         }
1725 
1726         public void setData(Object data) {
1727             Assert.check(!(data instanceof Env<?>), this);
1728             this.data = data;
1729         }
1730 
1731         public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
1732             return v.visitVarSymbol(this, p);
1733         }
1734     }
1735 
1736     @SuppressWarnings("preview")
1737     public static class RecordComponent extends VarSymbol implements RecordComponentElement {
1738 
1739         /**
1740          * Construct a record component, given its flags, name, type and owner.
1741          */
1742         public RecordComponent(long flags, Name name, Type type, Symbol owner) {
1743             super(flags, name, type, owner);
1744         }
1745 
1746         @Override @DefinedBy(Api.LANGUAGE_MODEL)
1747         @SuppressWarnings("preview")
1748         public ElementKind getKind() {
1749             return ElementKind.RECORD_COMPONENT;
1750         }
1751 
1752         @Override @DefinedBy(Api.LANGUAGE_MODEL)
1753         public ExecutableElement getAccessor() {
1754             return accessor;
1755         }
1756 
1757         @Override @DefinedBy(Api.LANGUAGE_MODEL)
1758         @SuppressWarnings("preview")
1759         public <R, P> R accept(ElementVisitor<R, P> v, P p) {
1760             return v.visitRecordComponent(this, p);
1761         }
1762     }
1763 
1764     public static class ParamSymbol extends VarSymbol {
1765         public ParamSymbol(long flags, Name name, Type type, Symbol owner) {
1766             super(flags, name, type, owner);
1767         }
1768 
1769         @Override
1770         public Name getSimpleName() {
1771             if ((flags_field & NAME_FILLED) == 0) {
1772                 flags_field |= NAME_FILLED;
1773                 Symbol rootPack = this;
1774                 while (rootPack != null && !(rootPack instanceof RootPackageSymbol)) {
1775                     rootPack = rootPack.owner;
1776                 }
1777                 if (rootPack != null) {
1778                     Name inferredName =


< prev index next >