< prev index next >

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

Print this page




1100     /**
1101      * Write NestMembers attribute (if needed)
1102      */
1103     int writeNestMembersIfNeeded(ClassSymbol csym) {
1104         ListBuffer<Symbol> nested = new ListBuffer<>();
1105         listNested(csym, nested);
1106         Set<Symbol> nestedUnique = new HashSet<>(nested);
1107         if (csym.owner.kind == PCK && !nestedUnique.isEmpty()) {
1108             int alenIdx = writeAttr(names.NestMembers);
1109             databuf.appendChar(nestedUnique.size());
1110             for (Symbol s : nestedUnique) {
1111                 databuf.appendChar(pool.put(s));
1112             }
1113             endAttr(alenIdx);
1114             return 1;
1115         }
1116         return 0;
1117     }
1118 
1119     /**
1120      * Write MemberOfNest attribute (if needed)
1121      */
1122     int writeMemberOfNestIfNeeded(ClassSymbol csym) {
1123         if (csym.owner.kind != PCK) {
1124             int alenIdx = writeAttr(names.MemberOfNest);
1125             databuf.appendChar(pool.put(csym.outermostClass()));
1126             endAttr(alenIdx);
1127             return 1;
1128         }
1129         return 0;
1130     }
1131 
1132     private void listNested(Symbol sym, ListBuffer<Symbol> seen) {
1133         if (sym.kind != TYP) return;
1134         ClassSymbol csym = (ClassSymbol)sym;
1135         if (csym.owner.kind != PCK) {
1136             seen.add(csym);
1137         }
1138         if (csym.members() != null) {
1139             for (Symbol s : sym.members().getSymbols()) {
1140                 listNested(s, seen);
1141             }
1142         }
1143         if (csym.trans_local != null) {
1144             for (Symbol s : csym.trans_local) {


1863         if (c.owner.kind == MDL) {
1864             acount += writeModuleAttribute(c);
1865             acount += writeFlagAttrs(c.owner.flags() & ~DEPRECATED);
1866         }
1867         acount += writeExtraClassAttributes(c);
1868 
1869         poolbuf.appendInt(JAVA_MAGIC);
1870 
1871         if (c.owner.kind == MDL) {
1872             // temporarily overide to force use of v53 for module-info.class
1873             poolbuf.appendChar(0);
1874             poolbuf.appendChar(53);
1875         } else {
1876             poolbuf.appendChar(target.minorVersion);
1877             poolbuf.appendChar(target.majorVersion);
1878 
1879             // TODO: Need to skip this for Modules - not sure where
1880             // that check really belongs, but this works.
1881             if (target.hasNestmateAccess()) {
1882                 acount += writeNestMembersIfNeeded(c);
1883                 acount += writeMemberOfNestIfNeeded(c);
1884             }
1885         }
1886 
1887         writePool(c.pool);
1888 
1889         if (innerClasses != null) {
1890             writeInnerClasses();
1891             acount++;
1892         }
1893 
1894         if (!bootstrapMethods.isEmpty()) {
1895             writeBootstrapMethods();
1896             acount++;
1897         }
1898 
1899         endAttrs(acountIdx, acount);
1900 
1901         poolbuf.appendBytes(databuf.elems, 0, databuf.length);
1902         out.write(poolbuf.elems, 0, poolbuf.length);
1903 




1100     /**
1101      * Write NestMembers attribute (if needed)
1102      */
1103     int writeNestMembersIfNeeded(ClassSymbol csym) {
1104         ListBuffer<Symbol> nested = new ListBuffer<>();
1105         listNested(csym, nested);
1106         Set<Symbol> nestedUnique = new HashSet<>(nested);
1107         if (csym.owner.kind == PCK && !nestedUnique.isEmpty()) {
1108             int alenIdx = writeAttr(names.NestMembers);
1109             databuf.appendChar(nestedUnique.size());
1110             for (Symbol s : nestedUnique) {
1111                 databuf.appendChar(pool.put(s));
1112             }
1113             endAttr(alenIdx);
1114             return 1;
1115         }
1116         return 0;
1117     }
1118 
1119     /**
1120      * Write NestHost attribute (if needed)
1121      */
1122     int writeNestHostIfNeeded(ClassSymbol csym) {
1123         if (csym.owner.kind != PCK) {
1124             int alenIdx = writeAttr(names.NestHost);
1125             databuf.appendChar(pool.put(csym.outermostClass()));
1126             endAttr(alenIdx);
1127             return 1;
1128         }
1129         return 0;
1130     }
1131 
1132     private void listNested(Symbol sym, ListBuffer<Symbol> seen) {
1133         if (sym.kind != TYP) return;
1134         ClassSymbol csym = (ClassSymbol)sym;
1135         if (csym.owner.kind != PCK) {
1136             seen.add(csym);
1137         }
1138         if (csym.members() != null) {
1139             for (Symbol s : sym.members().getSymbols()) {
1140                 listNested(s, seen);
1141             }
1142         }
1143         if (csym.trans_local != null) {
1144             for (Symbol s : csym.trans_local) {


1863         if (c.owner.kind == MDL) {
1864             acount += writeModuleAttribute(c);
1865             acount += writeFlagAttrs(c.owner.flags() & ~DEPRECATED);
1866         }
1867         acount += writeExtraClassAttributes(c);
1868 
1869         poolbuf.appendInt(JAVA_MAGIC);
1870 
1871         if (c.owner.kind == MDL) {
1872             // temporarily overide to force use of v53 for module-info.class
1873             poolbuf.appendChar(0);
1874             poolbuf.appendChar(53);
1875         } else {
1876             poolbuf.appendChar(target.minorVersion);
1877             poolbuf.appendChar(target.majorVersion);
1878 
1879             // TODO: Need to skip this for Modules - not sure where
1880             // that check really belongs, but this works.
1881             if (target.hasNestmateAccess()) {
1882                 acount += writeNestMembersIfNeeded(c);
1883                 acount += writeNestHostIfNeeded(c);
1884             }
1885         }
1886 
1887         writePool(c.pool);
1888 
1889         if (innerClasses != null) {
1890             writeInnerClasses();
1891             acount++;
1892         }
1893 
1894         if (!bootstrapMethods.isEmpty()) {
1895             writeBootstrapMethods();
1896             acount++;
1897         }
1898 
1899         endAttrs(acountIdx, acount);
1900 
1901         poolbuf.appendBytes(databuf.elems, 0, databuf.length);
1902         out.write(poolbuf.elems, 0, poolbuf.length);
1903 


< prev index next >