langtools/test/tools/javac/defaultMethods/static/hiding/InterfaceMethodHidingTest.java
author kizune
Tue, 01 Apr 2014 10:00:43 -0700
changeset 23801 e9b2766ef89c
parent 22448 a85fbad9d687
child 27319 030080f03e4f
permissions -rw-r--r--
8031425: Two langtools/javac tests fail by timeout on Windows Reviewed-by: jjg, vromero
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15377
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
     1
/*
23801
e9b2766ef89c 8031425: Two langtools/javac tests fail by timeout on Windows
kizune
parents: 22448
diff changeset
     2
 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
15377
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
     4
 *
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
     7
 * published by the Free Software Foundation.
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
     8
 *
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    13
 * accompanied this code).
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    14
 *
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    18
 *
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    21
 * questions.
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    22
 */
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    23
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    24
/*
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    25
 * @test
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    26
 * @bug 8005166
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    27
 * @summary Add support for static interface methods
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    28
 *          Smoke test for static interface method hiding
23801
e9b2766ef89c 8031425: Two langtools/javac tests fail by timeout on Windows
kizune
parents: 22448
diff changeset
    29
 * @run main/timeout=600 InterfaceMethodHidingTest
15377
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    30
 */
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    31
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    32
import com.sun.source.util.JavacTask;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    33
import java.net.URI;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    34
import java.util.Arrays;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    35
import javax.tools.Diagnostic;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    36
import javax.tools.JavaCompiler;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    37
import javax.tools.JavaFileObject;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    38
import javax.tools.SimpleJavaFileObject;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    39
import javax.tools.StandardJavaFileManager;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    40
import javax.tools.ToolProvider;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    41
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    42
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    43
public class InterfaceMethodHidingTest {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    44
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    45
    static int checkCount = 0;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    46
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    47
    enum SignatureKind {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    48
        VOID_INTEGER("void m(Integer s)", "return;"),
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    49
        STRING_INTEGER("String m(Integer s)", "return null;"),
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    50
        VOID_STRING("void m(String s)", "return;"),
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    51
        STRING_STRING("String m(String s)", "return null;");
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    52
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    53
        String sigStr;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    54
        String retStr;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    55
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    56
        SignatureKind(String sigStr, String retStr) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    57
            this.sigStr = sigStr;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    58
            this.retStr = retStr;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    59
        }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    60
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    61
        boolean overrideEquivalentWith(SignatureKind s2) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    62
            switch (this) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    63
                case VOID_INTEGER:
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    64
                case STRING_INTEGER:
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    65
                    return s2 == VOID_INTEGER || s2 == STRING_INTEGER;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    66
                case VOID_STRING:
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    67
                case STRING_STRING:
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    68
                    return s2 == VOID_STRING || s2 == STRING_STRING;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    69
                default:
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    70
                    throw new AssertionError("bad signature kind");
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    71
            }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    72
        }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    73
    }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    74
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    75
    enum MethodKind {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    76
        VIRTUAL("", "#M #S;"),
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    77
        STATIC("static", "#M #S { #BE; #R }"),
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    78
        DEFAULT("default", "#M #S { #BE; #R }");
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    79
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    80
        String modStr;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    81
        String methTemplate;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    82
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    83
        MethodKind(String modStr, String methTemplate) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    84
            this.modStr = modStr;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    85
            this.methTemplate = methTemplate;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    86
        }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    87
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    88
        boolean inherithed() {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    89
            return this != STATIC;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    90
        }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    91
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    92
        static boolean overrides(MethodKind mk1, SignatureKind sk1, MethodKind mk2, SignatureKind sk2) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    93
            return sk1 == sk2 &&
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    94
                    mk2.inherithed() &&
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    95
                    mk1 != STATIC;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    96
        }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    97
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    98
        String getBody(BodyExpr be, SignatureKind sk) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
    99
            return methTemplate.replaceAll("#BE", be.bodyExprStr)
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   100
                    .replaceAll("#R", sk.retStr)
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   101
                    .replaceAll("#M", modStr)
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   102
                    .replaceAll("#S", sk.sigStr);
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   103
        }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   104
    }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   105
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   106
    enum BodyExpr {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   107
        NONE(""),
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   108
        THIS("Object o = this");
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   109
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   110
        String bodyExprStr;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   111
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   112
        BodyExpr(String bodyExprStr) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   113
            this.bodyExprStr = bodyExprStr;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   114
        }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   115
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   116
        boolean allowed(MethodKind mk) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   117
            return this == NONE ||
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   118
                    mk != MethodKind.STATIC;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   119
        }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   120
    }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   121
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   122
    public static void main(String... args) throws Exception {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   123
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   124
        //create default shared JavaCompiler - reused across multiple compilations
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   125
        JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   126
        StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   127
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   128
        for (MethodKind mk1 : MethodKind.values()) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   129
            for (SignatureKind sk1 : SignatureKind.values()) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   130
                for (BodyExpr be1 : BodyExpr.values()) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   131
                    for (MethodKind mk2 : MethodKind.values()) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   132
                        for (SignatureKind sk2 : SignatureKind.values()) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   133
                            for (BodyExpr be2 : BodyExpr.values()) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   134
                                for (MethodKind mk3 : MethodKind.values()) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   135
                                    for (SignatureKind sk3 : SignatureKind.values()) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   136
                                        for (BodyExpr be3 : BodyExpr.values()) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   137
                                            new InterfaceMethodHidingTest(mk1, mk2, mk3, sk1, sk2, sk3, be1, be2, be3).run(comp, fm);
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   138
                                        }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   139
                                    }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   140
                                }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   141
                            }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   142
                        }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   143
                    }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   144
                }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   145
            }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   146
        }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   147
        System.out.println("Total check executed: " + checkCount);
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   148
    }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   149
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   150
    MethodKind mk1, mk2, mk3;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   151
    SignatureKind sk1, sk2, sk3;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   152
    BodyExpr be1, be2, be3;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   153
    JavaSource source;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   154
    DiagnosticChecker diagChecker;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   155
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   156
    InterfaceMethodHidingTest(MethodKind mk1, MethodKind mk2, MethodKind mk3,
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   157
            SignatureKind sk1, SignatureKind sk2, SignatureKind sk3, BodyExpr be1, BodyExpr be2, BodyExpr be3) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   158
        this.mk1 = mk1;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   159
        this.mk2 = mk2;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   160
        this.mk3 = mk3;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   161
        this.sk1 = sk1;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   162
        this.sk2 = sk2;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   163
        this.sk3 = sk3;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   164
        this.be1 = be1;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   165
        this.be2 = be2;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   166
        this.be3 = be3;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   167
        this.source = new JavaSource();
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   168
        this.diagChecker = new DiagnosticChecker();
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   169
    }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   170
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   171
    class JavaSource extends SimpleJavaFileObject {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   172
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   173
        String template = "interface Sup {\n" +
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   174
                          "   default void sup() { }\n" +
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   175
                          "}\n" +
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   176
                          "interface A extends Sup {\n" +
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   177
                          "   #M1\n" +
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   178
                          "}\n" +
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   179
                          "interface B extends A, Sup {\n" +
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   180
                          "   #M2\n" +
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   181
                          "}\n" +
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   182
                          "interface C extends B, Sup {\n" +
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   183
                          "   #M3\n" +
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   184
                          "}\n";
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   185
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   186
        String source;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   187
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   188
        public JavaSource() {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   189
            super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   190
            source = template.replaceAll("#M1", mk1.getBody(be1, sk1))
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   191
                    .replaceAll("#M2", mk2.getBody(be2, sk2))
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   192
                    .replaceAll("#M3", mk3.getBody(be3, sk3));
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   193
        }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   194
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   195
        @Override
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   196
        public CharSequence getCharContent(boolean ignoreEncodingErrors) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   197
            return source;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   198
        }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   199
    }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   200
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   201
    void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   202
        JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker,
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   203
                Arrays.asList("-XDallowStaticInterfaceMethods"), null, Arrays.asList(source));
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   204
        try {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   205
            ct.analyze();
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   206
        } catch (Throwable ex) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   207
            throw new AssertionError("Error thrown when analyzing the following source:\n" + source.getCharContent(true));
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   208
        }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   209
        check();
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   210
    }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   211
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   212
    void check() {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   213
        boolean errorExpected =
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   214
                !be1.allowed(mk1) || !be2.allowed(mk2) || !be3.allowed(mk3);
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   215
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   216
        if (mk1.inherithed()) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   217
            errorExpected |=
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   218
                    sk2.overrideEquivalentWith(sk1) && !MethodKind.overrides(mk2, sk2, mk1, sk1) ||
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   219
                    sk3.overrideEquivalentWith(sk1) && !MethodKind.overrides(mk3, sk3, mk1, sk1);
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   220
        }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   221
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   222
        if (mk2.inherithed()) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   223
            errorExpected |=
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   224
                    sk3.overrideEquivalentWith(sk2) && !MethodKind.overrides(mk3, sk3, mk2, sk2);
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   225
        }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   226
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   227
        checkCount++;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   228
        if (diagChecker.errorFound != errorExpected) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   229
            throw new AssertionError("Problem when compiling source:\n" + source.getCharContent(true) +
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   230
                    "\nfound error: " + diagChecker.errorFound);
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   231
        }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   232
    }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   233
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   234
    static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   235
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   236
        boolean errorFound;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   237
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   238
        public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   239
            if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   240
                errorFound = true;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   241
            }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   242
        }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   243
    }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents:
diff changeset
   244
}