1.1 --- a/test/tools/javac/MethodParameters/ClassFileVisitor.java Wed Oct 16 16:33:04 2013 -0400 1.2 +++ b/test/tools/javac/MethodParameters/ClassFileVisitor.java Thu Oct 17 13:27:36 2013 +0200 1.3 @@ -82,15 +82,14 @@ 1.4 * Read the class and determine some key characteristics, like if it's 1.5 * an enum, or inner class, etc. 1.6 */ 1.7 - void visitClass(final String cname, final File cfile, final StringBuilder sb) 1.8 - throws Exception { 1.9 + void visitClass(final String cname, final File cfile, final StringBuilder sb) throws Exception { 1.10 this.cname = cname; 1.11 classFile = ClassFile.read(cfile); 1.12 isEnum = classFile.access_flags.is(AccessFlags.ACC_ENUM); 1.13 isInterface = classFile.access_flags.is(AccessFlags.ACC_INTERFACE); 1.14 isPublic = classFile.access_flags.is(AccessFlags.ACC_PUBLIC); 1.15 isInner = false; 1.16 - isStatic = true; 1.17 + isStatic = false; 1.18 isAnon = false; 1.19 1.20 Attribute attr = classFile.getAttribute("InnerClasses"); 1.21 @@ -100,10 +99,11 @@ 1.22 sb.append(isStatic ? "static " : "") 1.23 .append(isPublic ? "public " : "") 1.24 .append(isEnum ? "enum " : isInterface ? "interface " : "class ") 1.25 - .append(cname).append(" -- ") 1.26 - .append(isInner? "inner " : "" ) 1.27 - .append(isAnon ? "anon" : "") 1.28 - .append("\n");; 1.29 + .append(cname).append(" -- "); 1.30 + if (isInner) { 1.31 + sb.append(isAnon ? "anon" : "inner"); 1.32 + } 1.33 + sb.append("\n"); 1.34 1.35 for (Method method : classFile.methods) { 1.36 new MethodVisitor().visitMethod(method, sb); 1.37 @@ -148,7 +148,9 @@ 1.38 public int mNumParams; 1.39 public boolean mSynthetic; 1.40 public boolean mIsConstructor; 1.41 + public boolean mIsClinit; 1.42 public boolean mIsBridge; 1.43 + public boolean isFinal; 1.44 public String prefix; 1.45 1.46 void visitMethod(Method method, StringBuilder sb) throws Exception { 1.47 @@ -160,9 +162,13 @@ 1.48 mNumParams = -1; // no MethodParameters attribute found 1.49 mSynthetic = method.access_flags.is(AccessFlags.ACC_SYNTHETIC); 1.50 mIsConstructor = mName.equals("<init>"); 1.51 + mIsClinit = mName.equals("<clinit>"); 1.52 prefix = cname + "." + mName + "() - "; 1.53 mIsBridge = method.access_flags.is(AccessFlags.ACC_BRIDGE); 1.54 1.55 + if (mIsClinit) { 1.56 + sb = new StringBuilder(); // Discard output 1.57 + } 1.58 sb.append(cname).append(".").append(mName).append("("); 1.59 1.60 for (Attribute a : method.attributes) { 1.61 @@ -170,9 +176,18 @@ 1.62 } 1.63 if (mNumParams == -1) { 1.64 if (mSynthetic) { 1.65 - sb.append("<none>)!!"); 1.66 + // We don't generate MethodParameters attribute for synthetic 1.67 + // methods, so we are creating a parameter pattern to match 1.68 + // ReflectionVisitor API output. 1.69 + for (int i = 0; i < mParams; i++) { 1.70 + if (i == 0) 1.71 + sb.append("arg").append(i); 1.72 + else 1.73 + sb.append(", arg").append(i); 1.74 + } 1.75 + sb.append(")/*synthetic*/"); 1.76 } else { 1.77 - sb.append("<none>)"); 1.78 + sb.append(")"); 1.79 } 1.80 } 1.81 sb.append("\n"); 1.82 @@ -217,7 +232,7 @@ 1.83 String sep = ""; 1.84 String userParam = null; 1.85 for (int x = 0; x < mNumParams; x++) { 1.86 - 1.87 + isFinal = (mp.method_parameter_table[x].flags & AccessFlags.ACC_FINAL) != 0; 1.88 // IMPL: Assume all parameters are named, something. 1.89 int cpi = mp.method_parameter_table[x].name_index; 1.90 if (cpi == 0) { 1.91 @@ -229,6 +244,8 @@ 1.92 String param = null; 1.93 try { 1.94 param = classFile.constant_pool.getUTF8Value(cpi); 1.95 + if (isFinal) 1.96 + param = "final " + param; 1.97 sb.append(sep).append(param); 1.98 sep = ", "; 1.99 } catch(ConstantPoolException e) { 1.100 @@ -239,7 +256,7 @@ 1.101 1.102 1.103 // Check availability, flags and special names 1.104 - int check = checkParam(mp, param, x, sb); 1.105 + int check = checkParam(mp, param, x, sb, isFinal); 1.106 if (check < 0) { 1.107 return null; 1.108 } 1.109 @@ -253,9 +270,15 @@ 1.110 char c = userParam.charAt(0); 1.111 expect = (++c) + userParam; 1.112 } 1.113 + if(isFinal && expect != null) 1.114 + expect = "final " + expect; 1.115 if (check > 0) { 1.116 + if(isFinal) { 1.117 + userParam = param.substring(6); 1.118 + } else { 1.119 userParam = param; 1.120 } 1.121 + } 1.122 if (expect != null && !param.equals(expect)) { 1.123 error(prefix + "param[" + x + "]='" 1.124 + param + "' expected '" + expect + "'"); 1.125 @@ -263,7 +286,7 @@ 1.126 } 1.127 } 1.128 if (mSynthetic) { 1.129 - sb.append(")!!"); 1.130 + sb.append(")/*synthetic*/"); 1.131 } else { 1.132 sb.append(")"); 1.133 } 1.134 @@ -278,7 +301,7 @@ 1.135 * explicitly declared parameter. 1.136 */ 1.137 int checkParam(MethodParameters_attribute mp, String param, int index, 1.138 - StringBuilder sb) { 1.139 + StringBuilder sb, boolean isFinal) { 1.140 1.141 boolean synthetic = (mp.method_parameter_table[index].flags 1.142 & AccessFlags.ACC_SYNTHETIC) != 0; 1.143 @@ -304,9 +327,13 @@ 1.144 } 1.145 } else if (index == 0) { 1.146 if (isAnon) { 1.147 + expect = "this\\$[0-9]+"; 1.148 allowMandated = true; 1.149 - expect = "this\\$[0-n]*"; 1.150 + if (isFinal) { 1.151 + expect = "final this\\$[0-9]+"; 1.152 + } 1.153 } else if (isInner && !isStatic) { 1.154 + expect = "this\\$[0-9]+"; 1.155 allowMandated = true; 1.156 if (!isPublic) { 1.157 // some but not all non-public inner classes 1.158 @@ -314,7 +341,9 @@ 1.159 // the test a bit of slack and allow either. 1.160 allowSynthetic = true; 1.161 } 1.162 - expect = "this\\$[0-n]*"; 1.163 + if (isFinal) { 1.164 + expect = "final this\\$[0-9]+"; 1.165 + } 1.166 } 1.167 } 1.168 } else if (isEnum && mNumParams == 1 && index == 0 && mName.equals("valueOf")) { 1.169 @@ -327,8 +356,8 @@ 1.170 */ 1.171 expect = null; 1.172 } 1.173 - if (mandated) sb.append("!"); 1.174 - if (synthetic) sb.append("!!"); 1.175 + if (mandated) sb.append("/*implicit*/"); 1.176 + if (synthetic) sb.append("/*synthetic*/"); 1.177 1.178 // IMPL: our rules a somewhat fuzzy, sometimes allowing both mandated 1.179 // and synthetic. However, a parameters cannot be both.