langtools/test/tools/javac/lambda/FunctionalInterfaceConversionTest.java
author kizune
Tue, 01 Apr 2014 10:00:43 -0700
changeset 23801 e9b2766ef89c
parent 15384 5a8d00abf076
child 30730 d3ce7619db2c
permissions -rw-r--r--
8031425: Two langtools/javac tests fail by timeout on Windows Reviewed-by: jjg, vromero
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14723
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
     1
/*
23801
e9b2766ef89c 8031425: Two langtools/javac tests fail by timeout on Windows
kizune
parents: 15384
diff changeset
     2
 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
14723
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
     4
 *
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
     7
 * published by the Free Software Foundation.
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
     8
 *
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    13
 * accompanied this code).
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    14
 *
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    18
 *
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    21
 * questions.
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    22
 */
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    23
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    24
/**
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    25
 * @test
15384
5a8d00abf076 8006694: temporarily workaround combo tests are causing time out in several platforms
vromero
parents: 15040
diff changeset
    26
 * @bug 8003280 8004102 8006694
14723
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    27
 * @summary Add lambda tests
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    28
 *  perform several automated checks in lambda conversion, esp. around accessibility
15384
5a8d00abf076 8006694: temporarily workaround combo tests are causing time out in several platforms
vromero
parents: 15040
diff changeset
    29
 *  temporarily workaround combo tests are causing time out in several platforms
14723
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    30
 * @author  Maurizio Cimadamore
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
    31
 * @library ../lib
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
    32
 * @build JavacTestingAbstractThreadedTest
23801
e9b2766ef89c 8031425: Two langtools/javac tests fail by timeout on Windows
kizune
parents: 15384
diff changeset
    33
 * @run main/timeout=600/othervm FunctionalInterfaceConversionTest
14723
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    34
 */
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    35
15384
5a8d00abf076 8006694: temporarily workaround combo tests are causing time out in several platforms
vromero
parents: 15040
diff changeset
    36
// use /othervm to avoid jtreg timeout issues (CODETOOLS-7900047)
5a8d00abf076 8006694: temporarily workaround combo tests are causing time out in several platforms
vromero
parents: 15040
diff changeset
    37
// see JDK-8006746
5a8d00abf076 8006694: temporarily workaround combo tests are causing time out in several platforms
vromero
parents: 15040
diff changeset
    38
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
    39
import java.io.IOException;
14723
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    40
import java.net.URI;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    41
import java.util.Arrays;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    42
import javax.tools.Diagnostic;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    43
import javax.tools.JavaCompiler;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    44
import javax.tools.JavaFileObject;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    45
import javax.tools.SimpleJavaFileObject;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    46
import javax.tools.ToolProvider;
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
    47
import com.sun.source.util.JavacTask;
14723
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    48
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
    49
public class FunctionalInterfaceConversionTest
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
    50
    extends JavacTestingAbstractThreadedTest
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
    51
    implements Runnable {
14723
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    52
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    53
    enum PackageKind {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    54
        NO_PKG(""),
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    55
        PKG_A("a");
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    56
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    57
        String pkg;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    58
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    59
        PackageKind(String pkg) {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    60
            this.pkg = pkg;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    61
        }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    62
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    63
        String getPkgDecl() {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    64
            return this == NO_PKG ?
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    65
                "" :
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    66
                "package " + pkg + ";";
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    67
        }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    68
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    69
        String getImportStat() {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    70
            return this == NO_PKG ?
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    71
                "" :
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    72
                "import " + pkg + ".*;";
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    73
        }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    74
    }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    75
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    76
    enum SamKind {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    77
        CLASS("public class Sam {  }"),
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    78
        ABSTACT_CLASS("public abstract class Sam {  }"),
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    79
        ANNOTATION("public @interface Sam {  }"),
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    80
        ENUM("public enum Sam { }"),
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    81
        INTERFACE("public interface Sam { \n #METH; \n }");
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    82
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    83
        String sam_str;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    84
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    85
        SamKind(String sam_str) {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    86
            this.sam_str = sam_str;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    87
        }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    88
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    89
        String getSam(String methStr) {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    90
            return sam_str.replaceAll("#METH", methStr);
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    91
        }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    92
    }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    93
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    94
    enum ModifierKind {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    95
        PUBLIC("public"),
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    96
        PACKAGE("");
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    97
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    98
        String modifier_str;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
    99
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   100
        ModifierKind(String modifier_str) {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   101
            this.modifier_str = modifier_str;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   102
        }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   103
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   104
        boolean stricterThan(ModifierKind that) {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   105
            return this.ordinal() > that.ordinal();
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   106
        }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   107
    }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   108
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   109
    enum TypeKind {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   110
        EXCEPTION("Exception"),
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   111
        PKG_CLASS("PackageClass");
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   112
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   113
        String typeStr;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   114
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   115
        private TypeKind(String typeStr) {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   116
            this.typeStr = typeStr;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   117
        }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   118
    }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   119
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   120
    enum ExprKind {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   121
        LAMBDA("x -> null"),
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   122
        MREF("this::m");
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   123
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   124
        String exprStr;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   125
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   126
        private ExprKind(String exprStr) {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   127
            this.exprStr = exprStr;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   128
        }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   129
    }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   130
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   131
    enum MethodKind {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   132
        NONE(""),
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   133
        NON_GENERIC("public abstract #R m(#ARG s) throws #T;"),
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   134
        GENERIC("public abstract <X> #R m(#ARG s) throws #T;");
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   135
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   136
        String methodTemplate;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   137
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   138
        private MethodKind(String methodTemplate) {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   139
            this.methodTemplate = methodTemplate;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   140
        }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   141
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   142
        String getMethod(TypeKind retType, TypeKind argType, TypeKind thrownType) {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   143
            return methodTemplate.replaceAll("#R", retType.typeStr).
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   144
                    replaceAll("#ARG", argType.typeStr).
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   145
                    replaceAll("#T", thrownType.typeStr);
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   146
        }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   147
    }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   148
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   149
    public static void main(String[] args) throws Exception {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   150
        for (PackageKind samPkg : PackageKind.values()) {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   151
            for (ModifierKind modKind : ModifierKind.values()) {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   152
                for (SamKind samKind : SamKind.values()) {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   153
                    for (MethodKind samMeth : MethodKind.values()) {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   154
                        for (MethodKind clientMeth : MethodKind.values()) {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   155
                            for (TypeKind retType : TypeKind.values()) {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   156
                                for (TypeKind argType : TypeKind.values()) {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   157
                                    for (TypeKind thrownType : TypeKind.values()) {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   158
                                        for (ExprKind exprKind : ExprKind.values()) {
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   159
                                            pool.execute(
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   160
                                                new FunctionalInterfaceConversionTest(
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   161
                                                    samPkg, modKind, samKind,
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   162
                                                    samMeth, clientMeth, retType,
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   163
                                                    argType, thrownType, exprKind));
14723
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   164
                                        }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   165
                                    }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   166
                                }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   167
                            }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   168
                        }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   169
                    }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   170
                }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   171
            }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   172
        }
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   173
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   174
        checkAfterExec(false);
14723
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   175
    }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   176
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   177
    PackageKind samPkg;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   178
    ModifierKind modKind;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   179
    SamKind samKind;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   180
    MethodKind samMeth;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   181
    MethodKind clientMeth;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   182
    TypeKind retType;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   183
    TypeKind argType;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   184
    TypeKind thrownType;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   185
    ExprKind exprKind;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   186
    DiagnosticChecker dc;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   187
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   188
    SourceFile samSourceFile = new SourceFile("Sam.java", "#P \n #C") {
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   189
        @Override
14723
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   190
        public String toString() {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   191
            return template.replaceAll("#P", samPkg.getPkgDecl()).
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   192
                    replaceAll("#C", samKind.getSam(
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   193
                    samMeth.getMethod(retType, argType, thrownType)));
14723
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   194
        }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   195
    };
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   196
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   197
    SourceFile pkgClassSourceFile =
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   198
            new SourceFile("PackageClass.java",
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   199
                           "#P\n #M class PackageClass extends Exception { }") {
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   200
        @Override
14723
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   201
        public String toString() {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   202
            return template.replaceAll("#P", samPkg.getPkgDecl()).
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   203
                    replaceAll("#M", modKind.modifier_str);
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   204
        }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   205
    };
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   206
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   207
    SourceFile clientSourceFile =
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   208
            new SourceFile("Client.java",
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   209
                           "#I\n abstract class Client { \n" +
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   210
                           "  Sam s = #E;\n" +
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   211
                           "  #M \n }") {
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   212
        @Override
14723
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   213
        public String toString() {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   214
            return template.replaceAll("#I", samPkg.getImportStat())
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   215
                    .replaceAll("#E", exprKind.exprStr)
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   216
                    .replaceAll("#M", clientMeth.getMethod(retType, argType, thrownType));
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   217
        }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   218
    };
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   219
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   220
    FunctionalInterfaceConversionTest(PackageKind samPkg, ModifierKind modKind,
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   221
            SamKind samKind, MethodKind samMeth, MethodKind clientMeth,
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   222
            TypeKind retType, TypeKind argType, TypeKind thrownType,
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   223
            ExprKind exprKind) {
14723
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   224
        this.samPkg = samPkg;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   225
        this.modKind = modKind;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   226
        this.samKind = samKind;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   227
        this.samMeth = samMeth;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   228
        this.clientMeth = clientMeth;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   229
        this.retType = retType;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   230
        this.argType = argType;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   231
        this.thrownType = thrownType;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   232
        this.exprKind = exprKind;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   233
        this.dc = new DiagnosticChecker();
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   234
    }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   235
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   236
    @Override
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   237
    public void run() {
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   238
        final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   239
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   240
        JavacTask ct = (JavacTask)tool.getTask(null, fm.get(), dc, null, null,
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   241
                Arrays.asList(samSourceFile, pkgClassSourceFile, clientSourceFile));
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   242
        try {
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   243
            ct.analyze();
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   244
        } catch (IOException ex) {
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   245
            throw new AssertionError("Test failing with cause", ex.getCause());
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   246
        }
14723
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   247
        if (dc.errorFound == checkSamConversion()) {
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   248
            throw new AssertionError(samSourceFile + "\n\n" +
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   249
                pkgClassSourceFile + "\n\n" + clientSourceFile);
14723
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   250
        }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   251
    }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   252
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   253
    boolean checkSamConversion() {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   254
        if (samKind != SamKind.INTERFACE) {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   255
            //sam type must be an interface
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   256
            return false;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   257
        } else if (samMeth == MethodKind.NONE) {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   258
            //interface must have at least a method
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   259
            return false;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   260
        } else if (exprKind == ExprKind.LAMBDA &&
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   261
                samMeth != MethodKind.NON_GENERIC) {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   262
            //target method for lambda must be non-generic
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   263
            return false;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   264
        } else if (exprKind == ExprKind.MREF &&
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   265
                clientMeth == MethodKind.NONE) {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   266
            return false;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   267
        } else if (samPkg != PackageKind.NO_PKG &&
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   268
                modKind != ModifierKind.PUBLIC &&
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   269
                (retType == TypeKind.PKG_CLASS ||
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   270
                argType == TypeKind.PKG_CLASS ||
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   271
                thrownType == TypeKind.PKG_CLASS)) {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   272
            //target must not contain inaccessible types
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   273
            return false;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   274
        } else {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   275
            return true;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   276
        }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   277
    }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   278
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   279
    abstract class SourceFile extends SimpleJavaFileObject {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   280
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   281
        protected String template;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   282
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   283
        public SourceFile(String filename, String template) {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   284
            super(URI.create("myfo:/" + filename), JavaFileObject.Kind.SOURCE);
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   285
            this.template = template;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   286
        }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   287
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   288
        @Override
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   289
        public CharSequence getCharContent(boolean ignoreEncodingErrors) {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   290
            return toString();
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   291
        }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   292
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   293
        @Override
14723
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   294
        public abstract String toString();
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   295
    }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   296
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   297
    static class DiagnosticChecker
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   298
        implements javax.tools.DiagnosticListener<JavaFileObject> {
14723
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   299
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   300
        boolean errorFound = false;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   301
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14723
diff changeset
   302
        @Override
14723
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   303
        public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   304
            if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   305
                errorFound = true;
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   306
            }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   307
        }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   308
    }
46aa71a5e4e0 8004102: Add support for generic functional descriptors
mcimadamore
parents:
diff changeset
   309
}