8034861: Incorrect format and indentation of InnerClasses section
authorjjg
Wed, 03 Sep 2014 14:06:25 -0700
changeset 26389 b389165f2c78
parent 26388 6048554767c0
child 26390 1d0902fe3ca0
8034861: Incorrect format and indentation of InnerClasses section Reviewed-by: jjg, ksrini, mcimadamore, lagergren
langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/AttributeWriter.java
langtools/test/tools/javap/T4975569.java
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/AttributeWriter.java	Wed Sep 03 19:22:16 2014 +0400
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/AttributeWriter.java	Wed Sep 03 14:06:25 2014 -0700
@@ -297,17 +297,18 @@
                     writeInnerClassHeader();
                     first = false;
                 }
-                print("   ");
                 for (String name: access_flags.getInnerClassModifiers())
                     print(name + " ");
-                if (info.inner_name_index!=0) {
+                if (info.inner_name_index != 0) {
                     print("#" + info.inner_name_index + "= ");
                 }
                 print("#" + info.inner_class_info_index);
                 if (info.outer_class_info_index != 0) {
                     print(" of #" + info.outer_class_info_index);
                 }
-                print("; //");
+                print(";");
+                tab();
+                print("// ");
                 if (info.inner_name_index != 0) {
                     print(getInnerName(constant_pool, info) + "=");
                 }
--- a/langtools/test/tools/javap/T4975569.java	Wed Sep 03 19:22:16 2014 +0400
+++ b/langtools/test/tools/javap/T4975569.java	Wed Sep 03 14:06:25 2014 -0700
@@ -23,73 +23,85 @@
 
 /*
  * @test
- * @bug 4975569 6622215
+ * @bug 4975569 6622215 8034861
  * @summary javap doesn't print new flag bits
  */
 
 import java.io.*;
 import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
-public class T4975569
-{
+public class T4975569 {
+    private static final String NEW_LINE = System.getProperty("line.separator");
+    private static final String TEST_CLASSES = System.getProperty("test.classes", ".");
+
     public static void main(String... args) {
         new T4975569().run();
     }
 
     void run() {
-        verify("T4975569$Anno", "flags: ACC_INTERFACE, ACC_ABSTRACT, ACC_ANNOTATION");
-        verify("T4975569$E",    "flags: ACC_FINAL, ACC_SUPER, ACC_ENUM");
-        verify("T4975569$S",    "flags: ACC_BRIDGE, ACC_SYNTHETIC",
-                                "InnerClasses:\n     static");
-        verify("T4975569$V",    "void m(java.lang.String...)",
-                                "flags: ACC_VARARGS");
-        verify("T4975569$Prot", "InnerClasses:\n     protected");
-        //verify("T4975569$Priv", "InnerClasses");
+        verify(Anno.class.getName(), "flags: ACC_INTERFACE, ACC_ABSTRACT, ACC_ANNOTATION");
+        verify(E.class.getName(),    "flags: ACC_FINAL, ACC_SUPER, ACC_ENUM");
+        verify(S.class.getName(),    "flags: ACC_BRIDGE, ACC_SYNTHETIC",
+                                     "InnerClasses:\n  static [# =\\w]+; +// ");
+        verify(V.class.getName(),    "void m\\(java.lang.String...\\)",
+                                     "flags: ACC_VARARGS");
+        verify(Prot.class.getName(), "InnerClasses:\n  protected [# =\\w]+; +// ");
+        verify(Priv.class.getName(), new String[]{"-p"},
+                                     "InnerClasses:\n  private [# =\\w]+; +// ");
+
         if (errors > 0)
             throw new Error(errors + " found.");
     }
 
-    void verify(String className, String... expects) {
-        String output = javap(className);
+    void verify(String className, String[] flags, String... expects) {
+        String output = javap(className, Arrays.asList(flags));
         for (String expect: expects) {
-            if (output.indexOf(expect)< 0)
+            Pattern expectPattern = Pattern.compile(expect);
+            Matcher matcher = expectPattern.matcher(output);
+            if (!matcher.find()) {
                 error(expect + " not found");
+            }
         }
     }
 
-    void error(String msg) {
-        System.err.println(msg);
-        errors++;
+    void verify(String className, String... expects) {
+        verify(className, new String[0], expects);
     }
 
     int errors;
+    void error(String msg) {
+        System.err.println(msg.replace("\n", NEW_LINE));
+        errors++;
+    }
 
-    String javap(String className) {
-        String newline = System.getProperty("line.separator");
-        String testClasses = System.getProperty("test.classes", ".");
+    String javap(String className, List<String> flags) {
         StringWriter sw = new StringWriter();
         PrintWriter out = new PrintWriter(sw);
-        String[] args = { "-v", "-classpath", testClasses, className };
-        int rc = com.sun.tools.javap.Main.run(args, out);
+        List<String> args = new ArrayList<>(flags);
+        args.addAll(Arrays.asList("-v", "-classpath", TEST_CLASSES, className));
+        int rc = com.sun.tools.javap.Main.run(args.toArray(new String[args.size()]), out);
+        out.close();
+        String output = sw.toString();
+        System.err.println("class " + className);
+        System.err.println(output);
+
         if (rc != 0)
             throw new Error("javap failed. rc=" + rc);
-        out.close();
-        String output = sw.toString().replaceAll(newline, "\n");
-        System.out.println("class " + className);
-        System.out.println(output);
-        return output;
+        return output.replaceAll(NEW_LINE, "\n");
     }
 
-    List x() { return null; };
+    List x() { return null; }
 
     class V { void m(String... args) { } }
-    enum E { e; }
+    enum E { e }
     @interface Anno { }
     static class S extends T4975569 {
         ArrayList x() { return null; }
     }
 
     protected class Prot { }
-    //private class Priv { int i; }
+    private class Priv { int i; }
 }