langtools/test/tools/javac/generics/bridges/BridgeHarness.java
author mchung
Wed, 27 May 2015 13:25:18 -0700
changeset 30846 2b3f379840f0
parent 30730 d3ce7619db2c
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:
18730
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27319
diff changeset
     2
 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
18730
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
     4
 *
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
     7
 * published by the Free Software Foundation.
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
     8
 *
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    13
 * accompanied this code).
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    14
 *
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    18
 *
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    21
 * questions.
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    22
 */
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    23
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    24
/*
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    25
 * @test
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    26
 * @bug 8013789
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    27
 * @summary Compiler should emit bridges in interfaces
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    28
 * @library /tools/javac/lib
30846
2b3f379840f0 8074432: Move jdeps and javap to jdk.jdeps module
mchung
parents: 30730
diff changeset
    29
 * @modules jdk.jdeps/com.sun.tools.classfile
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27319
diff changeset
    30
 *          jdk.compiler/com.sun.tools.javac.code
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27319
diff changeset
    31
 *          jdk.compiler/com.sun.tools.javac.util
18730
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    32
 * @build JavacTestingAbstractProcessor BridgeHarness
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    33
 * @run main BridgeHarness
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    34
 */
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    35
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    36
import com.sun.source.util.JavacTask;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    37
import com.sun.tools.classfile.AccessFlags;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    38
import com.sun.tools.classfile.ClassFile;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    39
import com.sun.tools.classfile.ConstantPool;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    40
import com.sun.tools.classfile.ConstantPoolException;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    41
import com.sun.tools.classfile.Method;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    42
import com.sun.tools.javac.code.Symbol.ClassSymbol;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    43
import com.sun.tools.javac.util.List;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    44
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    45
import java.io.File;
18731
38dd7ede2dfb 8013638: Few policy tests are failing in Lambda nightly
mcimadamore
parents: 18730
diff changeset
    46
import java.io.InputStream;
18730
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    47
import java.util.Arrays;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    48
import java.util.Collections;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    49
import java.util.HashMap;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    50
import java.util.Map;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    51
import java.util.Set;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    52
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    53
import javax.annotation.processing.RoundEnvironment;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    54
import javax.annotation.processing.SupportedAnnotationTypes;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    55
import javax.lang.model.element.Element;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    56
import javax.lang.model.element.TypeElement;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    57
import javax.tools.JavaCompiler;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    58
import javax.tools.JavaFileObject;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    59
import javax.tools.StandardJavaFileManager;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    60
import javax.tools.ToolProvider;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    61
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    62
import static javax.tools.StandardLocation.*;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    63
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    64
public class BridgeHarness {
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    65
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    66
    /** number of errors found (must be zero for the test to pass) */
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    67
    static int nerrors = 0;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    68
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    69
    /** the (shared) Java compiler used for compiling the tests */
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    70
    static final JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    71
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    72
    /** the (shared) file manager used by the compiler */
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    73
    static final StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    74
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    75
    public static void main(String[] args) throws Exception {
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 18731
diff changeset
    76
        try {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 18731
diff changeset
    77
            //set sourcepath
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 18731
diff changeset
    78
            fm.setLocation(SOURCE_PATH,
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 18731
diff changeset
    79
                    Arrays.asList(new File(System.getProperty("test.src"), "tests")));
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 18731
diff changeset
    80
            //set output (-d)
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 18731
diff changeset
    81
            fm.setLocation(javax.tools.StandardLocation.CLASS_OUTPUT,
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 18731
diff changeset
    82
                    Arrays.asList(new File(System.getProperty("user.dir"))));
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 18731
diff changeset
    83
            for (JavaFileObject jfo : fm.list(SOURCE_PATH, "", Collections.singleton(JavaFileObject.Kind.SOURCE), true)) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 18731
diff changeset
    84
                //for each source, compile and check against annotations
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 18731
diff changeset
    85
                new BridgeHarness(jfo).compileAndCheck();
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 18731
diff changeset
    86
            }
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 18731
diff changeset
    87
            //if there were errors, fail
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 18731
diff changeset
    88
            if (nerrors > 0) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 18731
diff changeset
    89
                throw new AssertionError("Errors were found");
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 18731
diff changeset
    90
            }
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 18731
diff changeset
    91
        } finally {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 18731
diff changeset
    92
            fm.close();
18730
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    93
        }
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    94
    }
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    95
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    96
    /* utility methods */
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    97
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    98
    /**
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
    99
     * Remove an element from a list
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   100
     */
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   101
    static <Z> List<Z> drop(List<Z> lz, Z z) {
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   102
        if (lz.head == z) {
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   103
            return drop(lz.tail, z);
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   104
        } else if (lz.isEmpty()) {
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   105
            return lz;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   106
        } else {
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   107
            return drop(lz.tail, z).prepend(lz.head);
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   108
        }
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   109
    }
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   110
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   111
    /**
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   112
     * return a string representation of a bytecode method
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   113
     */
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   114
    static String descriptor(Method m, ConstantPool cp) throws ConstantPoolException {
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   115
        return m.getName(cp) + m.descriptor.getValue(cp);
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   116
    }
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   117
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   118
    /* test harness */
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   119
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   120
    /** Test file to be compiled */
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   121
    JavaFileObject jfo;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   122
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   123
    /** Mapping between class name and list of bridges in class with that name */
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   124
    Map<String, List<Bridge>> bridgesMap = new HashMap<String, List<Bridge>>();
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   125
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   126
    protected BridgeHarness(JavaFileObject jfo) {
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   127
        this.jfo = jfo;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   128
    }
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   129
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   130
    /**
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   131
     * Compile a test using a custom annotation processor and check the generated
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   132
     * bytecode against discovered annotations.
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   133
     */
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   134
    protected void compileAndCheck() throws Exception {
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   135
        JavacTask ct = (JavacTask)comp.getTask(null, fm, null, null, null, Arrays.asList(jfo));
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   136
        ct.setProcessors(Collections.singleton(new BridgeFinder()));
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   137
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   138
        for (JavaFileObject jfo : ct.generate()) {
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   139
            checkBridges(jfo);
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   140
        }
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   141
    }
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   142
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   143
    /**
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   144
     * Check that every bridge in the generated classfile has a matching bridge
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   145
     * annotation in the bridge map
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   146
     */
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   147
    protected void checkBridges(JavaFileObject jfo) {
18731
38dd7ede2dfb 8013638: Few policy tests are failing in Lambda nightly
mcimadamore
parents: 18730
diff changeset
   148
        try (InputStream is = jfo.openInputStream()) {
38dd7ede2dfb 8013638: Few policy tests are failing in Lambda nightly
mcimadamore
parents: 18730
diff changeset
   149
            ClassFile cf = ClassFile.read(is);
18730
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   150
            System.err.println("checking: " + cf.getName());
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   151
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   152
            List<Bridge> bridgeList = bridgesMap.get(cf.getName());
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   153
            if (bridgeList == null) {
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   154
                //no bridges - nothing to check;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   155
                bridgeList = List.nil();
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   156
            }
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   157
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   158
            for (Method m : cf.methods) {
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   159
                if (m.access_flags.is(AccessFlags.ACC_SYNTHETIC | AccessFlags.ACC_BRIDGE)) {
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   160
                    //this is a bridge - see if there's a match in the bridge list
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   161
                    Bridge match = null;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   162
                    for (Bridge b : bridgeList) {
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   163
                        if (b.value().equals(descriptor(m, cf.constant_pool))) {
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   164
                            match = b;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   165
                            break;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   166
                        }
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   167
                    }
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   168
                    if (match == null) {
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   169
                        error("No annotation for bridge method: " + descriptor(m, cf.constant_pool));
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   170
                    } else {
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   171
                        bridgeList = drop(bridgeList, match);
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   172
                    }
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   173
                }
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   174
            }
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   175
            if (bridgeList.nonEmpty()) {
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   176
                error("Redundant bridge annotation found: " + bridgeList.head.value());
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   177
            }
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   178
        } catch (Exception e) {
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   179
            e.printStackTrace();
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   180
            throw new Error("error reading " + jfo.toUri() +": " + e);
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   181
        }
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   182
    }
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   183
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   184
    /**
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   185
     * Log an error
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   186
     */
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   187
    protected void error(String msg) {
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   188
        nerrors++;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   189
        System.err.printf("Error occurred while checking file: %s\nreason: %s\n", jfo.getName(), msg);
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   190
    }
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   191
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   192
    /**
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   193
     * This annotation processor is used to populate the bridge map with the
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   194
     * contents of the annotations that are found on the tests being compiled
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   195
     */
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   196
    @SupportedAnnotationTypes({"Bridges","Bridge"})
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   197
    class BridgeFinder extends JavacTestingAbstractProcessor {
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   198
        @Override
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   199
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   200
            if (roundEnv.processingOver())
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   201
                return true;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   202
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   203
            TypeElement bridgeAnno = elements.getTypeElement("Bridge");
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   204
            TypeElement bridgesAnno = elements.getTypeElement("Bridges");
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   205
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   206
            //see if there are repeated annos
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   207
            for (Element elem: roundEnv.getElementsAnnotatedWith(bridgesAnno)) {
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   208
                List<Bridge> bridgeList = List.nil();
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   209
                Bridges bridges = elem.getAnnotation(Bridges.class);
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   210
                for (Bridge bridge : bridges.value()) {
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   211
                    bridgeList = bridgeList.prepend(bridge);
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   212
                }
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   213
                bridgesMap.put(((ClassSymbol)elem).flatname.toString(), bridgeList);
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   214
            }
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   215
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   216
            //see if there are non-repeated annos
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   217
            for (Element elem: roundEnv.getElementsAnnotatedWith(bridgeAnno)) {
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   218
                Bridge bridge = elem.getAnnotation(Bridge.class);
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   219
                bridgesMap.put(((ClassSymbol)elem).flatname.toString(),
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   220
                        List.of(bridge));
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   221
            }
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   222
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   223
            return true;
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   224
        }
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   225
    }
95354d510139 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
diff changeset
   226
}