< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java

Print this page

        

*** 103,112 **** --- 103,120 ---- /** Switch: allow modules. */ boolean allowModules; + /** Switch: allow sealed + */ + boolean allowSealedTypes; + + /** Switch: allow records + */ + boolean allowRecords; + /** Lint option: warn about classfile issues */ boolean lintClassfile; /** Switch: preserve parameter names from the variable table.
*** 262,271 **** --- 270,281 ---- verbose = options.isSet(Option.VERBOSE); Source source = Source.instance(context); preview = Preview.instance(context); allowModules = Feature.MODULES.allowedInSource(source); + allowSealedTypes = Feature.SEALED.allowedInSource(source); + allowRecords = Feature.RECORDS.allowedInSource(source); saveParameterNames = options.isSet(PARAMETERS); profile = Profile.instance(context);
*** 1179,1188 **** --- 1189,1230 ---- ModuleSymbol msym = (ModuleSymbol) sym.owner; msym.resolutionFlags.addAll(readModuleResolutionFlags(nextChar())); } } }, + + new AttributeReader(names.PermittedSubtypes, V57, CLASS_ATTRIBUTE) { + @Override + protected boolean accepts(AttributeKind kind) { + return super.accepts(kind) && allowSealedTypes; + } + protected void read(Symbol sym, int attrLen) { + if (sym.kind == TYP) { + ClassType sealed = (ClassType)sym.type; + ListBuffer<Type> subtypes = new ListBuffer<>(); + int numberOfPermittedSubtypes = nextChar(); + for (int i = 0; i < numberOfPermittedSubtypes; i++) { + Type ct = poolReader.getClass(nextChar()).erasure(types); + subtypes.add(ct); + } + sealed.permitted = subtypes.toList(); + } + } + }, + + new AttributeReader(names.Record, V57, CLASS_ATTRIBUTE) { + @Override + protected boolean accepts(AttributeKind kind) { + return super.accepts(kind) && allowRecords; + } + protected void read(Symbol sym, int attrLen) { + if (sym.kind == TYP) { + sym.flags_field |= RECORD; + } + bp = bp + attrLen; + } + } }; for (AttributeReader r: readers) attributeReaders.put(r.name, r); }
*** 2439,2448 **** --- 2481,2495 ---- for (int i = 0; i < fieldCount; i++) skipMember(); char methodCount = nextChar(); for (int i = 0; i < methodCount; i++) skipMember(); readClassAttrs(c); + if (ct.permitted != null && !ct.permitted.isEmpty()) { + c.flags_field |= SEALED; + c.flags_field &= ~FINAL; + } + // reset and read rest of classinfo bp = startbp; int n = nextChar(); if ((flags & MODULE) != 0 && n > 0) { throw badClassFile("module.info.invalid.super.class");
< prev index next >