changeset 2958:92a298b8a0d7

small cleanup to ClassReader code
author jjg
date Tue, 31 Mar 2015 16:48:55 -0700
parents 171268c46d77
children 1421777eadbd
files src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties
diffstat 2 files changed, 25 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Tue Mar 31 13:15:40 2015 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Tue Mar 31 16:48:55 2015 -0700
@@ -522,6 +522,23 @@
         return (NameAndType)obj;
     }
 
+    /** Read the class name of a module-info.class file.
+     * The name is stored in a CONSTANT_Class entry, where the
+     * class name is of the form module-name.module-info.
+     */
+    Name readModuleInfoName(int i) {
+        int classIndex = poolIdx[i];
+        if (buf[classIndex] == CONSTANT_Class) {
+            int utf8Index = poolIdx[getChar(classIndex + 1)];
+            if (buf[utf8Index] == CONSTANT_Utf8) {
+                int len = getChar(utf8Index + 1);
+                int start = utf8Index + 3;
+                return names.fromUtf(internalize(buf, start, len));
+            }
+        }
+        throw badClassFile("bad.module-info.name");
+    }
+
     /** Read requires_flags.
      */
     Set<RequiresFlag> readRequiresFlags(int flags) {
@@ -2293,22 +2310,11 @@
             currentModule = c.packge().modle;
         } else {
             c.flags_field = flags;
-            // TODO: validate name
-            int i = nextChar();
-            // TODO: refactor some of this to a new method readModuleName
-            int classIndex = poolIdx[i];
-            if (buf[classIndex] == CONSTANT_Class) {
-                int utf8Index = poolIdx[getChar(classIndex + 1)];
-                if (buf[utf8Index] == CONSTANT_Utf8) {
-                    int len = getChar(utf8Index + 1);
-                    int start = utf8Index + 3;
-                    Name modInfoName = names.fromUtf(internalize(buf, start, len));
-                    if (c.owner.name == null) {
-                        syms.enterModule((ModuleSymbol) c.owner, Convert.packagePart(modInfoName));
-                    } else {
-                        // TODO: validate name
-                    }
-                }
+            Name modInfoName = readModuleInfoName(nextChar());
+            if (c.owner.name == null) {
+                syms.enterModule((ModuleSymbol) c.owner, Convert.packagePart(modInfoName));
+            } else {
+                // TODO: validate name
             }
             currentModule = (ModuleSymbol) c.owner;
         }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Tue Mar 31 13:15:40 2015 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Tue Mar 31 16:48:55 2015 -0700
@@ -1816,6 +1816,9 @@
 compiler.misc.bad.type.annotation.value=\
     bad type annotation target type value: {0}
 
+compiler.misc.bad.module-info.name=\
+    bad class name
+
 compiler.misc.class.file.wrong.class=\
     class file contains wrong class: {0}