langtools/test/tools/javac/annotations/SyntheticParameters.java
author emc
Fri, 13 Feb 2015 17:00:45 -0500
changeset 29050 76df9080086c
parent 27853 746c658e8d35
child 30730 d3ce7619db2c
permissions -rw-r--r--
8066725: javac produces classfiles it cannot read Summary: Revert behavioral changes from 8029012 and 8065132 Reviewed-by: jfranck
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
/*
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
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/
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    29
 * @run main SyntheticParameters
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    30
 */
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
import annotations.classfile.ClassfileInspector;
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    33
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    34
import java.io.*;
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    35
import java.lang.annotation.*;
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    36
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    37
import com.sun.tools.classfile.*;
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    38
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    39
public class SyntheticParameters extends ClassfileInspector {
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    40
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    41
    private static final String Inner_class = "SyntheticParameters$Inner.class";
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    42
    private static final String Foo_class = "SyntheticParameters$Foo.class";
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    43
    private static final Expected Inner_expected =
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    44
        new Expected("SyntheticParameters$Inner",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    45
                     null,
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
                     new ExpectedParameterAnnotation[] {
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    48
                         (ExpectedParameterAnnotation)
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    49
                         // Assert there is an annotation on the
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    50
                         // first parameter.
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    51
                         new ExpectedParameterAnnotation(
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    52
                             "<init>",
29050
76df9080086c 8066725: javac produces classfiles it cannot read
emc
parents: 27853
diff changeset
    53
                             0,
27853
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    54
                             "A",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    55
                             true,
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    56
                             1),
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    57
                         (ExpectedParameterAnnotation)
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    58
                         new ExpectedParameterAnnotation(
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    59
                             "foo",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    60
                             0,
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    61
                             "A",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    62
                             true,
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    63
                             1),
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    64
                         (ExpectedParameterAnnotation)
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    65
                         // Assert there is an annotation on the
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    66
                         // first parameter.
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    67
                         new ExpectedParameterAnnotation(
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    68
                             "<init>",
29050
76df9080086c 8066725: javac produces classfiles it cannot read
emc
parents: 27853
diff changeset
    69
                             0,
27853
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    70
                             "B",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    71
                             false,
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    72
                             1),
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    73
                         (ExpectedParameterAnnotation)
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    74
                         new ExpectedParameterAnnotation(
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    75
                             "foo",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    76
                             0,
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    77
                             "B",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    78
                             false,
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    79
                             1),
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    80
                         (ExpectedParameterAnnotation)
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    81
                         new ExpectedParameterAnnotation(
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    82
                             "foo",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    83
                             1,
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    84
                             "B",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    85
                             false,
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    86
                             0)
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    87
                     },
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    88
                     null);
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    89
    private static final Expected Foo_expected =
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    90
        new Expected("SyntheticParameters$Foo",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    91
                     null,
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
                     new ExpectedParameterAnnotation[] {
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    94
                         (ExpectedParameterAnnotation)
29050
76df9080086c 8066725: javac produces classfiles it cannot read
emc
parents: 27853
diff changeset
    95
                         // Assert there is an annotation on the
76df9080086c 8066725: javac produces classfiles it cannot read
emc
parents: 27853
diff changeset
    96
                         // first parameter.
27853
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    97
                         new ExpectedParameterAnnotation(
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    98
                             "<init>",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
    99
                             0,
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   100
                             "A",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   101
                             true,
29050
76df9080086c 8066725: javac produces classfiles it cannot read
emc
parents: 27853
diff changeset
   102
                             1),
27853
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   103
                         (ExpectedParameterAnnotation)
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   104
                         // Assert there is an annotation on the
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   105
                         // first parameter.
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   106
                         new ExpectedParameterAnnotation(
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   107
                             "<init>",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   108
                             0,
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   109
                             "B",
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   110
                             false,
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   111
                             1)
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   112
                     },
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   113
                     null);
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   114
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   115
    public static void main(String... args) throws Exception {
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   116
        new SyntheticParameters().run(
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   117
            new ClassFile[] { getClassFile(Inner_class, Inner.class),
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   118
                              getClassFile(Foo_class, Foo.class) },
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   119
            new Expected[] { Inner_expected, Foo_expected });
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   120
    }
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
    public class Inner {
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   123
        public Inner(@A @B int a) {}
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   124
        public void foo(@A @B int a, int b) {}
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   125
    }
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
    public static enum Foo {
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   128
        ONE(null);
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   129
        Foo(@A @B Object a) {}
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   130
    }
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
@Retention(RetentionPolicy.RUNTIME)
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   134
@interface A {}
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   135
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   136
@Retention(RetentionPolicy.CLASS)
746c658e8d35 8065132: Parameter annotations not updated when synthetic parameters are prepended
emc
parents:
diff changeset
   137
@interface B {}