langtools/test/tools/javac/defaultMethods/super/TestDefaultSuperCall.java
author akulyakh
Thu, 21 May 2015 11:41:04 -0700
changeset 30730 d3ce7619db2c
parent 19934 1d8232b1aa18
child 32454 b0ac04e0fefe
permissions -rw-r--r--
8076543: Add @modules as needed to the langtools tests Reviewed-by: jjg, shurailine
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 19934
diff changeset
     2
 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
     4
 *
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
     7
 * published by the Free Software Foundation.
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
     8
 *
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    13
 * accompanied this code).
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    14
 *
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    18
 *
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    21
 * questions.
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    22
 */
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    23
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    24
/*
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    25
 * @test
19934
1d8232b1aa18 8005222: Fixed bugs should have tests with bugid in @bug tag
jfranck
parents: 15384
diff changeset
    26
 * @bug 7192246 8006694
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    27
 * @summary Automatic test for checking correctness of default super/this resolution
15384
5a8d00abf076 8006694: temporarily workaround combo tests are causing time out in several platforms
vromero
parents: 15040
diff changeset
    28
 *  temporarily workaround combo tests are causing time out in several platforms
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
    29
 * @library ../../lib
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 19934
diff changeset
    30
 * @modules jdk.compiler
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
    31
 * @build JavacTestingAbstractThreadedTest
15384
5a8d00abf076 8006694: temporarily workaround combo tests are causing time out in several platforms
vromero
parents: 15040
diff changeset
    32
 * @run main/othervm TestDefaultSuperCall
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    33
 */
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    34
15384
5a8d00abf076 8006694: temporarily workaround combo tests are causing time out in several platforms
vromero
parents: 15040
diff changeset
    35
// 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
    36
// see JDK-8006746
5a8d00abf076 8006694: temporarily workaround combo tests are causing time out in several platforms
vromero
parents: 15040
diff changeset
    37
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    38
import java.net.URI;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    39
import java.util.Arrays;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    40
import java.util.ArrayList;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    41
import java.util.List;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    42
import javax.tools.Diagnostic;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    43
import javax.tools.JavaFileObject;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    44
import javax.tools.SimpleJavaFileObject;
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
    45
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
    46
import com.sun.source.util.JavacTask;
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    47
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
    48
public class TestDefaultSuperCall
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
    49
    extends JavacTestingAbstractThreadedTest
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
    50
    implements Runnable {
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    51
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    52
    enum InterfaceKind {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    53
        DEFAULT("interface A extends B { default void m() { } }"),
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    54
        ABSTRACT("interface A extends B { void m(); }"),
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    55
        NONE("interface A extends B { }");
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    56
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    57
        String interfaceStr;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    58
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    59
        InterfaceKind(String interfaceStr) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    60
            this.interfaceStr = interfaceStr;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    61
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    62
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    63
        boolean methodDefined() {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    64
            return this == DEFAULT;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    65
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    66
    }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    67
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    68
    enum PruneKind {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    69
        NO_PRUNE("interface C { }"),
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    70
        PRUNE("interface C extends A { }");
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    71
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    72
        boolean methodDefined(InterfaceKind ik) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    73
            return this == PRUNE &&
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    74
                    ik.methodDefined();
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    75
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    76
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    77
        String interfaceStr;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    78
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    79
        PruneKind(String interfaceStr) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    80
            this.interfaceStr = interfaceStr;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    81
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    82
    }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    83
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    84
    enum QualifierKind {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    85
        DIRECT_1("C"),
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    86
        DIRECT_2("A"),
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    87
        INDIRECT("B"),
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    88
        UNRELATED("E"),
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    89
        ENCLOSING_1(null),
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    90
        ENCLOSING_2(null);
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    91
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    92
        String qualifierStr;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    93
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    94
        QualifierKind(String qualifierStr) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    95
            this.qualifierStr = qualifierStr;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    96
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    97
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    98
        String getQualifier(Shape sh) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
    99
            switch (this) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   100
                case ENCLOSING_1: return sh.enclosingAt(0);
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   101
                case ENCLOSING_2: return sh.enclosingAt(1);
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   102
                default:
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   103
                    return qualifierStr;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   104
            }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   105
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   106
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   107
        boolean isEnclosing() {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   108
            return this == ENCLOSING_1 ||
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   109
                    this == ENCLOSING_2;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   110
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   111
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   112
        boolean allowSuperCall(InterfaceKind ik, PruneKind pk) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   113
            switch (this) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   114
                case DIRECT_1:
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   115
                    return pk.methodDefined(ik);
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   116
                case DIRECT_2:
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   117
                    return ik.methodDefined() && pk == PruneKind.NO_PRUNE;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   118
                default:
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   119
                    return false;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   120
            }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   121
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   122
    }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   123
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   124
    enum ExprKind {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   125
        THIS("this"),
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   126
        SUPER("super");
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   127
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   128
        String exprStr;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   129
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   130
        ExprKind(String exprStr) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   131
            this.exprStr = exprStr;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   132
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   133
    }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   134
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   135
    enum ElementKind {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   136
        INTERFACE("interface #N { #B }", true),
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   137
        INTERFACE_EXTENDS("interface #N extends A, C { #B }", true),
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   138
        CLASS("class #N { #B }", false),
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   139
        CLASS_EXTENDS("abstract class #N implements A, C { #B }", false),
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   140
        STATIC_CLASS("static class #N { #B }", true),
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   141
        STATIC_CLASS_EXTENDS("abstract static class #N implements A, C { #B }", true),
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   142
        ANON_CLASS("new Object() { #B };", false),
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   143
        METHOD("void test() { #B }", false),
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   144
        STATIC_METHOD("static void test() { #B }", true),
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   145
        DEFAULT_METHOD("default void test() { #B }", false);
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   146
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   147
        String templateDecl;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   148
        boolean isStatic;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   149
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   150
        ElementKind(String templateDecl, boolean isStatic) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   151
            this.templateDecl = templateDecl;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   152
            this.isStatic = isStatic;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   153
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   154
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   155
        boolean isClassDecl() {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   156
            switch(this) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   157
                case METHOD:
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   158
                case STATIC_METHOD:
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   159
                case DEFAULT_METHOD:
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   160
                    return false;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   161
                default:
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   162
                    return true;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   163
            }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   164
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   165
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   166
        boolean isAllowedEnclosing(ElementKind ek, boolean isTop) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   167
            switch (this) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   168
                case CLASS:
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   169
                case CLASS_EXTENDS:
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   170
                    //class is implicitly static inside interface, so skip this combo
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   171
                    return ek.isClassDecl() &&
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   172
                            ek != INTERFACE && ek != INTERFACE_EXTENDS;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   173
                case ANON_CLASS:
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   174
                    return !ek.isClassDecl();
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   175
                case METHOD:
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   176
                    return ek == CLASS || ek == CLASS_EXTENDS ||
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   177
                            ek == STATIC_CLASS || ek == STATIC_CLASS_EXTENDS ||
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   178
                            ek == ANON_CLASS;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   179
                case INTERFACE:
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   180
                case INTERFACE_EXTENDS:
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   181
                case STATIC_CLASS:
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   182
                case STATIC_CLASS_EXTENDS:
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   183
                case STATIC_METHOD:
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   184
                    return (isTop && (ek == CLASS || ek == CLASS_EXTENDS)) ||
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   185
                            ek == STATIC_CLASS || ek == STATIC_CLASS_EXTENDS;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   186
                case DEFAULT_METHOD:
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   187
                    return ek == INTERFACE || ek == INTERFACE_EXTENDS;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   188
                default:
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   189
                    throw new AssertionError("Bad enclosing element kind" + this);
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   190
            }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   191
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   192
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   193
        boolean isAllowedTop() {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   194
            switch (this) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   195
                case CLASS:
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   196
                case CLASS_EXTENDS:
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   197
                case INTERFACE:
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   198
                case INTERFACE_EXTENDS:
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   199
                    return true;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   200
                default:
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   201
                    return false;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   202
            }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   203
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   204
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   205
        boolean hasSuper() {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   206
            return this == INTERFACE_EXTENDS ||
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   207
                    this == STATIC_CLASS_EXTENDS ||
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   208
                    this == CLASS_EXTENDS;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   209
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   210
    }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   211
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   212
    static class Shape {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   213
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   214
        String shapeStr;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   215
        List<ElementKind> enclosingElements;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   216
        List<String> enclosingNames;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   217
        List<String> elementsWithMethod;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   218
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   219
        Shape(ElementKind... elements) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   220
            enclosingElements = new ArrayList<>();
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   221
            enclosingNames = new ArrayList<>();
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   222
            elementsWithMethod = new ArrayList<>();
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   223
            int count = 0;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   224
            String prevName = null;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   225
            for (ElementKind ek : elements) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   226
                String name = "name"+count++;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   227
                if (ek.isStatic) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   228
                    enclosingElements = new ArrayList<>();
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   229
                    enclosingNames = new ArrayList<>();
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   230
                }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   231
                if (ek.isClassDecl()) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   232
                    enclosingElements.add(ek);
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   233
                    enclosingNames.add(name);
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   234
                } else {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   235
                    elementsWithMethod.add(prevName);
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   236
                }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   237
                String element = ek.templateDecl.replaceAll("#N", name);
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   238
                shapeStr = shapeStr ==
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   239
                        null ? element : shapeStr.replaceAll("#B", element);
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   240
                prevName = name;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   241
            }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   242
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   243
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   244
        String getShape(QualifierKind qk, ExprKind ek) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   245
            String methName = ek == ExprKind.THIS ? "test" : "m";
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   246
            String call = qk.getQualifier(this) + "." +
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   247
                    ek.exprStr + "." + methName + "();";
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   248
            return shapeStr.replaceAll("#B", call);
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   249
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   250
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   251
        String enclosingAt(int index) {
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   252
            return index < enclosingNames.size() ?
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   253
                    enclosingNames.get(index) : "BAD";
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   254
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   255
    }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   256
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   257
    public static void main(String... args) throws Exception {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   258
        for (InterfaceKind ik : InterfaceKind.values()) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   259
            for (PruneKind pk : PruneKind.values()) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   260
                for (ElementKind ek1 : ElementKind.values()) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   261
                    if (!ek1.isAllowedTop()) continue;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   262
                    for (ElementKind ek2 : ElementKind.values()) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   263
                        if (!ek2.isAllowedEnclosing(ek1, true)) continue;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   264
                        for (ElementKind ek3 : ElementKind.values()) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   265
                            if (!ek3.isAllowedEnclosing(ek2, false)) continue;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   266
                            for (ElementKind ek4 : ElementKind.values()) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   267
                                if (!ek4.isAllowedEnclosing(ek3, false)) continue;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   268
                                for (ElementKind ek5 : ElementKind.values()) {
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   269
                                    if (!ek5.isAllowedEnclosing(ek4, false) ||
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   270
                                            ek5.isClassDecl()) continue;
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   271
                                    for (QualifierKind qk : QualifierKind.values()) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   272
                                        for (ExprKind ek : ExprKind.values()) {
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   273
                                            pool.execute(
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   274
                                                    new TestDefaultSuperCall(ik, pk,
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   275
                                                    new Shape(ek1, ek2, ek3,
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   276
                                                    ek4, ek5), qk, ek));
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   277
                                        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   278
                                    }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   279
                                }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   280
                            }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   281
                        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   282
                    }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   283
                }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   284
            }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   285
        }
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   286
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   287
        checkAfterExec();
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   288
    }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   289
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   290
    InterfaceKind ik;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   291
    PruneKind pk;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   292
    Shape sh;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   293
    QualifierKind qk;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   294
    ExprKind ek;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   295
    JavaSource source;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   296
    DiagnosticChecker diagChecker;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   297
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   298
    TestDefaultSuperCall(InterfaceKind ik, PruneKind pk, Shape sh,
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   299
            QualifierKind qk, ExprKind ek) {
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   300
        this.ik = ik;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   301
        this.pk = pk;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   302
        this.sh = sh;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   303
        this.qk = qk;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   304
        this.ek = ek;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   305
        this.source = new JavaSource();
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   306
        this.diagChecker = new DiagnosticChecker();
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   307
    }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   308
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   309
    class JavaSource extends SimpleJavaFileObject {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   310
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   311
        String template = "interface E {}\n" +
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   312
                          "interface B { }\n" +
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   313
                          "#I\n" +
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   314
                          "#P\n" +
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   315
                          "#C";
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   316
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   317
        String source;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   318
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   319
        public JavaSource() {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   320
            super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   321
            source = template.replaceAll("#I", ik.interfaceStr)
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   322
                    .replaceAll("#P", pk.interfaceStr)
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   323
                    .replaceAll("#C", sh.getShape(qk, ek));
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   324
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   325
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   326
        @Override
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   327
        public CharSequence getCharContent(boolean ignoreEncodingErrors) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   328
            return source;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   329
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   330
    }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   331
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   332
    public void run() {
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   333
        JavacTask ct = (JavacTask)comp.getTask(null, fm.get(), diagChecker,
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14443
diff changeset
   334
                null, null, Arrays.asList(source));
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   335
        try {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   336
            ct.analyze();
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   337
        } catch (Throwable ex) {
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   338
            processException(ex);
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   339
            return;
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   340
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   341
        check();
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   342
    }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   343
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   344
    void check() {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   345
        boolean errorExpected = false;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   346
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   347
        boolean badEnclosing = false;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   348
        boolean badThis = false;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   349
        boolean badSuper = false;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   350
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   351
        if (qk == QualifierKind.ENCLOSING_1 &&
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   352
                sh.enclosingNames.size() < 1) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   353
            errorExpected |= true;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   354
            badEnclosing = true;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   355
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   356
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   357
        if (qk == QualifierKind.ENCLOSING_2 &&
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   358
                sh.enclosingNames.size() < 2) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   359
            errorExpected |= true;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   360
            badEnclosing = true;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   361
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   362
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   363
        if (ek == ExprKind.THIS) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   364
            boolean found = false;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   365
            for (int i = 0; i < sh.enclosingElements.size(); i++) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   366
                if (sh.enclosingElements.get(i) == ElementKind.ANON_CLASS) continue;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   367
                if (sh.enclosingNames.get(i).equals(qk.getQualifier(sh))) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   368
                    found = sh.elementsWithMethod.contains(sh.enclosingNames.get(i));
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   369
                    break;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   370
                }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   371
            }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   372
            errorExpected |= !found;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   373
            if (!found) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   374
                badThis = true;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   375
            }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   376
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   377
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   378
        if (ek == ExprKind.SUPER) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   379
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   380
            int lastIdx = sh.enclosingElements.size() - 1;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   381
            boolean found = lastIdx == -1 ? false :
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   382
                    sh.enclosingElements.get(lastIdx).hasSuper() &&
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   383
                    qk.allowSuperCall(ik, pk);
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   384
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   385
            errorExpected |= !found;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   386
            if (!found) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   387
                badSuper = true;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   388
            }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   389
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   390
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   391
        checkCount.incrementAndGet();
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   392
        if (diagChecker.errorFound != errorExpected) {
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   393
            throw new AssertionError("Problem when compiling source:\n" +
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   394
                    source.getCharContent(true) +
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   395
                    "\nenclosingElems: " + sh.enclosingElements +
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   396
                    "\nenclosingNames: " + sh.enclosingNames +
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   397
                    "\nelementsWithMethod: " + sh.elementsWithMethod +
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   398
                    "\nbad encl: " + badEnclosing +
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   399
                    "\nbad this: " + badThis +
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   400
                    "\nbad super: " + badSuper +
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   401
                    "\nqual kind: " + qk +
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   402
                    "\nfound error: " + diagChecker.errorFound);
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   403
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   404
    }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   405
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   406
    static class DiagnosticChecker
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   407
        implements javax.tools.DiagnosticListener<JavaFileObject> {
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   408
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   409
        boolean errorFound;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   410
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   411
        public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   412
            if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   413
                errorFound = true;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   414
            }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   415
        }
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   416
    }
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 14547
diff changeset
   417
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents:
diff changeset
   418
}