langtools/test/tools/javac/importscope/TestLazyImportScope.java
author vasya
Mon, 14 Dec 2015 20:18:19 +0100
changeset 34752 9c262a013456
parent 30730 d3ce7619db2c
permissions -rw-r--r--
8145342: Some copyright notices are inconsistently and ill formatted Summary: Adjusted formatting of copyright notices. Reviewed-by: darcy, alundblad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27857
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
     1
/*
34752
9c262a013456 8145342: Some copyright notices are inconsistently and ill formatted
vasya
parents: 30730
diff changeset
     2
 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
27857
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
     4
 *
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
     8
 *
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    13
 * accompanied this code).
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    14
 *
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    18
 *
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    21
 * questions.
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    22
 */
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    23
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    24
/*
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    25
 * @test
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    26
 * @bug 7101822
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    27
 * @summary static import fails to resolve interfaces on nested enums via import statements
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27857
diff changeset
    28
 * @modules jdk.compiler
27857
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    29
 */
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    30
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    31
import com.sun.source.util.JavacTask;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    32
import java.net.URI;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    33
import java.util.Arrays;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    34
import javax.tools.Diagnostic;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    35
import javax.tools.JavaCompiler;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    36
import javax.tools.JavaFileObject;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    37
import javax.tools.SimpleJavaFileObject;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    38
import javax.tools.StandardJavaFileManager;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    39
import javax.tools.ToolProvider;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    40
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    41
public class TestLazyImportScope {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    42
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    43
    static int checkCount = 0;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    44
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    45
    enum ImportOrder {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    46
        NORMAL("import a.C.D;\n" +
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    47
               "#I"),
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    48
        REVERSE("#I\n" +
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    49
               "import a.C.D;");
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    50
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    51
        String importLayout;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    52
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    53
        ImportOrder(String importLayout) {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    54
            this.importLayout = importLayout;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    55
        }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    56
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    57
        String getImportString(ImportKind ik) {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    58
            return importLayout.replaceAll("#I", ik.importStr);
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    59
        }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    60
    }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    61
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    62
    enum ImportKind {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    63
        NAMED("import a.A.B.E;"),
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    64
        ON_DEMAND("import a.A.B.*;"),
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    65
        STATIC_NAMED_TYPE("import static a.A.B.E;"),
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    66
        STATIC_NAMED_MEMBER("import static a.A.B.bm;"),
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    67
        STATIC_ON_DEMAND("import static a.A.B.*;");
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    68
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    69
        String importStr;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    70
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    71
        private ImportKind(String importStr) {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    72
            this.importStr = importStr;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    73
        }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    74
    }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    75
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    76
    enum TypeRefKind {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    77
        NONE(""),
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    78
        E("E e = null;"),
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    79
        F("F f = null;"),
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    80
        BOTH("E e = null; F f = null;");
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    81
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    82
        String typeRefStr;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    83
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    84
        private TypeRefKind(String typeRefStr) {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    85
            this.typeRefStr = typeRefStr;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    86
        }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    87
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    88
        boolean isImported(ImportKind ik) {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    89
            switch (ik) {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    90
                case NAMED:
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    91
                case STATIC_NAMED_TYPE: return this == NONE || this == E;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    92
                case ON_DEMAND:
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    93
                case STATIC_ON_DEMAND: return true;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    94
                default: return this == NONE;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    95
            }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    96
        }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    97
    }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    98
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
    99
    enum MemberRefKind {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   100
        NONE(""),
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   101
        FIELD("Object o = bf;"),
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   102
        METHOD("bm();"),
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   103
        BOTH("Object o = bf; bm();");
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   104
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   105
        String memberRefStr;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   106
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   107
        private MemberRefKind(String memberRefStr) {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   108
            this.memberRefStr = memberRefStr;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   109
        }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   110
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   111
        boolean isImported(ImportKind ik) {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   112
            switch (ik) {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   113
                case STATIC_NAMED_MEMBER: return this == NONE || this == METHOD;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   114
                case STATIC_ON_DEMAND: return true;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   115
                default: return this == NONE;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   116
            }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   117
        }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   118
    }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   119
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   120
    public static void main(String... args) throws Exception {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   121
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   122
        //create default shared JavaCompiler - reused across multiple compilations
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   123
        JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   124
        StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   125
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   126
        for (ImportOrder ord : ImportOrder.values()) {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   127
            for (ImportKind ik : ImportKind.values()) {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   128
                for (TypeRefKind tk : TypeRefKind.values()) {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   129
                    for (MemberRefKind mk : MemberRefKind.values()) {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   130
                        new TestLazyImportScope(ord, ik, tk, mk).run(comp, fm);
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   131
                    }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   132
                }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   133
            }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   134
        }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   135
        System.out.println("Total check executed: " + checkCount);
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   136
    }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   137
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   138
    ImportOrder ord;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   139
    ImportKind ik;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   140
    TypeRefKind tk;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   141
    MemberRefKind mk;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   142
    JavaSource source;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   143
    DiagnosticChecker diagChecker;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   144
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   145
    TestLazyImportScope(ImportOrder ord, ImportKind ik, TypeRefKind tk, MemberRefKind mk) {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   146
        this.ord = ord;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   147
        this.ik = ik;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   148
        this.tk = tk;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   149
        this.mk = mk;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   150
        this.source = new JavaSource();
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   151
        this.diagChecker = new DiagnosticChecker();
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   152
    }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   153
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   154
    class JavaSource extends SimpleJavaFileObject {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   155
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   156
        String bodyTemplate = "package a;\n" +
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   157
                              "#I\n" +
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   158
                              "class A {\n" +
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   159
                              "   static class B extends D {\n" +
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   160
                              "      static class E { }\n" +
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   161
                              "      static class F { }\n" +
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   162
                              "      static Object bf;\n" +
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   163
                              "      static void bm() { }\n" +
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   164
                              "   }\n" +
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   165
                              "}\n" +
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   166
                              "class C {\n" +
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   167
                              "   static class D { }\n" +
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   168
                              "}\n" +
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   169
                              "class Test {\n" +
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   170
                              "   void test() {\n" +
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   171
                              "      #T\n" +
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   172
                              "      #M\n" +
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   173
                              "   }\n" +
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   174
                              "}";
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   175
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   176
        String source;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   177
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   178
        public JavaSource() {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   179
            super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   180
            source = bodyTemplate.replaceAll("#I", ord.getImportString(ik))
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   181
                    .replaceAll("#T", tk.typeRefStr)
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   182
                    .replaceAll("#M", mk.memberRefStr);
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   183
        }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   184
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   185
        @Override
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   186
        public CharSequence getCharContent(boolean ignoreEncodingErrors) {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   187
            return source;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   188
        }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   189
    }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   190
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   191
    void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   192
        JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker,
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   193
                null, null, Arrays.asList(source));
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   194
        try {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   195
            ct.analyze();
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   196
        } catch (Throwable ex) {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   197
            throw new AssertionError("Error thrown when compiling the following code:\n" + source.getCharContent(true));
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   198
        }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   199
        check();
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   200
    }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   201
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   202
    void check() {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   203
        checkCount++;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   204
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   205
        boolean errorExpected = !tk.isImported(ik) || !mk.isImported(ik);
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   206
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   207
        if (errorExpected != diagChecker.errorFound) {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   208
            throw new Error("invalid diagnostics for source:\n" +
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   209
                source.getCharContent(true) +
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   210
                "\nFound error: " + diagChecker.errorFound +
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   211
                "\nExpected error: " + errorExpected);
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   212
        }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   213
    }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   214
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   215
    static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   216
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   217
        boolean errorFound;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   218
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   219
        public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   220
            if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   221
                errorFound = true;
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   222
            }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   223
        }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   224
    }
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents:
diff changeset
   225
}