langtools/test/tools/javac/lambda/LambdaParserTest.java
author mcimadamore
Mon, 31 Aug 2015 17:33:34 +0100
changeset 32454 b0ac04e0fefe
parent 30730 d3ce7619db2c
permissions -rw-r--r--
8129962: Investigate performance improvements in langtools combo tests Summary: New combo API that runs all combo instances in a shared javac context (whenever possible). Reviewed-by: jjg, jlahoda, vromero
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 15384
diff changeset
     2
 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
     4
 *
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
     8
 *
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    13
 * accompanied this code).
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    14
 *
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    18
 *
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    21
 * questions.
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    22
 */
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    23
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    24
/*
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    25
 * @test
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    26
 * @bug 7115050 8003280 8005852 8006694 8129962
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 11381
diff changeset
    27
 * @summary Add lambda tests
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 11381
diff changeset
    28
 *  Add parser support for lambda expressions
15384
5a8d00abf076 8006694: temporarily workaround combo tests are causing time out in several platforms
vromero
parents: 15367
diff changeset
    29
 *  temporarily workaround combo tests are causing time out in several platforms
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    30
 * @library /tools/javac/lib
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    31
 * @modules jdk.compiler/com.sun.tools.javac.api
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    32
 *          jdk.compiler/com.sun.tools.javac.code
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    33
 *          jdk.compiler/com.sun.tools.javac.comp
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    34
 *          jdk.compiler/com.sun.tools.javac.main
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    35
 *          jdk.compiler/com.sun.tools.javac.tree
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    36
 *          jdk.compiler/com.sun.tools.javac.util
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    37
 * @build combo.ComboTestHelper
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    38
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    39
 * @run main LambdaParserTest
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    40
 */
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    41
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    42
import java.io.IOException;
15384
5a8d00abf076 8006694: temporarily workaround combo tests are causing time out in several platforms
vromero
parents: 15367
diff changeset
    43
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    44
import combo.ComboInstance;
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    45
import combo.ComboParameter;
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    46
import combo.ComboTask.Result;
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    47
import combo.ComboTestHelper;
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    48
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    49
public class LambdaParserTest extends ComboInstance<LambdaParserTest> {
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    50
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    51
    enum LambdaKind implements ComboParameter {
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    52
        NILARY_EXPR("()->x"),
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    53
        NILARY_STMT("()->{ return x; }"),
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    54
        ONEARY_SHORT_EXPR("#{NAME}->x"),
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    55
        ONEARY_SHORT_STMT("#{NAME}->{ return x; }"),
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    56
        ONEARY_EXPR("(#{MOD[0]} #{TYPE[0]} #{NAME})->x"),
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    57
        ONEARY_STMT("(#{MOD[0]} #{TYPE[0]} #{NAME})->{ return x; }"),
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    58
        TWOARY_EXPR("(#{MOD[0]} #{TYPE[0]} #{NAME}, #{MOD[1]} #{TYPE[1]} y)->x"),
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    59
        TWOARY_STMT("(#{MOD[0]} #{TYPE[0]} #{NAME}, #{MOD[1]} #{TYPE[1]} y)->{ return x; }");
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    60
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    61
        String lambdaTemplate;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    62
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    63
        LambdaKind(String lambdaTemplate) {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    64
            this.lambdaTemplate = lambdaTemplate;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    65
        }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    66
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    67
        @Override
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    68
        public String expand(String optParameter) {
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    69
            return lambdaTemplate;
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    70
        }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    71
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    72
        int arity() {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    73
            switch (this) {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    74
                case NILARY_EXPR:
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    75
                case NILARY_STMT: return 0;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    76
                case ONEARY_SHORT_EXPR:
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    77
                case ONEARY_SHORT_STMT:
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    78
                case ONEARY_EXPR:
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    79
                case ONEARY_STMT: return 1;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    80
                case TWOARY_EXPR:
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    81
                case TWOARY_STMT: return 2;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    82
                default: throw new AssertionError("Invalid lambda kind " + this);
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    83
            }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    84
        }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    85
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    86
        boolean isShort() {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    87
            return this == ONEARY_SHORT_EXPR ||
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    88
                    this == ONEARY_SHORT_STMT;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    89
        }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    90
    }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
    91
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
    92
    enum LambdaParameterName implements ComboParameter {
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 15040
diff changeset
    93
        IDENT("x"),
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 15040
diff changeset
    94
        UNDERSCORE("_");
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 15040
diff changeset
    95
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 15040
diff changeset
    96
        String nameStr;
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 15040
diff changeset
    97
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 15040
diff changeset
    98
        LambdaParameterName(String nameStr) {
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 15040
diff changeset
    99
            this.nameStr = nameStr;
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 15040
diff changeset
   100
        }
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   101
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   102
        @Override
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   103
        public String expand(String optParameter) {
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   104
            return nameStr;
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   105
        }
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 15040
diff changeset
   106
    }
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 15040
diff changeset
   107
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   108
    enum LambdaParameterKind implements ComboParameter {
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   109
        IMPLICIT(""),
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   110
        EXPLIICT_SIMPLE("A"),
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14547
diff changeset
   111
        EXPLIICT_SIMPLE_ARR1("A[]"),
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14547
diff changeset
   112
        EXPLIICT_SIMPLE_ARR2("A[][]"),
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   113
        EXPLICIT_VARARGS("A..."),
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   114
        EXPLICIT_GENERIC1("A<X>"),
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14547
diff changeset
   115
        EXPLICIT_GENERIC2("A<? extends X, ? super Y>"),
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14547
diff changeset
   116
        EXPLICIT_GENERIC2_VARARGS("A<? extends X, ? super Y>..."),
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14547
diff changeset
   117
        EXPLICIT_GENERIC2_ARR1("A<? extends X, ? super Y>[]"),
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14547
diff changeset
   118
        EXPLICIT_GENERIC2_ARR2("A<? extends X, ? super Y>[][]");
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   119
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   120
        String parameterType;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   121
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   122
        LambdaParameterKind(String parameterType) {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   123
            this.parameterType = parameterType;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   124
        }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   125
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   126
        boolean explicit() {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   127
            return this != IMPLICIT;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   128
        }
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14547
diff changeset
   129
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14547
diff changeset
   130
        boolean isVarargs() {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14547
diff changeset
   131
            return this == EXPLICIT_VARARGS ||
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14547
diff changeset
   132
                    this == EXPLICIT_GENERIC2_VARARGS;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14547
diff changeset
   133
        }
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   134
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   135
        @Override
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   136
        public String expand(String optParameter) {
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   137
            return parameterType;
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   138
        }
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   139
    }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   140
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   141
    enum ModifierKind implements ComboParameter {
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   142
        NONE(""),
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   143
        FINAL("final"),
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   144
        PUBLIC("public");
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   145
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   146
        String modifier;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   147
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   148
        ModifierKind(String modifier) {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   149
            this.modifier = modifier;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   150
        }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   151
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   152
        boolean compatibleWith(LambdaParameterKind pk) {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   153
            switch (this) {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   154
                case PUBLIC: return false;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   155
                case FINAL: return pk != LambdaParameterKind.IMPLICIT;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   156
                case NONE: return true;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   157
                default: throw new AssertionError("Invalid modifier kind " + this);
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   158
            }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   159
        }
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   160
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   161
        @Override
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   162
        public String expand(String optParameter) {
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   163
            return modifier;
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   164
        }
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   165
    }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   166
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   167
    enum ExprKind implements ComboParameter {
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   168
        NONE("#{LAMBDA}#{SUBEXPR}"),
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   169
        SINGLE_PAREN1("(#{LAMBDA}#{SUBEXPR})"),
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   170
        SINGLE_PAREN2("(#{LAMBDA})#{SUBEXPR}"),
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   171
        DOUBLE_PAREN1("((#{LAMBDA}#{SUBEXPR}))"),
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   172
        DOUBLE_PAREN2("((#{LAMBDA})#{SUBEXPR})"),
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   173
        DOUBLE_PAREN3("((#{LAMBDA}))#{SUBEXPR}");
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   174
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   175
        String expressionTemplate;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   176
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   177
        ExprKind(String expressionTemplate) {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   178
            this.expressionTemplate = expressionTemplate;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   179
        }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   180
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   181
        @Override
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   182
        public String expand(String optParameter) {
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   183
            return expressionTemplate;
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   184
        }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   185
    }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   186
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   187
    enum SubExprKind implements ComboParameter {
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   188
        NONE(""),
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   189
        SELECT_FIELD(".f"),
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   190
        SELECT_METHOD(".f()"),
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   191
        SELECT_NEW(".new Foo()"),
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   192
        POSTINC("++"),
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   193
        POSTDEC("--");
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   194
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   195
        String subExpression;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   196
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   197
        SubExprKind(String subExpression) {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   198
            this.subExpression = subExpression;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   199
        }
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   200
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   201
        @Override
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   202
        public String expand(String optParameter) {
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   203
            return subExpression;
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   204
        }
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   205
    }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   206
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   207
    public static void main(String... args) throws Exception {
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   208
        new ComboTestHelper<LambdaParserTest>()
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   209
                .withFilter(LambdaParserTest::redundantTestFilter)
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   210
                .withFilter(LambdaParserTest::badImplicitFilter)
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   211
                .withDimension("LAMBDA", (x, lk) -> x.lk = lk, LambdaKind.values())
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   212
                .withDimension("NAME", (x, name) -> x.pn = name, LambdaParameterName.values())
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   213
                .withArrayDimension("TYPE", (x, type, idx) -> x.pks[idx] = type, 2, LambdaParameterKind.values())
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   214
                .withArrayDimension("MOD", (x, mod, idx) -> x.mks[idx] = mod, 2, ModifierKind.values())
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   215
                .withDimension("EXPR", ExprKind.values())
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   216
                .withDimension("SUBEXPR", SubExprKind.values())
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   217
                .run(LambdaParserTest::new);
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   218
    }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   219
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   220
    LambdaParameterKind[] pks = new LambdaParameterKind[2];
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   221
    ModifierKind[] mks = new ModifierKind[2];
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   222
    LambdaKind lk;
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 15040
diff changeset
   223
    LambdaParameterName pn;
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   224
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   225
    boolean badImplicitFilter() {
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   226
        return !(mks[0] != ModifierKind.NONE && lk.isShort());
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   227
    }
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   228
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   229
    boolean redundantTestFilter() {
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   230
        for (int i = lk.arity(); i < mks.length ; i++) {
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   231
            if (mks[i].ordinal() != 0) {
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   232
                return false;
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   233
            }
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   234
        }
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   235
        for (int i = lk.arity(); i < pks.length ; i++) {
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   236
            if (pks[i].ordinal() != 0) {
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   237
                return false;
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   238
            }
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   239
        }
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   240
        return true;
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   241
    }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   242
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   243
    String template = "class Test {\n" +
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   244
                      "   SAM s = #{EXPR};\n" +
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   245
                      "}";
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   246
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   247
    @Override
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   248
    public void doWork() throws IOException {
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   249
        check(newCompilationTask()
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   250
                .withSourceFromTemplate(template)
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   251
                .parse());
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   252
    }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   253
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   254
    void check(Result<?> res) {
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   255
        boolean errorExpected = (lk.arity() > 0 && !mks[0].compatibleWith(pks[0])) ||
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   256
                (lk.arity() > 1 && !mks[1].compatibleWith(pks[1]));
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   257
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   258
        if (lk.arity() == 2 &&
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   259
                (pks[0].explicit() != pks[1].explicit() ||
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   260
                pks[0].isVarargs())) {
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   261
            errorExpected = true;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   262
        }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   263
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 15040
diff changeset
   264
        errorExpected |= pn == LambdaParameterName.UNDERSCORE &&
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 15040
diff changeset
   265
                lk.arity() > 0;
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 15040
diff changeset
   266
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   267
        if (errorExpected != res.hasErrors()) {
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   268
            fail("invalid diagnostics for source:\n" +
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   269
                res.compilationInfo() +
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30730
diff changeset
   270
                "\nFound error: " + res.hasErrors() +
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   271
                "\nExpected error: " + errorExpected);
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   272
        }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   273
    }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents:
diff changeset
   274
}