8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final

Reviewed-by: jjg, jfranck
This commit is contained in:
Matherey Nunez 2013-10-17 13:27:36 +02:00
parent b8aff04aa0
commit 7c6e4696ab
23 changed files with 352 additions and 51 deletions

View file

@ -82,15 +82,14 @@ class ClassFileVisitor extends Tester.Visitor {
* Read the class and determine some key characteristics, like if it's
* an enum, or inner class, etc.
*/
void visitClass(final String cname, final File cfile, final StringBuilder sb)
throws Exception {
void visitClass(final String cname, final File cfile, final StringBuilder sb) throws Exception {
this.cname = cname;
classFile = ClassFile.read(cfile);
isEnum = classFile.access_flags.is(AccessFlags.ACC_ENUM);
isInterface = classFile.access_flags.is(AccessFlags.ACC_INTERFACE);
isPublic = classFile.access_flags.is(AccessFlags.ACC_PUBLIC);
isInner = false;
isStatic = true;
isStatic = false;
isAnon = false;
Attribute attr = classFile.getAttribute("InnerClasses");
@ -100,10 +99,11 @@ class ClassFileVisitor extends Tester.Visitor {
sb.append(isStatic ? "static " : "")
.append(isPublic ? "public " : "")
.append(isEnum ? "enum " : isInterface ? "interface " : "class ")
.append(cname).append(" -- ")
.append(isInner? "inner " : "" )
.append(isAnon ? "anon" : "")
.append("\n");;
.append(cname).append(" -- ");
if (isInner) {
sb.append(isAnon ? "anon" : "inner");
}
sb.append("\n");
for (Method method : classFile.methods) {
new MethodVisitor().visitMethod(method, sb);
@ -148,7 +148,9 @@ class ClassFileVisitor extends Tester.Visitor {
public int mNumParams;
public boolean mSynthetic;
public boolean mIsConstructor;
public boolean mIsClinit;
public boolean mIsBridge;
public boolean isFinal;
public String prefix;
void visitMethod(Method method, StringBuilder sb) throws Exception {
@ -160,9 +162,13 @@ class ClassFileVisitor extends Tester.Visitor {
mNumParams = -1; // no MethodParameters attribute found
mSynthetic = method.access_flags.is(AccessFlags.ACC_SYNTHETIC);
mIsConstructor = mName.equals("<init>");
mIsClinit = mName.equals("<clinit>");
prefix = cname + "." + mName + "() - ";
mIsBridge = method.access_flags.is(AccessFlags.ACC_BRIDGE);
if (mIsClinit) {
sb = new StringBuilder(); // Discard output
}
sb.append(cname).append(".").append(mName).append("(");
for (Attribute a : method.attributes) {
@ -170,9 +176,18 @@ class ClassFileVisitor extends Tester.Visitor {
}
if (mNumParams == -1) {
if (mSynthetic) {
sb.append("<none>)!!");
// We don't generate MethodParameters attribute for synthetic
// methods, so we are creating a parameter pattern to match
// ReflectionVisitor API output.
for (int i = 0; i < mParams; i++) {
if (i == 0)
sb.append("arg").append(i);
else
sb.append(", arg").append(i);
}
sb.append(")/*synthetic*/");
} else {
sb.append("<none>)");
sb.append(")");
}
}
sb.append("\n");
@ -217,7 +232,7 @@ class ClassFileVisitor extends Tester.Visitor {
String sep = "";
String userParam = null;
for (int x = 0; x < mNumParams; x++) {
isFinal = (mp.method_parameter_table[x].flags & AccessFlags.ACC_FINAL) != 0;
// IMPL: Assume all parameters are named, something.
int cpi = mp.method_parameter_table[x].name_index;
if (cpi == 0) {
@ -229,6 +244,8 @@ class ClassFileVisitor extends Tester.Visitor {
String param = null;
try {
param = classFile.constant_pool.getUTF8Value(cpi);
if (isFinal)
param = "final " + param;
sb.append(sep).append(param);
sep = ", ";
} catch(ConstantPoolException e) {
@ -239,7 +256,7 @@ class ClassFileVisitor extends Tester.Visitor {
// Check availability, flags and special names
int check = checkParam(mp, param, x, sb);
int check = checkParam(mp, param, x, sb, isFinal);
if (check < 0) {
return null;
}
@ -253,9 +270,15 @@ class ClassFileVisitor extends Tester.Visitor {
char c = userParam.charAt(0);
expect = (++c) + userParam;
}
if(isFinal && expect != null)
expect = "final " + expect;
if (check > 0) {
if(isFinal) {
userParam = param.substring(6);
} else {
userParam = param;
}
}
if (expect != null && !param.equals(expect)) {
error(prefix + "param[" + x + "]='"
+ param + "' expected '" + expect + "'");
@ -263,7 +286,7 @@ class ClassFileVisitor extends Tester.Visitor {
}
}
if (mSynthetic) {
sb.append(")!!");
sb.append(")/*synthetic*/");
} else {
sb.append(")");
}
@ -278,7 +301,7 @@ class ClassFileVisitor extends Tester.Visitor {
* explicitly declared parameter.
*/
int checkParam(MethodParameters_attribute mp, String param, int index,
StringBuilder sb) {
StringBuilder sb, boolean isFinal) {
boolean synthetic = (mp.method_parameter_table[index].flags
& AccessFlags.ACC_SYNTHETIC) != 0;
@ -304,9 +327,13 @@ class ClassFileVisitor extends Tester.Visitor {
}
} else if (index == 0) {
if (isAnon) {
expect = "this\\$[0-9]+";
allowMandated = true;
expect = "this\\$[0-n]*";
if (isFinal) {
expect = "final this\\$[0-9]+";
}
} else if (isInner && !isStatic) {
expect = "this\\$[0-9]+";
allowMandated = true;
if (!isPublic) {
// some but not all non-public inner classes
@ -314,7 +341,9 @@ class ClassFileVisitor extends Tester.Visitor {
// the test a bit of slack and allow either.
allowSynthetic = true;
}
expect = "this\\$[0-n]*";
if (isFinal) {
expect = "final this\\$[0-9]+";
}
}
}
} else if (isEnum && mNumParams == 1 && index == 0 && mName.equals("valueOf")) {
@ -327,8 +356,8 @@ class ClassFileVisitor extends Tester.Visitor {
*/
expect = null;
}
if (mandated) sb.append("!");
if (synthetic) sb.append("!!");
if (mandated) sb.append("/*implicit*/");
if (synthetic) sb.append("/*synthetic*/");
// IMPL: our rules a somewhat fuzzy, sometimes allowing both mandated
// and synthetic. However, a parameters cannot be both.