test/langtools/tools/javap/typeAnnotations/InvisibleParameterAnnotationsTest.java
author jjg
Tue, 21 Nov 2017 13:06:43 -0800
changeset 47875 93bba74ed8a3
parent 47216 71c04702a3d5
child 52377 907fdbbdf584
permissions -rw-r--r--
8156694: javap should render annotations in a friendly way Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43364
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
     1
/*
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
     4
 *
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    10
 *
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    15
 * accompanied this code).
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    16
 *
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    20
 *
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    23
 * questions.
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    24
 */
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    25
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    26
/*
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    27
 * @test
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    28
 * @bug 8051768
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    29
 * @summary Verify that javap prints "param" for RuntimeInvisibleParameterAnnotations
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    30
 * @library /tools/lib
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    31
 * @modules jdk.compiler/com.sun.tools.javac.api
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    32
 *          jdk.compiler/com.sun.tools.javac.main
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    33
 *          jdk.jdeps/com.sun.tools.javap
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    34
 * @build toolbox.ToolBox toolbox.JavacTask toolbox.JavapTask toolbox.Assert
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    35
 * @run main InvisibleParameterAnnotationsTest
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    36
 */
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    37
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    38
import toolbox.Assert;
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    39
import toolbox.JavacTask;
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    40
import toolbox.JavapTask;
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    41
import toolbox.Task;
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    42
import toolbox.ToolBox;
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    43
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    44
import java.util.Collections;
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    45
import java.util.List;
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    46
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    47
public class InvisibleParameterAnnotationsTest {
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    48
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    49
    private static final String TestSrc =
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    50
            "import java.lang.annotation.Retention \n;" +
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    51
            "import java.lang.annotation.RetentionPolicy \n;" +
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    52
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    53
            "public class Sample { \n" +
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    54
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    55
                "@Retention(RetentionPolicy.CLASS) \n" +
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    56
                "public @interface InvisAnno{} \n" +
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    57
                "@Retention(RetentionPolicy.RUNTIME) \n" +
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    58
                "public @interface VisAnno{} \n" +
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    59
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    60
                "public void Method(@InvisAnno int arg1,@VisAnno int arg2){};" +
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    61
            "}";
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    62
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    63
    private static final String ExpectedSubstring =
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    64
            "    RuntimeVisibleParameterAnnotations:\n" +
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    65
            "      parameter 0:\n" +
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    66
            "      parameter 1:\n" +
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    67
            "        0: #16()\n" +
47875
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    68
            "          Sample$VisAnno\n" +
43364
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    69
            "    RuntimeInvisibleParameterAnnotations:\n" +
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    70
            "      parameter 0:\n" +
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    71
            "        0: #18()\n" +
47875
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    72
            "          Sample$InvisAnno\n" +
43364
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    73
            "      parameter 1:";
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    74
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    75
    public static void main(String[] args) throws Exception {
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    76
        ToolBox tb = new ToolBox();
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    77
        new JavacTask(tb).sources(TestSrc).run();
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    78
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    79
        List<String> res = new JavapTask(tb)
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    80
                .options("-v")
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    81
                .classes("Sample.class")
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    82
                .run()
47875
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    83
                .writeAll()
43364
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    84
                .getOutputLines(Task.OutputKind.DIRECT);
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    85
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    86
        List<String> expectedList = tb.split(ExpectedSubstring, "\n");
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    87
        Boolean found = Collections.indexOfSubList(res, expectedList) > -1;
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    88
        Assert.check(found, "expected output not found: " + ExpectedSubstring);
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    89
    }
469da954ee6b 8051768: Inconsistent output for Visible and InvisibleParameterAnnotations
jjg
parents:
diff changeset
    90
}