SyntheticParameters.java revision 2823:e77eb6b8977e
1/* 2 * Copyright (c) 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 */ 23 24/* 25 * @test SyntheticParameters 26 * @summary Test generation of annotations on inner class parameters. 27 * @library /lib/annotations/ 28 * @run main SyntheticParameters 29 */ 30 31import annotations.classfile.ClassfileInspector; 32 33import java.io.*; 34import java.lang.annotation.*; 35 36import com.sun.tools.classfile.*; 37 38public class SyntheticParameters extends ClassfileInspector { 39 40 private static final String Inner_class = "SyntheticParameters$Inner.class"; 41 private static final String Foo_class = "SyntheticParameters$Foo.class"; 42 private static final Expected Inner_expected = 43 new Expected("SyntheticParameters$Inner", 44 null, 45 new ExpectedMethodTypeAnnotation[] { 46 (ExpectedMethodTypeAnnotation) 47 // Assert there is an annotation on the 48 // first parameter. 49 new ExpectedMethodTypeAnnotation.Builder( 50 "<init>", 51 "A", 52 TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER, 53 false, 54 1).setParameterIndex(0).build() 55 }, 56 null); 57 private static final Expected Foo_expected = 58 new Expected("SyntheticParameters$Foo", 59 null, 60 new ExpectedMethodTypeAnnotation[] { 61 (ExpectedMethodTypeAnnotation) 62 // Assert there is no annotation on the 63 // $enum$name parameter. 64 new ExpectedMethodTypeAnnotation.Builder( 65 "<init>", 66 "A", 67 TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER, 68 false, 69 1).setParameterIndex(0).build() }, 70 null); 71 72 public static void main(String... args) throws Exception { 73 new SyntheticParameters().run( 74 new ClassFile[] { getClassFile(Inner_class, Inner.class), 75 getClassFile(Foo_class, Foo.class) }, 76 new Expected[] { Inner_expected, Foo_expected }); 77 } 78 79 public class Inner { 80 public Inner(@A int a) {} 81 public void foo(@A int a, int b) {} 82 } 83 84 public static enum Foo { 85 ONE(null); 86 Foo(@A Object a) {} 87 } 88} 89 90@Target({ElementType.TYPE_USE}) 91@interface A {} 92