--- old/test/tools/javap/typeAnnotations/TypeCasts.java Thu Feb 28 23:38:00 2013 +++ new/test/tools/javap/typeAnnotations/TypeCasts.java Thu Feb 28 23:38:00 2013 @@ -41,10 +41,6 @@ File classFile = compileTestFile(javaFile); ClassFile cf = ClassFile.read(classFile); - test(cf); - for (Field f : cf.fields) { - test(cf, f); - } for (Method m: cf.methods) { test(cf, m); } @@ -56,77 +52,45 @@ System.out.println("PASSED"); } - void test(ClassFile cf) { - test(cf, Attribute.RuntimeVisibleTypeAnnotations, true); - test(cf, Attribute.RuntimeInvisibleTypeAnnotations, false); - } - void test(ClassFile cf, Method m) { test(cf, m, Attribute.RuntimeVisibleTypeAnnotations, true); test(cf, m, Attribute.RuntimeInvisibleTypeAnnotations, false); } - void test(ClassFile cf, Field m) { - test(cf, m, Attribute.RuntimeVisibleTypeAnnotations, true); - test(cf, m, Attribute.RuntimeInvisibleTypeAnnotations, false); - } // test the result of Attributes.getIndex according to expectations // encoded in the method's name - void test(ClassFile cf, String name, boolean visible) { - int index = cf.attributes.getIndex(cf.constant_pool, name); - if (index != -1) { - Attribute attr = cf.attributes.get(index); - assert attr instanceof RuntimeTypeAnnotations_attribute; - RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr; - all += tAttr.annotations.length; - if (visible) - visibles += tAttr.annotations.length; - else - invisibles += tAttr.annotations.length; - } - } - - // test the result of Attributes.getIndex according to expectations - // encoded in the method's name void test(ClassFile cf, Method m, String name, boolean visible) { - int index = m.attributes.getIndex(cf.constant_pool, name); - if (index != -1) { - Attribute attr = m.attributes.get(index); - assert attr instanceof RuntimeTypeAnnotations_attribute; - RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr; - all += tAttr.annotations.length; - if (visible) - visibles += tAttr.annotations.length; - else - invisibles += tAttr.annotations.length; - } - } + Attribute attr = null; + Code_attribute cAttr = null; - // test the result of Attributes.getIndex according to expectations - // encoded in the method's name - void test(ClassFile cf, Field m, String name, boolean visible) { - int index = m.attributes.getIndex(cf.constant_pool, name); - if (index != -1) { - Attribute attr = m.attributes.get(index); - assert attr instanceof RuntimeTypeAnnotations_attribute; - RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr; - all += tAttr.annotations.length; - if (visible) - visibles += tAttr.annotations.length; - else - invisibles += tAttr.annotations.length; + int index = m.attributes.getIndex(cf.constant_pool, Attribute.Code); + if(index!= -1) { + attr = m.attributes.get(index); + assert attr instanceof Code_attribute; + cAttr = (Code_attribute)attr; + index = cAttr.attributes.getIndex(cf.constant_pool, name); + if(index!= -1) { + attr = cAttr.attributes.get(index); + assert attr instanceof RuntimeTypeAnnotations_attribute; + RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr; + all += tAttr.annotations.length; + if (visible) + visibles += tAttr.annotations.length; + else + invisibles += tAttr.annotations.length; + } } } + File writeTestFile() throws IOException { File f = new File("Test.java"); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f))); out.println("import java.lang.annotation.*;"); out.println("class Test { "); - out.println(" @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})"); - out.println(" @interface A { }"); + out.println(" @Target(ElementType.TYPE_USE) @interface A { }"); out.println(" void emit() {"); out.println(" Object o = null;");