src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java
changeset 50735 2f2af62dfac7
parent 50213 3085969bdf91
child 54568 b2ed96c35687
equal deleted inserted replaced
50734:0828a0f6676b 50735:2f2af62dfac7
    29 import java.util.LinkedHashMap;
    29 import java.util.LinkedHashMap;
    30 import java.util.Map;
    30 import java.util.Map;
    31 import java.util.Set;
    31 import java.util.Set;
    32 import java.util.HashSet;
    32 import java.util.HashSet;
    33 import java.util.LinkedHashSet;
    33 import java.util.LinkedHashSet;
       
    34 import java.util.stream.Collectors;
    34 
    35 
    35 import javax.tools.JavaFileManager;
    36 import javax.tools.JavaFileManager;
    36 import javax.tools.FileObject;
    37 import javax.tools.FileObject;
    37 import javax.tools.JavaFileManager.Location;
    38 import javax.tools.JavaFileManager.Location;
    38 import javax.tools.JavaFileObject;
    39 import javax.tools.JavaFileObject;
  1104             databuf.appendChar(flags);
  1105             databuf.appendChar(flags);
  1105         }
  1106         }
  1106         endAttr(alenIdx);
  1107         endAttr(alenIdx);
  1107     }
  1108     }
  1108 
  1109 
       
  1110     /**
       
  1111      * Write NestMembers attribute (if needed)
       
  1112      */
       
  1113     int writeNestMembersIfNeeded(ClassSymbol csym) {
       
  1114         ListBuffer<Symbol> nested = new ListBuffer<>();
       
  1115         listNested(csym, nested);
       
  1116         Set<Symbol> nestedUnique = new LinkedHashSet<>(nested);
       
  1117         if (csym.owner.kind == PCK && !nestedUnique.isEmpty()) {
       
  1118             int alenIdx = writeAttr(names.NestMembers);
       
  1119             databuf.appendChar(nestedUnique.size());
       
  1120             for (Symbol s : nestedUnique) {
       
  1121                 databuf.appendChar(pool.put(s));
       
  1122             }
       
  1123             endAttr(alenIdx);
       
  1124             return 1;
       
  1125         }
       
  1126         return 0;
       
  1127     }
       
  1128 
       
  1129     /**
       
  1130      * Write NestHost attribute (if needed)
       
  1131      */
       
  1132     int writeNestHostIfNeeded(ClassSymbol csym) {
       
  1133         if (csym.owner.kind != PCK) {
       
  1134             int alenIdx = writeAttr(names.NestHost);
       
  1135             databuf.appendChar(pool.put(csym.outermostClass()));
       
  1136             endAttr(alenIdx);
       
  1137             return 1;
       
  1138         }
       
  1139         return 0;
       
  1140     }
       
  1141 
       
  1142     private void listNested(Symbol sym, ListBuffer<Symbol> seen) {
       
  1143         if (sym.kind != TYP) return;
       
  1144         ClassSymbol csym = (ClassSymbol)sym;
       
  1145         if (csym.owner.kind != PCK) {
       
  1146             seen.add(csym);
       
  1147         }
       
  1148         if (csym.members() != null) {
       
  1149             for (Symbol s : sym.members().getSymbols()) {
       
  1150                 listNested(s, seen);
       
  1151             }
       
  1152         }
       
  1153         if (csym.trans_local != null) {
       
  1154             for (Symbol s : csym.trans_local) {
       
  1155                 listNested(s, seen);
       
  1156             }
       
  1157         }
       
  1158     }
       
  1159 
  1109     /** Write "bootstrapMethods" attribute.
  1160     /** Write "bootstrapMethods" attribute.
  1110      */
  1161      */
  1111     void writeBootstrapMethods() {
  1162     void writeBootstrapMethods() {
  1112         int alenIdx = writeAttr(names.BootstrapMethods);
  1163         int alenIdx = writeAttr(names.BootstrapMethods);
  1113         databuf.appendChar(bootstrapMethods.size());
  1164         databuf.appendChar(bootstrapMethods.size());
  1833         } else {
  1884         } else {
  1834             poolbuf.appendChar(target.minorVersion);
  1885             poolbuf.appendChar(target.minorVersion);
  1835         }
  1886         }
  1836         poolbuf.appendChar(target.majorVersion);
  1887         poolbuf.appendChar(target.majorVersion);
  1837 
  1888 
       
  1889         if (c.owner.kind != MDL) {
       
  1890             if (target.hasNestmateAccess()) {
       
  1891                 acount += writeNestMembersIfNeeded(c);
       
  1892                 acount += writeNestHostIfNeeded(c);
       
  1893             }
       
  1894         }
       
  1895 
  1838         writePool(c.pool);
  1896         writePool(c.pool);
  1839 
  1897 
  1840         if (innerClasses != null) {
  1898         if (innerClasses != null) {
  1841             writeInnerClasses();
  1899             writeInnerClasses();
  1842             acount++;
  1900             acount++;