1 /* 2 * Copyright (c) 2017, 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 /* 27 * @test 28 * @bug 8051768 29 * @summary Verify that javap prints "param" for RuntimeInvisibleParameterAnnotations 30 * @library /tools/lib 31 * @modules jdk.compiler/com.sun.tools.javac.api 32 * jdk.compiler/com.sun.tools.javac.main 33 * jdk.jdeps/com.sun.tools.javap 34 * @build toolbox.ToolBox toolbox.JavacTask toolbox.JavapTask toolbox.Assert 35 * @run main InvisibleParameterAnnotationsTest 36 */ 37 38 import toolbox.Assert; 39 import toolbox.JavacTask; 40 import toolbox.JavapTask; 41 import toolbox.Task; 42 import toolbox.ToolBox; 43 44 import java.util.Collections; 45 import java.util.List; 46 47 public class InvisibleParameterAnnotationsTest { 48 49 private static final String TestSrc = 50 "import java.lang.annotation.Retention \n;" + 51 "import java.lang.annotation.RetentionPolicy \n;" + 52 53 "public class Sample { \n" + 54 55 "@Retention(RetentionPolicy.CLASS) \n" + 56 "public @interface InvisAnno{} \n" + 57 "@Retention(RetentionPolicy.RUNTIME) \n" + 58 "public @interface VisAnno{} \n" + 59 60 "public void Method(@InvisAnno int arg1,@VisAnno int arg2){};" + 61 "}"; 62 63 private static final String ExpectedSubstring = 64 " RuntimeVisibleParameterAnnotations:\n" + 65 " parameter 0:\n" + 66 " parameter 1:\n" + 67 " 0: #16()\n" + 68 " Sample$VisAnno\n" + 69 " RuntimeInvisibleParameterAnnotations:\n" + 70 " parameter 0:\n" + 71 " 0: #18()\n" + 72 " Sample$InvisAnno\n" + 73 " parameter 1:"; 74 main(String[] args)75 public static void main(String[] args) throws Exception { 76 ToolBox tb = new ToolBox(); 77 new JavacTask(tb).sources(TestSrc).run(); 78 79 List<String> res = new JavapTask(tb) 80 .options("-v") 81 .classes("Sample.class") 82 .run() 83 .writeAll() 84 .getOutputLines(Task.OutputKind.DIRECT); 85 86 List<String> expectedList = tb.split(ExpectedSubstring, "\n"); 87 Boolean found = Collections.indexOfSubList(res, expectedList) > -1; 88 Assert.check(found, "expected output not found: " + ExpectedSubstring); 89 } 90 } 91