langtools/test/tools/javac/annotations/SyntheticParameters.java
author mchung
Wed, 27 May 2015 13:25:18 -0700
changeset 30846 2b3f379840f0
parent 30730 d3ce7619db2c
child 36526 3b41f1c69604
permissions -rw-r--r--
8074432: Move jdeps and javap to jdk.jdeps module Reviewed-by: jjg, alanb, erikj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27853
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 29050
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
27853
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
     4
 *
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
     7
 * published by the Free Software Foundation.
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
     8
 *
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    13
 * accompanied this code).
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    14
 *
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    18
 *
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    21
 * questions.
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    22
 */
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    23
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    24
/*
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    25
 * @test SyntheticParameters
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    26
 * @bug 8065132
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    27
 * @summary Test generation of annotations on inner class parameters.
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    28
 * @library /lib/annotations/
30846
2b3f379840f0 8074432: Move jdeps and javap to jdk.jdeps module
mchung
parents: 30730
diff changeset
    29
 * @modules jdk.jdeps/com.sun.tools.classfile
27853
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    30
 * @run main SyntheticParameters
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    31
 */
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    32
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    33
import annotations.classfile.ClassfileInspector;
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    34
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    35
import java.io.*;
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    36
import java.lang.annotation.*;
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    37
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    38
import com.sun.tools.classfile.*;
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    39
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    40
public class SyntheticParameters extends ClassfileInspector {
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    41
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    42
    private static final String Inner_class = "SyntheticParameters$Inner.class";
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    43
    private static final String Foo_class = "SyntheticParameters$Foo.class";
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    44
    private static final Expected Inner_expected =
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    45
        new Expected("SyntheticParameters$Inner",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    46
                     null,
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    47
                     null,
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    48
                     new ExpectedParameterAnnotation[] {
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    49
                         (ExpectedParameterAnnotation)
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    50
                         // Assert there is an annotation on the
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    51
                         // first parameter.
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    52
                         new ExpectedParameterAnnotation(
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    53
                             "<init>",
29050
76df9080086c 8066725: javac produces classfiles it cannot read
emc
parents: 27853
diff changeset
    54
                             0,
27853
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    55
                             "A",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    56
                             true,
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    57
                             1),
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    58
                         (ExpectedParameterAnnotation)
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    59
                         new ExpectedParameterAnnotation(
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    60
                             "foo",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    61
                             0,
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    62
                             "A",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    63
                             true,
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    64
                             1),
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    65
                         (ExpectedParameterAnnotation)
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    66
                         // Assert there is an annotation on the
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    67
                         // first parameter.
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    68
                         new ExpectedParameterAnnotation(
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    69
                             "<init>",
29050
76df9080086c 8066725: javac produces classfiles it cannot read
emc
parents: 27853
diff changeset
    70
                             0,
27853
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    71
                             "B",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    72
                             false,
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    73
                             1),
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    74
                         (ExpectedParameterAnnotation)
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    75
                         new ExpectedParameterAnnotation(
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    76
                             "foo",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    77
                             0,
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    78
                             "B",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    79
                             false,
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    80
                             1),
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    81
                         (ExpectedParameterAnnotation)
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    82
                         new ExpectedParameterAnnotation(
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    83
                             "foo",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    84
                             1,
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    85
                             "B",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    86
                             false,
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    87
                             0)
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    88
                     },
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    89
                     null);
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    90
    private static final Expected Foo_expected =
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    91
        new Expected("SyntheticParameters$Foo",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    92
                     null,
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    93
                     null,
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    94
                     new ExpectedParameterAnnotation[] {
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    95
                         (ExpectedParameterAnnotation)
29050
76df9080086c 8066725: javac produces classfiles it cannot read
emc
parents: 27853
diff changeset
    96
                         // Assert there is an annotation on the
76df9080086c 8066725: javac produces classfiles it cannot read
emc
parents: 27853
diff changeset
    97
                         // first parameter.
27853
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    98
                         new ExpectedParameterAnnotation(
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    99
                             "<init>",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   100
                             0,
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   101
                             "A",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   102
                             true,
29050
76df9080086c 8066725: javac produces classfiles it cannot read
emc
parents: 27853
diff changeset
   103
                             1),
27853
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   104
                         (ExpectedParameterAnnotation)
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   105
                         // Assert there is an annotation on the
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   106
                         // first parameter.
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   107
                         new ExpectedParameterAnnotation(
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   108
                             "<init>",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   109
                             0,
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   110
                             "B",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   111
                             false,
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   112
                             1)
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   113
                     },
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   114
                     null);
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   115
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   116
    public static void main(String... args) throws Exception {
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   117
        new SyntheticParameters().run(
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   118
            new ClassFile[] { getClassFile(Inner_class, Inner.class),
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   119
                              getClassFile(Foo_class, Foo.class) },
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   120
            new Expected[] { Inner_expected, Foo_expected });
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   121
    }
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   122
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   123
    public class Inner {
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   124
        public Inner(@A @B int a) {}
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   125
        public void foo(@A @B int a, int b) {}
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   126
    }
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   127
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   128
    public static enum Foo {
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   129
        ONE(null);
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   130
        Foo(@A @B Object a) {}
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   131
    }
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   132
}
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   133
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   134
@Retention(RetentionPolicy.RUNTIME)
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   135
@interface A {}
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   136
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   137
@Retention(RetentionPolicy.CLASS)
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   138
@interface B {}