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