langtools/test/tools/javac/T6695379/AnnotationsAreNotCopiedToBridgeMethodsTest.java
author juh
Tue, 25 Jun 2013 14:31:29 -0700
changeset 18551 882a3948c6e6
parent 18000 5d29ce00a7a2
child 30730 d3ce7619db2c
permissions -rw-r--r--
8017325: Cleanup of the javadoc <code> tag in java.security.cert Summary: Convert javadoc <code>...</code> and <tt>...</tt> tags to {@code ...} Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18000
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
     1
/*
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
     4
 *
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
     8
 *
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    13
 * accompanied this code).
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    14
 *
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    18
 *
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    21
 * questions.
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    22
 */
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    23
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    24
/*
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    25
 * @test
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    26
 * @bug 6695379
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    27
 * @summary Copy method annotations and parameter annotations to synthetic
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    28
 * bridge methods
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    29
 * @run main AnnotationsAreNotCopiedToBridgeMethodsTest
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    30
 */
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    31
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    32
import java.lang.annotation.ElementType;
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    33
import java.lang.annotation.Target;
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    34
import java.io.BufferedInputStream;
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    35
import java.lang.annotation.Retention;
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    36
import java.lang.annotation.RetentionPolicy;
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    37
import java.nio.file.Files;
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    38
import java.nio.file.Path;
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    39
import java.nio.file.Paths;
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    40
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    41
import com.sun.tools.classfile.AccessFlags;
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    42
import com.sun.tools.classfile.Attribute;
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    43
import com.sun.tools.classfile.Attributes;
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    44
import com.sun.tools.classfile.ClassFile;
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    45
import com.sun.tools.classfile.Method;
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    46
import com.sun.tools.javac.util.Assert;
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    47
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    48
public class AnnotationsAreNotCopiedToBridgeMethodsTest {
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    49
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    50
    public static void main(String[] args) throws Exception {
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    51
        new AnnotationsAreNotCopiedToBridgeMethodsTest().run();
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    52
    }
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    53
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    54
    void run() throws Exception {
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    55
        checkClassFile(Paths.get(System.getProperty("test.classes"),
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    56
                this.getClass().getSimpleName() + "$CovariantReturnType.class"));
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    57
        checkClassFile(Paths.get(System.getProperty("test.classes"),
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    58
                this.getClass().getSimpleName() +
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    59
                "$CovariantReturnType$VisibilityChange.class"));
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    60
    }
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    61
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    62
    void checkClassFile(final Path cfilePath) throws Exception {
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    63
        ClassFile classFile = ClassFile.read(
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    64
                new BufferedInputStream(Files.newInputStream(cfilePath)));
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    65
        for (Method method : classFile.methods) {
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    66
            if (method.access_flags.is(AccessFlags.ACC_BRIDGE)) {
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    67
                checkForAttr(method.attributes,
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    68
                        "Annotations hasn't been copied to bridge method",
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    69
                        Attribute.RuntimeVisibleAnnotations,
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    70
                        Attribute.RuntimeVisibleParameterAnnotations);
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    71
            }
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    72
        }
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    73
    }
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    74
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    75
    void checkForAttr(Attributes attrs, String errorMsg, String... attrNames) {
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    76
        for (String attrName : attrNames) {
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    77
            Assert.checkNonNull(attrs.get(attrName), errorMsg);
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    78
        }
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    79
    }
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    80
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    81
    @Target(value = {ElementType.PARAMETER})
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    82
    @Retention(RetentionPolicy.RUNTIME)
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    83
    @interface ParamAnnotation {}
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    84
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    85
    @Target(value = {ElementType.METHOD})
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    86
    @Retention(RetentionPolicy.RUNTIME)
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    87
    @interface MethodAnnotation {}
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    88
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    89
    abstract class T<A,B> {
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    90
        B m(A a){return null;}
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    91
    }
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    92
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    93
    class CovariantReturnType extends T<Integer, Integer> {
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    94
        @MethodAnnotation
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    95
        Integer m(@ParamAnnotation Integer i) {
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    96
            return i;
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    97
        }
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    98
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
    99
        public class VisibilityChange extends CovariantReturnType {}
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
   100
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
   101
    }
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
   102
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
diff changeset
   103
}