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 31 import annotations.classfile.ClassfileInspector; 32 33 import java.io.*; 34 import java.lang.annotation.*; 35 36 import com.sun.tools.classfile.*; 37 38 public 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 no annotation on the 48 // this$0 parameter. 49 new ExpectedMethodTypeAnnotation.Builder( 50 "<init>", 51 "A", 52 TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER, 53 false, 54 0).setParameterIndex(0).build(), 55 (ExpectedMethodTypeAnnotation) 56 // Assert there is an annotation on the 57 // first parameter. 58 new ExpectedMethodTypeAnnotation.Builder( 59 "<init>", 60 "A", 61 TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER, 62 false, 63 1).setParameterIndex(1).build(), 64 (ExpectedMethodTypeAnnotation) 65 new ExpectedMethodTypeAnnotation.Builder( 66 "foo", 67 "A", 68 TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER, 69 false, 70 1).setParameterIndex(0).build(), 71 (ExpectedMethodTypeAnnotation) 72 new ExpectedMethodTypeAnnotation.Builder( 73 "foo", 74 "A", 75 TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER, 76 false, 77 0).setParameterIndex(1).build() 78 }, 79 null); 80 private static final Expected Foo_expected = 81 new Expected("SyntheticParameters$Foo", 82 null, 83 new ExpectedMethodTypeAnnotation[] { 84 (ExpectedMethodTypeAnnotation) 85 // Assert there is no annotation on the 86 // $enum$name parameter. 87 new ExpectedMethodTypeAnnotation.Builder( 88 "<init>", 89 "A", 90 TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER, 91 false, 92 0).setParameterIndex(0).build(), 93 (ExpectedMethodTypeAnnotation) 94 // Assert there is no annotation on the 95 // $enum$ordinal parameter. 96 new ExpectedMethodTypeAnnotation.Builder( 97 "<init>", 98 "A", 99 TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER, 100 false, 101 0).setParameterIndex(1).build(), 102 (ExpectedMethodTypeAnnotation) 103 // Assert there is an annotation on the 104 // first parameter. 105 new ExpectedMethodTypeAnnotation.Builder( 106 "<init>", 107 "A", 108 TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER, 109 false, 110 1).setParameterIndex(2).build() 111 }, 112 null); 113 114 public static void main(String... args) throws Exception { 115 new SyntheticParameters().run( 116 new ClassFile[] { getClassFile(Inner_class, Inner.class), 117 getClassFile(Foo_class, Foo.class) }, 118 new Expected[] { Inner_expected, Foo_expected }); 119 } 120 121 public class Inner { 122 public Inner(@A int a) {} 123 public void foo(@A int a, int b) {} 124 } 125 126 public static enum Foo { 127 ONE(null); 128 Foo(@A Object a) {} 129 } 130 } 131 132 @Target({ElementType.TYPE_USE}) 133 @interface A {}