test/tools/javap/typeAnnotations/Presence.java

changeset 1755
ddb4a2bfcd82
parent 1521
71f35e4b93a5
child 2525
2eb010b6cb22
     1.1 --- a/test/tools/javap/typeAnnotations/Presence.java	Tue May 14 13:55:35 2013 -0700
     1.2 +++ b/test/tools/javap/typeAnnotations/Presence.java	Tue May 14 15:04:06 2013 -0700
     1.3 @@ -91,17 +91,40 @@
     1.4      // test the result of Attributes.getIndex according to expectations
     1.5      // encoded in the method's name
     1.6      void test(ClassFile cf, Method m, String name, boolean visible) {
     1.7 +        Attribute attr = null;
     1.8 +        Code_attribute cAttr = null;
     1.9 +        RuntimeTypeAnnotations_attribute tAttr = null;
    1.10 +
    1.11 +        // collect annotations attributes on method
    1.12          int index = m.attributes.getIndex(cf.constant_pool, name);
    1.13          if (index != -1) {
    1.14 -            Attribute attr = m.attributes.get(index);
    1.15 +            attr = m.attributes.get(index);
    1.16              assert attr instanceof RuntimeTypeAnnotations_attribute;
    1.17 -            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
    1.18 +            tAttr = (RuntimeTypeAnnotations_attribute)attr;
    1.19              all += tAttr.annotations.length;
    1.20              if (visible)
    1.21                  visibles += tAttr.annotations.length;
    1.22              else
    1.23                  invisibles += tAttr.annotations.length;
    1.24          }
    1.25 +        // collect annotations from method's code attribute
    1.26 +        index = m.attributes.getIndex(cf.constant_pool, Attribute.Code);
    1.27 +        if(index!= -1) {
    1.28 +            attr = m.attributes.get(index);
    1.29 +            assert attr instanceof Code_attribute;
    1.30 +            cAttr = (Code_attribute)attr;
    1.31 +            index = cAttr.attributes.getIndex(cf.constant_pool, name);
    1.32 +            if(index!= -1) {
    1.33 +                attr = cAttr.attributes.get(index);
    1.34 +                assert attr instanceof RuntimeTypeAnnotations_attribute;
    1.35 +                tAttr = (RuntimeTypeAnnotations_attribute)attr;
    1.36 +                all += tAttr.annotations.length;
    1.37 +                if (visible)
    1.38 +                    visibles += tAttr.annotations.length;
    1.39 +                else
    1.40 +                    invisibles += tAttr.annotations.length;
    1.41 +               }
    1.42 +        }
    1.43      }
    1.44  
    1.45      // test the result of Attributes.getIndex according to expectations
    1.46 @@ -121,12 +144,12 @@
    1.47      }
    1.48  
    1.49      File writeTestFile() throws IOException {
    1.50 -        File f = new File("Test.java");
    1.51 +        File f = new File("TestPresence.java");
    1.52          PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f)));
    1.53          out.println("import java.util.*;");
    1.54          out.println("import java.lang.annotation.*;");
    1.55  
    1.56 -        out.println("class Test<@Test.A T extends @Test.A List<@Test.A String>> { ");
    1.57 +        out.println("class TestPresence<@TestPresence.A T extends @TestPresence.A List<@TestPresence.A String>> { ");
    1.58          out.println("  @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})");
    1.59          out.println("  @interface A { }");
    1.60  
    1.61 @@ -134,7 +157,7 @@
    1.62  
    1.63          out.println("  <@A TM extends @A List<@A String>>");
    1.64          out.println("  Map<@A String, @A List<@A String>>");
    1.65 -        out.println("  method(@A Test<T> this, List<@A String> @A [] param1, String @A [] @A ... param2)");
    1.66 +        out.println("  method(@A TestPresence<T> this, List<@A String> @A [] param1, String @A [] @A ... param2)");
    1.67          out.println("  throws @A Exception {");
    1.68          out.println("    @A String lc1 = null;");
    1.69          out.println("    @A List<@A String> lc2 = null;");

mercurial