< prev index next >

src/jdk.jdeps/share/classes/com/sun/tools/javap/ClassWriter.java

Print this page

        

@@ -56,10 +56,12 @@
 import com.sun.tools.classfile.Type.SimpleType;
 import com.sun.tools.classfile.Type.TypeParamType;
 import com.sun.tools.classfile.Type.WildcardType;
 
 import static com.sun.tools.classfile.AccessFlags.*;
+import static com.sun.tools.classfile.ConstantPool.CONSTANT_Module;
+import static com.sun.tools.classfile.ConstantPool.CONSTANT_Package;
 
 /*
  *  The main javap class to write the contents of a class file as text.
  *
  *  <p><b>This is NOT part of any supported API.

@@ -164,19 +166,28 @@
             Attribute attr = classFile.attributes.get(Attribute.Module);
             if (attr instanceof Module_attribute) {
                 Module_attribute modAttr = (Module_attribute) attr;
                 String name;
                 try {
+                    // FIXME: compatibility code
+                    if (constant_pool.get(modAttr.module_name).getTag() == CONSTANT_Module) {
+                        name = getJavaName(constant_pool.getModuleInfo(modAttr.module_name).getName());
+                    } else {
                     name = getJavaName(constant_pool.getUTF8Value(modAttr.module_name));
+                    }
                 } catch (ConstantPoolException e) {
                     name = report(e);
                 }
                 if ((modAttr.module_flags & Module_attribute.ACC_OPEN) != 0) {
                     print("open ");
                 }
                 print("module ");
                 print(name);
+                if (modAttr.module_version_index != 0) {
+                    print("@");
+                    print(getUTF8Value(modAttr.module_version_index));
+                }
             } else {
                 // fallback for malformed class files
                 print("class ");
                 print(getJavaName(classFile));
             }

@@ -600,23 +611,35 @@
             if ((entry.requires_flags & Module_attribute.ACC_STATIC_PHASE) != 0)
                 print(" static");
             if ((entry.requires_flags & Module_attribute.ACC_TRANSITIVE) != 0)
                 print(" transitive");
             print(" ");
-            print(getUTF8Value(entry.requires_index).replace('/', '.'));
+            String mname;
+            try {
+                mname = getModuleName(entry.requires_index);
+            } catch (ConstantPoolException e) {
+                mname = report(e);
+            }
+            print(mname);
             println(";");
         }
 
         for (Module_attribute.ExportsEntry entry: m.exports) {
             print("exports");
             print(" ");
-            print(getUTF8Value(entry.exports_index).replace('/', '.'));
+            String pname;
+            try {
+                pname = getPackageName(entry.exports_index).replace('/', '.');
+            } catch (ConstantPoolException e) {
+                pname = report(e);
+            }
+            print(pname);
             boolean first = true;
             for (int i: entry.exports_to_index) {
                 String mname;
                 try {
-                    mname = classFile.constant_pool.getUTF8Value(i).replace('/', '.');
+                    mname = getModuleName(i);
                 } catch (ConstantPoolException e) {
                     mname = report(e);
                 }
                 if (first) {
                     println(" to");

@@ -633,16 +656,22 @@
         }
 
         for (Module_attribute.OpensEntry entry: m.opens) {
             print("opens");
             print(" ");
-            print(getUTF8Value(entry.opens_index).replace('/', '.'));
+            String pname;
+            try {
+                pname = getPackageName(entry.opens_index).replace('/', '.');
+            } catch (ConstantPoolException e) {
+                pname = report(e);
+            }
+            print(pname);
             boolean first = true;
             for (int i: entry.opens_to_index) {
                 String mname;
                 try {
-                    mname = classFile.constant_pool.getUTF8Value(i).replace('/', '.');
+                    mname = getModuleName(i);
                 } catch (ConstantPoolException e) {
                     mname = report(e);
                 }
                 if (first) {
                     println(" to");

@@ -682,10 +711,26 @@
             if (!first)
                 indent(-1);
         }
     }
 
+    String getModuleName(int index) throws ConstantPoolException {
+        if (constant_pool.get(index).getTag() == CONSTANT_Module) {
+            return constant_pool.getModuleInfo(index).getName();
+        } else {
+            return constant_pool.getUTF8Value(index);
+        }
+    }
+
+    String getPackageName(int index) throws ConstantPoolException {
+        if (constant_pool.get(index).getTag() == CONSTANT_Package) {
+            return constant_pool.getPackageInfo(index).getName();
+        } else {
+            return constant_pool.getUTF8Value(index);
+        }
+    }
+
     String getUTF8Value(int index) {
         try {
             return classFile.constant_pool.getUTF8Value(index);
         } catch (ConstantPoolException e) {
             return report(e);
< prev index next >