73 * This code and its internal interfaces are subject to change or |
73 * This code and its internal interfaces are subject to change or |
74 * deletion without notice.</b> |
74 * deletion without notice.</b> |
75 */ |
75 */ |
76 public class ClassReader { |
76 public class ClassReader { |
77 /** The context key for the class reader. */ |
77 /** The context key for the class reader. */ |
78 protected static final Context.Key<ClassReader> classReaderKey = |
78 protected static final Context.Key<ClassReader> classReaderKey = new Context.Key<>(); |
79 new Context.Key<ClassReader>(); |
|
80 |
79 |
81 public static final int INITIAL_BUFFER_SIZE = 0x0fff0; |
80 public static final int INITIAL_BUFFER_SIZE = 0x0fff0; |
82 |
81 |
83 Annotate annotate; |
82 Annotate annotate; |
84 |
83 |
231 boolean sawMethodParameters; |
230 boolean sawMethodParameters; |
232 |
231 |
233 /** |
232 /** |
234 * The set of attribute names for which warnings have been generated for the current class |
233 * The set of attribute names for which warnings have been generated for the current class |
235 */ |
234 */ |
236 Set<Name> warnedAttrs = new HashSet<Name>(); |
235 Set<Name> warnedAttrs = new HashSet<>(); |
237 |
236 |
238 /** |
237 /** |
239 * Completer that delegates to the complete-method of this class. |
238 * Completer that delegates to the complete-method of this class. |
240 */ |
239 */ |
241 private final Completer thisCompleter = new Completer() { |
240 private final Completer thisCompleter = new Completer() { |
269 Assert.check(packages == null || packages == syms.packages); |
268 Assert.check(packages == null || packages == syms.packages); |
270 packages = syms.packages; |
269 packages = syms.packages; |
271 Assert.check(classes == null || classes == syms.classes); |
270 Assert.check(classes == null || classes == syms.classes); |
272 classes = syms.classes; |
271 classes = syms.classes; |
273 } else { |
272 } else { |
274 packages = new HashMap<Name, PackageSymbol>(); |
273 packages = new HashMap<>(); |
275 classes = new HashMap<Name, ClassSymbol>(); |
274 classes = new HashMap<>(); |
276 } |
275 } |
277 |
276 |
278 packages.put(names.empty, syms.rootPackage); |
277 packages.put(names.empty, syms.rootPackage); |
279 syms.rootPackage.completer = thisCompleter; |
278 syms.rootPackage.completer = thisCompleter; |
280 syms.unnamedPackage.completer = thisCompleter; |
279 syms.unnamedPackage.completer = thisCompleter; |
935 |
934 |
936 /************************************************************************ |
935 /************************************************************************ |
937 * Reading Attributes |
936 * Reading Attributes |
938 ***********************************************************************/ |
937 ***********************************************************************/ |
939 |
938 |
940 protected enum AttributeKind { CLASS, MEMBER }; |
939 protected enum AttributeKind { CLASS, MEMBER } |
|
940 |
941 protected abstract class AttributeReader { |
941 protected abstract class AttributeReader { |
942 protected AttributeReader(Name name, ClassFile.Version version, Set<AttributeKind> kinds) { |
942 protected AttributeReader(Name name, ClassFile.Version version, Set<AttributeKind> kinds) { |
943 this.name = name; |
943 this.name = name; |
944 this.version = version; |
944 this.version = version; |
945 this.kinds = kinds; |
945 this.kinds = kinds; |
976 protected Set<AttributeKind> MEMBER_ATTRIBUTE = |
976 protected Set<AttributeKind> MEMBER_ATTRIBUTE = |
977 EnumSet.of(AttributeKind.MEMBER); |
977 EnumSet.of(AttributeKind.MEMBER); |
978 protected Set<AttributeKind> CLASS_OR_MEMBER_ATTRIBUTE = |
978 protected Set<AttributeKind> CLASS_OR_MEMBER_ATTRIBUTE = |
979 EnumSet.of(AttributeKind.CLASS, AttributeKind.MEMBER); |
979 EnumSet.of(AttributeKind.CLASS, AttributeKind.MEMBER); |
980 |
980 |
981 protected Map<Name, AttributeReader> attributeReaders = new HashMap<Name, AttributeReader>(); |
981 protected Map<Name, AttributeReader> attributeReaders = new HashMap<>(); |
982 |
982 |
983 private void initAttributeReaders() { |
983 private void initAttributeReaders() { |
984 AttributeReader[] readers = { |
984 AttributeReader[] readers = { |
985 // v45.3 attributes |
985 // v45.3 attributes |
986 |
986 |
1129 try { |
1129 try { |
1130 ClassType ct1 = (ClassType)c.type; |
1130 ClassType ct1 = (ClassType)c.type; |
1131 Assert.check(c == currentOwner); |
1131 Assert.check(c == currentOwner); |
1132 ct1.typarams_field = readTypeParams(nextChar()); |
1132 ct1.typarams_field = readTypeParams(nextChar()); |
1133 ct1.supertype_field = sigToType(); |
1133 ct1.supertype_field = sigToType(); |
1134 ListBuffer<Type> is = new ListBuffer<Type>(); |
1134 ListBuffer<Type> is = new ListBuffer<>(); |
1135 while (sigp != siglimit) is.append(sigToType()); |
1135 while (sigp != siglimit) is.append(sigToType()); |
1136 ct1.interfaces_field = is.toList(); |
1136 ct1.interfaces_field = is.toList(); |
1137 } finally { |
1137 } finally { |
1138 readingClassAttr = false; |
1138 readingClassAttr = false; |
1139 } |
1139 } |
1273 } else { |
1273 } else { |
1274 ((ClassType)sym.type).setEnclosingType(Type.noType); |
1274 ((ClassType)sym.type).setEnclosingType(Type.noType); |
1275 } |
1275 } |
1276 enterTypevars(self); |
1276 enterTypevars(self); |
1277 if (!missingTypeVariables.isEmpty()) { |
1277 if (!missingTypeVariables.isEmpty()) { |
1278 ListBuffer<Type> typeVars = new ListBuffer<Type>(); |
1278 ListBuffer<Type> typeVars = new ListBuffer<>(); |
1279 for (Type typevar : missingTypeVariables) { |
1279 for (Type typevar : missingTypeVariables) { |
1280 typeVars.append(findTypeVar(typevar.tsym.name)); |
1280 typeVars.append(findTypeVar(typevar.tsym.name)); |
1281 } |
1281 } |
1282 foundTypeVariables = typeVars.toList(); |
1282 foundTypeVariables = typeVars.toList(); |
1283 } else { |
1283 } else { |
1400 /** Attach annotations. |
1400 /** Attach annotations. |
1401 */ |
1401 */ |
1402 void attachAnnotations(final Symbol sym) { |
1402 void attachAnnotations(final Symbol sym) { |
1403 int numAttributes = nextChar(); |
1403 int numAttributes = nextChar(); |
1404 if (numAttributes != 0) { |
1404 if (numAttributes != 0) { |
1405 ListBuffer<CompoundAnnotationProxy> proxies = |
1405 ListBuffer<CompoundAnnotationProxy> proxies = new ListBuffer<>(); |
1406 new ListBuffer<CompoundAnnotationProxy>(); |
|
1407 for (int i = 0; i<numAttributes; i++) { |
1406 for (int i = 0; i<numAttributes; i++) { |
1408 CompoundAnnotationProxy proxy = readCompoundAnnotation(); |
1407 CompoundAnnotationProxy proxy = readCompoundAnnotation(); |
1409 if (proxy.type.tsym == syms.proprietaryType.tsym) |
1408 if (proxy.type.tsym == syms.proprietaryType.tsym) |
1410 sym.flags_field |= PROPRIETARY; |
1409 sym.flags_field |= PROPRIETARY; |
1411 else if (proxy.type.tsym == syms.profileType.tsym) { |
1410 else if (proxy.type.tsym == syms.profileType.tsym) { |
1487 } |
1486 } |
1488 |
1487 |
1489 CompoundAnnotationProxy readCompoundAnnotation() { |
1488 CompoundAnnotationProxy readCompoundAnnotation() { |
1490 Type t = readTypeOrClassSymbol(nextChar()); |
1489 Type t = readTypeOrClassSymbol(nextChar()); |
1491 int numFields = nextChar(); |
1490 int numFields = nextChar(); |
1492 ListBuffer<Pair<Name,Attribute>> pairs = |
1491 ListBuffer<Pair<Name,Attribute>> pairs = new ListBuffer<>(); |
1493 new ListBuffer<Pair<Name,Attribute>>(); |
|
1494 for (int i=0; i<numFields; i++) { |
1492 for (int i=0; i<numFields; i++) { |
1495 Name name = readName(nextChar()); |
1493 Name name = readName(nextChar()); |
1496 Attribute value = readAttributeValue(); |
1494 Attribute value = readAttributeValue(); |
1497 pairs.append(new Pair<Name,Attribute>(name, value)); |
1495 pairs.append(new Pair<>(name, value)); |
1498 } |
1496 } |
1499 return new CompoundAnnotationProxy(t, pairs.toList()); |
1497 return new CompoundAnnotationProxy(t, pairs.toList()); |
1500 } |
1498 } |
1501 |
1499 |
1502 TypeAnnotationProxy readTypeAnnotation() { |
1500 TypeAnnotationProxy readTypeAnnotation() { |
1629 return new EnumAttributeProxy(readEnumType(nextChar()), readName(nextChar())); |
1627 return new EnumAttributeProxy(readEnumType(nextChar()), readName(nextChar())); |
1630 case 'c': |
1628 case 'c': |
1631 return new Attribute.Class(types, readTypeOrClassSymbol(nextChar())); |
1629 return new Attribute.Class(types, readTypeOrClassSymbol(nextChar())); |
1632 case '[': { |
1630 case '[': { |
1633 int n = nextChar(); |
1631 int n = nextChar(); |
1634 ListBuffer<Attribute> l = new ListBuffer<Attribute>(); |
1632 ListBuffer<Attribute> l = new ListBuffer<>(); |
1635 for (int i=0; i<n; i++) |
1633 for (int i=0; i<n; i++) |
1636 l.append(readAttributeValue()); |
1634 l.append(readAttributeValue()); |
1637 return new ArrayAttributeProxy(l.toList()); |
1635 return new ArrayAttributeProxy(l.toList()); |
1638 } |
1636 } |
1639 case '@': |
1637 case '@': |
1724 private ClassSymbol requestingOwner = currentOwner.kind == MTH |
1722 private ClassSymbol requestingOwner = currentOwner.kind == MTH |
1725 ? currentOwner.enclClass() : (ClassSymbol)currentOwner; |
1723 ? currentOwner.enclClass() : (ClassSymbol)currentOwner; |
1726 |
1724 |
1727 List<Attribute.Compound> deproxyCompoundList(List<CompoundAnnotationProxy> pl) { |
1725 List<Attribute.Compound> deproxyCompoundList(List<CompoundAnnotationProxy> pl) { |
1728 // also must fill in types!!!! |
1726 // also must fill in types!!!! |
1729 ListBuffer<Attribute.Compound> buf = |
1727 ListBuffer<Attribute.Compound> buf = new ListBuffer<>(); |
1730 new ListBuffer<Attribute.Compound>(); |
|
1731 for (List<CompoundAnnotationProxy> l = pl; l.nonEmpty(); l=l.tail) { |
1728 for (List<CompoundAnnotationProxy> l = pl; l.nonEmpty(); l=l.tail) { |
1732 buf.append(deproxyCompound(l.head)); |
1729 buf.append(deproxyCompound(l.head)); |
1733 } |
1730 } |
1734 return buf.toList(); |
1731 return buf.toList(); |
1735 } |
1732 } |
1736 |
1733 |
1737 Attribute.Compound deproxyCompound(CompoundAnnotationProxy a) { |
1734 Attribute.Compound deproxyCompound(CompoundAnnotationProxy a) { |
1738 ListBuffer<Pair<Symbol.MethodSymbol,Attribute>> buf = |
1735 ListBuffer<Pair<Symbol.MethodSymbol,Attribute>> buf = new ListBuffer<>(); |
1739 new ListBuffer<Pair<Symbol.MethodSymbol,Attribute>>(); |
|
1740 for (List<Pair<Name,Attribute>> l = a.values; |
1736 for (List<Pair<Name,Attribute>> l = a.values; |
1741 l.nonEmpty(); |
1737 l.nonEmpty(); |
1742 l = l.tail) { |
1738 l = l.tail) { |
1743 MethodSymbol meth = findAccessMethod(a.type, l.head.fst); |
1739 MethodSymbol meth = findAccessMethod(a.type, l.head.fst); |
1744 buf.append(new Pair<Symbol.MethodSymbol,Attribute> |
1740 buf.append(new Pair<>(meth, deproxy(meth.type.getReturnType(), l.head.snd))); |
1745 (meth, deproxy(meth.type.getReturnType(), l.head.snd))); |
|
1746 } |
1741 } |
1747 return new Attribute.Compound(a.type, buf.toList()); |
1742 return new Attribute.Compound(a.type, buf.toList()); |
1748 } |
1743 } |
1749 |
1744 |
1750 MethodSymbol findAccessMethod(Type container, Name name) { |
1745 MethodSymbol findAccessMethod(Type container, Name name) { |