langtools/src/jdk.jdeps/share/classes/com/sun/tools/javap/ClassWriter.java
changeset 42822 a84956e7ee4d
parent 42407 f3702cff2933
equal deleted inserted replaced
42812:084017ef9300 42822:a84956e7ee4d
    56 import com.sun.tools.classfile.Type.SimpleType;
    56 import com.sun.tools.classfile.Type.SimpleType;
    57 import com.sun.tools.classfile.Type.TypeParamType;
    57 import com.sun.tools.classfile.Type.TypeParamType;
    58 import com.sun.tools.classfile.Type.WildcardType;
    58 import com.sun.tools.classfile.Type.WildcardType;
    59 
    59 
    60 import static com.sun.tools.classfile.AccessFlags.*;
    60 import static com.sun.tools.classfile.AccessFlags.*;
       
    61 import static com.sun.tools.classfile.ConstantPool.CONSTANT_Module;
       
    62 import static com.sun.tools.classfile.ConstantPool.CONSTANT_Package;
    61 
    63 
    62 /*
    64 /*
    63  *  The main javap class to write the contents of a class file as text.
    65  *  The main javap class to write the contents of a class file as text.
    64  *
    66  *
    65  *  <p><b>This is NOT part of any supported API.
    67  *  <p><b>This is NOT part of any supported API.
   164             Attribute attr = classFile.attributes.get(Attribute.Module);
   166             Attribute attr = classFile.attributes.get(Attribute.Module);
   165             if (attr instanceof Module_attribute) {
   167             if (attr instanceof Module_attribute) {
   166                 Module_attribute modAttr = (Module_attribute) attr;
   168                 Module_attribute modAttr = (Module_attribute) attr;
   167                 String name;
   169                 String name;
   168                 try {
   170                 try {
   169                     name = getJavaName(constant_pool.getUTF8Value(modAttr.module_name));
   171                     // FIXME: compatibility code
       
   172                     if (constant_pool.get(modAttr.module_name).getTag() == CONSTANT_Module) {
       
   173                         name = getJavaName(constant_pool.getModuleInfo(modAttr.module_name).getName());
       
   174                     } else {
       
   175                         name = getJavaName(constant_pool.getUTF8Value(modAttr.module_name));
       
   176                     }
   170                 } catch (ConstantPoolException e) {
   177                 } catch (ConstantPoolException e) {
   171                     name = report(e);
   178                     name = report(e);
   172                 }
   179                 }
   173                 if ((modAttr.module_flags & Module_attribute.ACC_OPEN) != 0) {
   180                 if ((modAttr.module_flags & Module_attribute.ACC_OPEN) != 0) {
   174                     print("open ");
   181                     print("open ");
   175                 }
   182                 }
   176                 print("module ");
   183                 print("module ");
   177                 print(name);
   184                 print(name);
       
   185                 if (modAttr.module_version_index != 0) {
       
   186                     print("@");
       
   187                     print(getUTF8Value(modAttr.module_version_index));
       
   188                 }
   178             } else {
   189             } else {
   179                 // fallback for malformed class files
   190                 // fallback for malformed class files
   180                 print("class ");
   191                 print("class ");
   181                 print(getJavaName(classFile));
   192                 print(getJavaName(classFile));
   182             }
   193             }
   600             if ((entry.requires_flags & Module_attribute.ACC_STATIC_PHASE) != 0)
   611             if ((entry.requires_flags & Module_attribute.ACC_STATIC_PHASE) != 0)
   601                 print(" static");
   612                 print(" static");
   602             if ((entry.requires_flags & Module_attribute.ACC_TRANSITIVE) != 0)
   613             if ((entry.requires_flags & Module_attribute.ACC_TRANSITIVE) != 0)
   603                 print(" transitive");
   614                 print(" transitive");
   604             print(" ");
   615             print(" ");
   605             print(getUTF8Value(entry.requires_index).replace('/', '.'));
   616             String mname;
       
   617             try {
       
   618                 mname = getModuleName(entry.requires_index);
       
   619             } catch (ConstantPoolException e) {
       
   620                 mname = report(e);
       
   621             }
       
   622             print(mname);
   606             println(";");
   623             println(";");
   607         }
   624         }
   608 
   625 
   609         for (Module_attribute.ExportsEntry entry: m.exports) {
   626         for (Module_attribute.ExportsEntry entry: m.exports) {
   610             print("exports");
   627             print("exports");
   611             print(" ");
   628             print(" ");
   612             print(getUTF8Value(entry.exports_index).replace('/', '.'));
   629             String pname;
       
   630             try {
       
   631                 pname = getPackageName(entry.exports_index).replace('/', '.');
       
   632             } catch (ConstantPoolException e) {
       
   633                 pname = report(e);
       
   634             }
       
   635             print(pname);
   613             boolean first = true;
   636             boolean first = true;
   614             for (int i: entry.exports_to_index) {
   637             for (int i: entry.exports_to_index) {
   615                 String mname;
   638                 String mname;
   616                 try {
   639                 try {
   617                     mname = classFile.constant_pool.getUTF8Value(i).replace('/', '.');
   640                     mname = getModuleName(i);
   618                 } catch (ConstantPoolException e) {
   641                 } catch (ConstantPoolException e) {
   619                     mname = report(e);
   642                     mname = report(e);
   620                 }
   643                 }
   621                 if (first) {
   644                 if (first) {
   622                     println(" to");
   645                     println(" to");
   633         }
   656         }
   634 
   657 
   635         for (Module_attribute.OpensEntry entry: m.opens) {
   658         for (Module_attribute.OpensEntry entry: m.opens) {
   636             print("opens");
   659             print("opens");
   637             print(" ");
   660             print(" ");
   638             print(getUTF8Value(entry.opens_index).replace('/', '.'));
   661             String pname;
       
   662             try {
       
   663                 pname = getPackageName(entry.opens_index).replace('/', '.');
       
   664             } catch (ConstantPoolException e) {
       
   665                 pname = report(e);
       
   666             }
       
   667             print(pname);
   639             boolean first = true;
   668             boolean first = true;
   640             for (int i: entry.opens_to_index) {
   669             for (int i: entry.opens_to_index) {
   641                 String mname;
   670                 String mname;
   642                 try {
   671                 try {
   643                     mname = classFile.constant_pool.getUTF8Value(i).replace('/', '.');
   672                     mname = getModuleName(i);
   644                 } catch (ConstantPoolException e) {
   673                 } catch (ConstantPoolException e) {
   645                     mname = report(e);
   674                     mname = report(e);
   646                 }
   675                 }
   647                 if (first) {
   676                 if (first) {
   648                     println(" to");
   677                     println(" to");
   679                 print(getClassName(i).replace('/', '.'));
   708                 print(getClassName(i).replace('/', '.'));
   680             }
   709             }
   681             println(";");
   710             println(";");
   682             if (!first)
   711             if (!first)
   683                 indent(-1);
   712                 indent(-1);
       
   713         }
       
   714     }
       
   715 
       
   716     String getModuleName(int index) throws ConstantPoolException {
       
   717         if (constant_pool.get(index).getTag() == CONSTANT_Module) {
       
   718             return constant_pool.getModuleInfo(index).getName();
       
   719         } else {
       
   720             return constant_pool.getUTF8Value(index);
       
   721         }
       
   722     }
       
   723 
       
   724     String getPackageName(int index) throws ConstantPoolException {
       
   725         if (constant_pool.get(index).getTag() == CONSTANT_Package) {
       
   726             return constant_pool.getPackageInfo(index).getName();
       
   727         } else {
       
   728             return constant_pool.getUTF8Value(index);
   684         }
   729         }
   685     }
   730     }
   686 
   731 
   687     String getUTF8Value(int index) {
   732     String getUTF8Value(int index) {
   688         try {
   733         try {