test/tools/javac/annotations/typeAnnotations/classfile/NoTargetAnnotations.java

Print this page


   1 /*
   2  * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 129             Attribute attr = m.attributes.get(index);
 130             assert attr instanceof RuntimeAnnotations_attribute;
 131             RuntimeAnnotations_attribute tAttr = (RuntimeAnnotations_attribute)attr;
 132             this.declAnnotations += tAttr.annotations.length;
 133         }
 134     }
 135 
 136     // test the result of Attributes.getIndex according to expectations
 137     // encoded in the method's name
 138     void testDecl(ClassFile cf, Field m, String name, boolean visible) {
 139         int index = m.attributes.getIndex(cf.constant_pool, name);
 140         if (index != -1) {
 141             Attribute attr = m.attributes.get(index);
 142             assert attr instanceof RuntimeAnnotations_attribute;
 143             RuntimeAnnotations_attribute tAttr = (RuntimeAnnotations_attribute)attr;
 144             this.declAnnotations += tAttr.annotations.length;
 145         }
 146     }
 147 
 148     File compileTestFile(File f) {
 149         int rc = com.sun.tools.javac.Main.compile(new String[] { "-XDTA:writer", "-source", "1.8", "-g", f.getPath() });
 150         if (rc != 0)
 151             throw new Error("compilation failed. rc=" + rc);
 152         String path = f.getPath();
 153         return new File(path.substring(0, path.length() - 5) + ".class");
 154     }
 155 
 156     void countAnnotations() {
 157         int expected_all = expected_visibles + expected_invisibles;
 158 
 159         if (expected_all != all) {
 160             errors++;
 161             System.err.println("expected " + expected_all
 162                     + " annotations but found " + all);
 163         }
 164 
 165         if (expected_visibles != visibles) {
 166             errors++;
 167             System.err.println("expected " + expected_visibles
 168                     + " visibles annotations but found " + visibles);
 169         }


   1 /*
   2  * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 129             Attribute attr = m.attributes.get(index);
 130             assert attr instanceof RuntimeAnnotations_attribute;
 131             RuntimeAnnotations_attribute tAttr = (RuntimeAnnotations_attribute)attr;
 132             this.declAnnotations += tAttr.annotations.length;
 133         }
 134     }
 135 
 136     // test the result of Attributes.getIndex according to expectations
 137     // encoded in the method's name
 138     void testDecl(ClassFile cf, Field m, String name, boolean visible) {
 139         int index = m.attributes.getIndex(cf.constant_pool, name);
 140         if (index != -1) {
 141             Attribute attr = m.attributes.get(index);
 142             assert attr instanceof RuntimeAnnotations_attribute;
 143             RuntimeAnnotations_attribute tAttr = (RuntimeAnnotations_attribute)attr;
 144             this.declAnnotations += tAttr.annotations.length;
 145         }
 146     }
 147 
 148     File compileTestFile(File f) {
 149         int rc = com.sun.tools.javac.Main.compile(new String[] { "-XDTA:writer", "-g", f.getPath() });
 150         if (rc != 0)
 151             throw new Error("compilation failed. rc=" + rc);
 152         String path = f.getPath();
 153         return new File(path.substring(0, path.length() - 5) + ".class");
 154     }
 155 
 156     void countAnnotations() {
 157         int expected_all = expected_visibles + expected_invisibles;
 158 
 159         if (expected_all != all) {
 160             errors++;
 161             System.err.println("expected " + expected_all
 162                     + " annotations but found " + all);
 163         }
 164 
 165         if (expected_visibles != visibles) {
 166             errors++;
 167             System.err.println("expected " + expected_visibles
 168                     + " visibles annotations but found " + visibles);
 169         }