langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java
author chegar
Sun, 17 Aug 2014 15:52:32 +0100
changeset 25874 83c19f00452c
parent 25453 langtools/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java@be80cf0463b3
child 26264 a09fedde76be
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
23115
97722ad6c874 8030714: The steps attribute, flow and desugar are unnecessary for implicit classes when compiling with -implicit:none
alundblad
parents: 22165
diff changeset
     2
 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5007
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5007
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5007
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5007
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5007
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.main;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.io.*;
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
    29
import java.util.HashMap;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import java.util.HashSet;
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11867
diff changeset
    31
import java.util.LinkedHashMap;
1046
e395ce284cbf 6734819: Javac performs flows analysis on already translated classes
mcimadamore
parents: 936
diff changeset
    32
import java.util.LinkedHashSet;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import java.util.Map;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import java.util.MissingResourceException;
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
    35
import java.util.Queue;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
import java.util.ResourceBundle;
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import java.util.Set;
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
    39
import javax.annotation.processing.Processor;
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
    40
import javax.lang.model.SourceVersion;
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11867
diff changeset
    41
import javax.tools.DiagnosticListener;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
import javax.tools.JavaFileManager;
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
import javax.tools.JavaFileObject;
12213
516b112d6c68 7150368: javac should include basic ability to generate native headers
jjg
parents: 12016
diff changeset
    44
import javax.tools.StandardLocation;
516b112d6c68 7150368: javac should include basic ability to generate native headers
jjg
parents: 12016
diff changeset
    45
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11867
diff changeset
    46
import static javax.tools.StandardLocation.CLASS_OUTPUT;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
import com.sun.source.util.TaskEvent;
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11867
diff changeset
    49
import com.sun.tools.javac.api.MultiTaskListener;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
import com.sun.tools.javac.code.*;
7335
8b390fd27190 6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents: 7076
diff changeset
    51
import com.sun.tools.javac.code.Lint.LintCategory;
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
    52
import com.sun.tools.javac.code.Symbol.*;
11053
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
    53
import com.sun.tools.javac.comp.*;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17551
diff changeset
    54
import com.sun.tools.javac.comp.CompileStates.CompileState;
11053
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
    55
import com.sun.tools.javac.file.JavacFileManager;
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
    56
import com.sun.tools.javac.jvm.*;
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
    57
import com.sun.tools.javac.parser.*;
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
    58
import com.sun.tools.javac.processing.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
import com.sun.tools.javac.tree.*;
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
    60
import com.sun.tools.javac.tree.JCTree.*;
11053
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
    61
import com.sun.tools.javac.util.*;
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
    62
import com.sun.tools.javac.util.Log.WriterKind;
12213
516b112d6c68 7150368: javac should include basic ability to generate native headers
jjg
parents: 12016
diff changeset
    63
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
    64
import static com.sun.tools.javac.code.TypeTag.CLASS;
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 11053
diff changeset
    65
import static com.sun.tools.javac.main.Option.*;
6582
c7a4fb5a2f86 6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents: 6581
diff changeset
    66
import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
/** This class could be the main entry point for GJC when GJC is used as a
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
 *  component in a larger software system. It provides operations to
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
 *  construct a new compiler, and to run a new compiler on a set of source
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
 *  files.
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    74
 *  <p><b>This is NOT part of any supported API.
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    75
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
 */
19921
58bcbe156057 8023974: Drop 'implements Completer' and 'implements SourceCompleter' from ClassReader resp. JavaCompiler.
jfranck
parents: 19664
diff changeset
    79
public class JavaCompiler {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    /** The context key for the compiler. */
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
    81
    protected static final Context.Key<JavaCompiler> compilerKey = new Context.Key<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    /** Get the JavaCompiler instance for this context. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    public static JavaCompiler instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
        JavaCompiler instance = context.get(compilerKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
        if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
            instance = new JavaCompiler(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
    /** The current version number as a string.
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    public static String version() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
        return version("release");  // mm.nn.oo[-milestone]
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
    /** The current full version number as a string.
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
    public static String fullVersion() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
        return version("full"); // mm.mm.oo[-milestone]-build
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
    private static final String versionRBName = "com.sun.tools.javac.resources.version";
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
    private static ResourceBundle versionRB;
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    private static String version(String key) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
        if (versionRB == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
                versionRB = ResourceBundle.getBundle(versionRBName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
            } catch (MissingResourceException e) {
6031
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents: 5847
diff changeset
   111
                return Log.getLocalizedString("version.not.available");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
            return versionRB.getString(key);
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
        catch (MissingResourceException e) {
6031
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents: 5847
diff changeset
   118
            return Log.getLocalizedString("version.not.available");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
1355
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   122
    /**
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   123
     * Control how the compiler's latter phases (attr, flow, desugar, generate)
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   124
     * are connected. Each individual file is processed by each phase in turn,
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   125
     * but with different compile policies, you can control the order in which
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   126
     * each class is processed through its next phase.
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   127
     *
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   128
     * <p>Generally speaking, the compiler will "fail fast" in the face of
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   129
     * errors, although not aggressively so. flow, desugar, etc become no-ops
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   130
     * once any errors have occurred. No attempt is currently made to determine
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   131
     * if it might be safe to process a class through its next phase because
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   132
     * it does not depend on any unrelated errors that might have occurred.
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   133
     */
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   134
    protected static enum CompilePolicy {
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   135
        /**
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   136
         * Just attribute the parse trees.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
        ATTR_ONLY,
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
1355
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   140
        /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
         * Just attribute and do flow analysis on the parse trees.
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
         * This should catch most user errors.
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
        CHECK_ONLY,
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
1355
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   146
        /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
         * Attribute everything, then do flow analysis for everything,
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
         * then desugar everything, and only then generate output.
1355
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   149
         * This means no output will be generated if there are any
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   150
         * errors in any classes.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
        SIMPLE,
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
1355
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   154
        /**
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   155
         * Groups the classes for each source file together, then process
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   156
         * each group in a manner equivalent to the {@code SIMPLE} policy.
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   157
         * This means no output will be generated if there are any
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   158
         * errors in any of the classes in a source file.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
        BY_FILE,
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
1355
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   162
        /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
         * Completely process each entry on the todo list in turn.
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
         * -- this is the same for 1.5.
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
         * Means output might be generated for some classes in a compilation unit
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
         * and not others.
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
        BY_TODO;
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
        static CompilePolicy decode(String option) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
            if (option == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
                return DEFAULT_COMPILE_POLICY;
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
            else if (option.equals("attr"))
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
                return ATTR_ONLY;
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
            else if (option.equals("check"))
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
                return CHECK_ONLY;
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
            else if (option.equals("simple"))
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
                return SIMPLE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
            else if (option.equals("byfile"))
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
                return BY_FILE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
            else if (option.equals("bytodo"))
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
                return BY_TODO;
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
                return DEFAULT_COMPILE_POLICY;
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
14801
d66cab4ef397 8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents: 14548
diff changeset
   188
    private static final CompilePolicy DEFAULT_COMPILE_POLICY = CompilePolicy.BY_TODO;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
1355
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   190
    protected static enum ImplicitSourcePolicy {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
        /** Don't generate or process implicitly read source files. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
        NONE,
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
        /** Generate classes for implicitly read source files. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
        CLASS,
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
        /** Like CLASS, but generate warnings if annotation processing occurs */
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
        UNSET;
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
        static ImplicitSourcePolicy decode(String option) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
            if (option == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
                return UNSET;
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
            else if (option.equals("none"))
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
                return NONE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
            else if (option.equals("class"))
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
                return CLASS;
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
                return UNSET;
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
    /** The log to be used for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
    public Log log;
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
169
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
   214
    /** Factory for creating diagnostic objects
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
   215
     */
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
   216
    JCDiagnostic.Factory diagFactory;
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
   217
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
    /** The tree factory module.
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
    protected TreeMaker make;
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24392
diff changeset
   222
    /** The class finder.
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24392
diff changeset
   223
     */
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24392
diff changeset
   224
    protected ClassFinder finder;
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24392
diff changeset
   225
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
    /** The class reader.
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
    protected ClassReader reader;
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
    /** The class writer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
    protected ClassWriter writer;
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
12213
516b112d6c68 7150368: javac should include basic ability to generate native headers
jjg
parents: 12016
diff changeset
   234
    /** The native header writer.
516b112d6c68 7150368: javac should include basic ability to generate native headers
jjg
parents: 12016
diff changeset
   235
     */
516b112d6c68 7150368: javac should include basic ability to generate native headers
jjg
parents: 12016
diff changeset
   236
    protected JNIWriter jniWriter;
516b112d6c68 7150368: javac should include basic ability to generate native headers
jjg
parents: 12016
diff changeset
   237
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
    /** The module for the symbol table entry phases.
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
    protected Enter enter;
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
    /** The symbol table.
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
    protected Symtab syms;
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
    /** The language version.
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
    protected Source source;
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
    /** The module for code generation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
    protected Gen gen;
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
    /** The name table.
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
     */
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1258
diff changeset
   256
    protected Names names;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
    /** The attributor.
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
    protected Attr attr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
    /** The attributor.
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
    protected Check chk;
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
    /** The flow analyzer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
    protected Flow flow;
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
    /** The type eraser.
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
     */
1355
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   272
    protected TransTypes transTypes;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
    /** The syntactic sugar desweetener.
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
     */
1355
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   276
    protected Lower lower;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
    /** The annotation annotator.
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
    protected Annotate annotate;
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
    /** Force a completion failure on this name
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
    protected final Name completionFailureName;
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
    /** Type utilities.
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
    protected Types types;
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
    /** Access to file objects.
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
    protected JavaFileManager fileManager;
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
    /** Factory for parsers.
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
     */
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 1046
diff changeset
   296
    protected ParserFactory parserFactory;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11867
diff changeset
   298
    /** Broadcasting listener for progress events
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
     */
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11867
diff changeset
   300
    protected MultiTaskListener taskListener;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
    /**
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24392
diff changeset
   303
     * SourceCompleter that delegates to the readSourceFile method of this class.
19921
58bcbe156057 8023974: Drop 'implements Completer' and 'implements SourceCompleter' from ClassReader resp. JavaCompiler.
jfranck
parents: 19664
diff changeset
   304
     */
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24392
diff changeset
   305
    protected final Symbol.Completer sourceCompleter =
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24392
diff changeset
   306
            new Symbol.Completer() {
19921
58bcbe156057 8023974: Drop 'implements Completer' and 'implements SourceCompleter' from ClassReader resp. JavaCompiler.
jfranck
parents: 19664
diff changeset
   307
                @Override
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24392
diff changeset
   308
                public void complete(Symbol sym) throws CompletionFailure {
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24392
diff changeset
   309
                    readSourceFile((ClassSymbol) sym);
19921
58bcbe156057 8023974: Drop 'implements Completer' and 'implements SourceCompleter' from ClassReader resp. JavaCompiler.
jfranck
parents: 19664
diff changeset
   310
                }
58bcbe156057 8023974: Drop 'implements Completer' and 'implements SourceCompleter' from ClassReader resp. JavaCompiler.
jfranck
parents: 19664
diff changeset
   311
            };
58bcbe156057 8023974: Drop 'implements Completer' and 'implements SourceCompleter' from ClassReader resp. JavaCompiler.
jfranck
parents: 19664
diff changeset
   312
58bcbe156057 8023974: Drop 'implements Completer' and 'implements SourceCompleter' from ClassReader resp. JavaCompiler.
jfranck
parents: 19664
diff changeset
   313
    /**
8618
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents: 8614
diff changeset
   314
     * Command line options.
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents: 8614
diff changeset
   315
     */
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents: 8614
diff changeset
   316
    protected Options options;
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents: 8614
diff changeset
   317
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents: 8614
diff changeset
   318
    protected Context context;
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents: 8614
diff changeset
   319
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents: 8614
diff changeset
   320
    /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
     * Flag set if any annotation processing occurred.
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
     **/
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
    protected boolean annotationProcessingOccurred;
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
     * Flag set if any implicit source files read.
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
     **/
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
    protected boolean implicitSourceFilesRead;
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
16968
19f0da2d3143 8010659: Javac Crashes while building OpenJFX
vromero
parents: 15562
diff changeset
   330
    protected CompileStates compileStates;
19f0da2d3143 8010659: Javac Crashes while building OpenJFX
vromero
parents: 15562
diff changeset
   331
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
    /** Construct a new compiler using a shared context.
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
     */
8614
06e42328ddab 7021650: fix Context issues
jjg
parents: 8032
diff changeset
   334
    public JavaCompiler(Context context) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
        this.context = context;
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
        context.put(compilerKey, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
        // if fileManager not already set, register the JavacFileManager to be used
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
        if (context.get(JavaFileManager.class) == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
            JavacFileManager.preRegister(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1258
diff changeset
   342
        names = Names.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
        log = Log.instance(context);
169
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
   344
        diagFactory = JCDiagnostic.Factory.instance(context);
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24392
diff changeset
   345
        finder = ClassFinder.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
        reader = ClassReader.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
        make = TreeMaker.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
        writer = ClassWriter.instance(context);
12213
516b112d6c68 7150368: javac should include basic ability to generate native headers
jjg
parents: 12016
diff changeset
   349
        jniWriter = JNIWriter.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
        enter = Enter.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
        todo = Todo.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
        fileManager = context.get(JavaFileManager.class);
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 1046
diff changeset
   354
        parserFactory = ParserFactory.instance(context);
16968
19f0da2d3143 8010659: Javac Crashes while building OpenJFX
vromero
parents: 15562
diff changeset
   355
        compileStates = CompileStates.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
            // catch completion problems with predefineds
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
            syms = Symtab.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
        } catch (CompletionFailure ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
            // inlined Check.completionError as it is not initialized yet
169
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
   362
            log.error("cant.access", ex.sym, ex.getDetailValue());
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24392
diff changeset
   363
            if (ex instanceof ClassFinder.BadClassFile)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
                throw new Abort();
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
        source = Source.instance(context);
19508
e2cd0ed6c9b0 8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents: 18394
diff changeset
   367
        Target target = Target.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
        attr = Attr.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
        chk = Check.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
        gen = Gen.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
        flow = Flow.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
        transTypes = TransTypes.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
        lower = Lower.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
        annotate = Annotate.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
        types = Types.instance(context);
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11867
diff changeset
   376
        taskListener = MultiTaskListener.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24392
diff changeset
   378
        finder.sourceCompleter = sourceCompleter;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
8618
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents: 8614
diff changeset
   380
        options = Options.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
   382
        verbose       = options.isSet(VERBOSE);
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
   383
        sourceOutput  = options.isSet(PRINTSOURCE); // used to be -s
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
   384
        stubOutput    = options.isSet("-stubs");
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
   385
        relax         = options.isSet("-relax");
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
   386
        printFlat     = options.isSet("-printflat");
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
   387
        attrParseOnly = options.isSet("-attrparseonly");
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
   388
        encoding      = options.get(ENCODING);
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
   389
        lineDebugInfo = options.isUnset(G_CUSTOM) ||
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
   390
                        options.isSet(G_CUSTOM, "lines");
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
   391
        genEndPos     = options.isSet(XJCOV) ||
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
                        context.get(DiagnosticListener.class) != null;
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
   393
        devVerbose    = options.isSet("dev");
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
   394
        processPcks   = options.isSet("process.packages");
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
   395
        werror        = options.isSet(WERROR);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 24604
diff changeset
   397
        // Should this be with other option checking, in Main
7335
8b390fd27190 6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents: 7076
diff changeset
   398
        if (source.compareTo(Source.DEFAULT) < 0) {
8b390fd27190 6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents: 7076
diff changeset
   399
            if (options.isUnset(XLINT_CUSTOM, "-" + LintCategory.OPTIONS.option)) {
8b390fd27190 6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents: 7076
diff changeset
   400
                if (fileManager instanceof BaseFileManager) {
8b390fd27190 6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents: 7076
diff changeset
   401
                    if (((BaseFileManager) fileManager).isDefaultBootClassPath())
8b390fd27190 6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents: 7076
diff changeset
   402
                        log.warning(LintCategory.OPTIONS, "source.no.bootclasspath", source.name);
8b390fd27190 6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents: 7076
diff changeset
   403
                }
8b390fd27190 6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents: 7076
diff changeset
   404
            }
8b390fd27190 6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents: 7076
diff changeset
   405
        }
8b390fd27190 6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents: 7076
diff changeset
   406
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 24604
diff changeset
   407
        // Should this be with other option checking, in Main
19508
e2cd0ed6c9b0 8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents: 18394
diff changeset
   408
        checkForObsoleteOptions(target);
e2cd0ed6c9b0 8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents: 18394
diff changeset
   409
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
   410
        verboseCompilePolicy = options.isSet("verboseCompilePolicy");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
        if (attrParseOnly)
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
            compilePolicy = CompilePolicy.ATTR_ONLY;
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
            compilePolicy = CompilePolicy.decode(options.get("compilePolicy"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
        implicitSourcePolicy = ImplicitSourcePolicy.decode(options.get("-implicit"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
        completionFailureName =
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
   420
            options.isSet("failcomplete")
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
            ? names.fromString(options.get("failcomplete"))
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
            : null;
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
   423
14050
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   424
        shouldStopPolicyIfError =
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   425
            options.isSet("shouldStopPolicy") // backwards compatible
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
   426
            ? CompileState.valueOf(options.get("shouldStopPolicy"))
14050
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   427
            : options.isSet("shouldStopPolicyIfError")
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   428
            ? CompileState.valueOf(options.get("shouldStopPolicyIfError"))
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   429
            : CompileState.INIT;
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   430
        shouldStopPolicyIfNoError =
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   431
            options.isSet("shouldStopPolicyIfNoError")
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   432
            ? CompileState.valueOf(options.get("shouldStopPolicyIfNoError"))
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   433
            : CompileState.GENERATE;
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   434
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
   435
        if (options.isUnset("oldDiags"))
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2514
diff changeset
   436
            log.setDiagnosticFormatter(RichDiagnosticFormatter.instance(context));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 24604
diff changeset
   439
    // Should this be with other option checking, in Main
19508
e2cd0ed6c9b0 8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents: 18394
diff changeset
   440
    private void checkForObsoleteOptions(Target target) {
e2cd0ed6c9b0 8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents: 18394
diff changeset
   441
        // Unless lint checking on options is disabled, check for
e2cd0ed6c9b0 8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents: 18394
diff changeset
   442
        // obsolete source and target options.
e2cd0ed6c9b0 8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents: 18394
diff changeset
   443
        boolean obsoleteOptionFound = false;
25445
603f0c93d5c9 8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents: 24898
diff changeset
   444
603f0c93d5c9 8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents: 24898
diff changeset
   445
        boolean lintOptions =
603f0c93d5c9 8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents: 24898
diff changeset
   446
            options.isUnset(XLINT_CUSTOM, "-"+LintCategory.OPTIONS.option);
19508
e2cd0ed6c9b0 8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents: 18394
diff changeset
   447
25453
be80cf0463b3 8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents: 25445
diff changeset
   448
        if (source.compareTo(Source.MIN) < 0) {
be80cf0463b3 8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents: 25445
diff changeset
   449
            log.error("option.removed.source", source.name, Source.MIN.name);
be80cf0463b3 8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents: 25445
diff changeset
   450
        } else if (source == Source.MIN && lintOptions) {
be80cf0463b3 8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents: 25445
diff changeset
   451
            log.warning(LintCategory.OPTIONS, "option.obsolete.source", source.name);
be80cf0463b3 8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents: 25445
diff changeset
   452
            obsoleteOptionFound = true;
25445
603f0c93d5c9 8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents: 24898
diff changeset
   453
        }
19508
e2cd0ed6c9b0 8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents: 18394
diff changeset
   454
25453
be80cf0463b3 8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents: 25445
diff changeset
   455
        if (target.compareTo(Target.MIN) < 0) {
be80cf0463b3 8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents: 25445
diff changeset
   456
            log.error("option.removed.target", target.name, Target.MIN.name);
be80cf0463b3 8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents: 25445
diff changeset
   457
        } else if (target == Target.MIN && lintOptions) {
be80cf0463b3 8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents: 25445
diff changeset
   458
            log.warning(LintCategory.OPTIONS, "option.obsolete.target", target.name);
be80cf0463b3 8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents: 25445
diff changeset
   459
            obsoleteOptionFound = true;
be80cf0463b3 8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents: 25445
diff changeset
   460
        }
be80cf0463b3 8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents: 25445
diff changeset
   461
be80cf0463b3 8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents: 25445
diff changeset
   462
        if (obsoleteOptionFound)
be80cf0463b3 8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents: 25445
diff changeset
   463
            log.warning(LintCategory.OPTIONS, "option.obsolete.suppression");
19508
e2cd0ed6c9b0 8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents: 18394
diff changeset
   464
    }
e2cd0ed6c9b0 8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents: 18394
diff changeset
   465
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
    /* Switches:
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
    /** Verbose output.
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
    public boolean verbose;
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
    /** Emit plain Java source files rather than class files.
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
    public boolean sourceOutput;
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
    /** Emit stub source files rather than class files.
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
    public boolean stubOutput;
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
    /** Generate attributed parse tree only.
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
    public boolean attrParseOnly;
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
    /** Switch: relax some constraints for producing the jsr14 prototype.
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
    boolean relax;
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
    /** Debug switch: Emit Java sources after inner class flattening.
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
    public boolean printFlat;
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
    /** The encoding to be used for source input.
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
    public String encoding;
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
    /** Generate code with the LineNumberTable attribute for debugging
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
    public boolean lineDebugInfo;
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
    /** Switch: should we store the ending positions?
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
    public boolean genEndPos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
    /** Switch: should we debug ignored exceptions
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
    protected boolean devVerbose;
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
    /** Switch: should we (annotation) process packages as well
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
    protected boolean processPcks;
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
1996
c855318a4b03 6595666: fix -Werror
jjg
parents: 1870
diff changeset
   513
    /** Switch: treat warnings as errors
c855318a4b03 6595666: fix -Werror
jjg
parents: 1870
diff changeset
   514
     */
c855318a4b03 6595666: fix -Werror
jjg
parents: 1870
diff changeset
   515
    protected boolean werror;
c855318a4b03 6595666: fix -Werror
jjg
parents: 1870
diff changeset
   516
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17551
diff changeset
   517
    /** Switch: is annotation processing requested explicitly via
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
     * CompilationTask.setProcessors?
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
    protected boolean explicitAnnotationProcessingRequested = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
     * The policy for the order in which to perform the compilation
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
    protected CompilePolicy compilePolicy;
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
     * The policy for what to do with implicitly read source files
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
    protected ImplicitSourcePolicy implicitSourcePolicy;
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
     * Report activity related to compilePolicy
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
    public boolean verboseCompilePolicy;
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
   537
    /**
14050
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   538
     * Policy of how far to continue compilation after errors have occurred.
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   539
     * Set this to minimum CompileState (INIT) to stop as soon as possible
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   540
     * after errors.
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
   541
     */
14050
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   542
    public CompileState shouldStopPolicyIfError;
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
   543
14050
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   544
    /**
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   545
     * Policy of how far to continue compilation when no errors have occurred.
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   546
     * Set this to maximum CompileState (GENERATE) to perform full compilation.
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   547
     * Set this lower to perform partial compilation, such as -proc:only.
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   548
     */
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   549
    public CompileState shouldStopPolicyIfNoError;
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   550
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14957
diff changeset
   551
    /** A queue of all as yet unattributed classes.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
    public Todo todo;
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
10637
2ea5fbb913ac 7092965: javac should not close processorClassLoader before end of compilation
jjg
parents: 8851
diff changeset
   555
    /** A list of items to be closed when the compilation is complete.
2ea5fbb913ac 7092965: javac should not close processorClassLoader before end of compilation
jjg
parents: 8851
diff changeset
   556
     */
2ea5fbb913ac 7092965: javac should not close processorClassLoader before end of compilation
jjg
parents: 8851
diff changeset
   557
    public List<Closeable> closeables = List.nil();
2ea5fbb913ac 7092965: javac should not close processorClassLoader before end of compilation
jjg
parents: 8851
diff changeset
   558
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
    /** The set of currently compiled inputfiles, needed to ensure
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
     *  we don't accidentally overwrite an input file when -s is set.
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
     *  initialized by `compile'.
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
     */
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   563
    protected Set<JavaFileObject> inputFiles = new HashSet<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
   565
    protected boolean shouldStop(CompileState cs) {
14050
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   566
        CompileState shouldStopPolicy = (errorCount() > 0 || unrecoverableError())
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   567
            ? shouldStopPolicyIfError
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   568
            : shouldStopPolicyIfNoError;
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   569
        return cs.isAfter(shouldStopPolicy);
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
   570
    }
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
   571
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   572
    /** The number of errors reported so far.
06bc494ca11e Initial load
duke
parents:
diff changeset
   573
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
    public int errorCount() {
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   575
        if (werror && log.nerrors == 0 && log.nwarnings > 0) {
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   576
            log.error("warnings.and.werror");
1996
c855318a4b03 6595666: fix -Werror
jjg
parents: 1870
diff changeset
   577
        }
6355
f01ebbf5a5f7 6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents: 6156
diff changeset
   578
        return log.nerrors;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
   581
    protected final <T> Queue<T> stopIfError(CompileState cs, Queue<T> queue) {
22165
ec53c8946fc2 8030807: langtools should still build using jdk 7
vromero
parents: 22163
diff changeset
   582
        return shouldStop(cs) ? new ListBuffer<T>() : queue;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
   585
    protected final <T> List<T> stopIfError(CompileState cs, List<T> list) {
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
   586
        return shouldStop(cs) ? List.<T>nil() : list;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
    /** The number of warnings reported so far.
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
    public int warningCount() {
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   592
        return log.nwarnings;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
    /** Try to open input stream with given name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
     *  Report an error if this fails.
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
     *  @param filename   The file name of the input stream to be opened.
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
    public CharSequence readSource(JavaFileObject filename) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
            inputFiles.add(filename);
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
            return filename.getCharContent(false);
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
        } catch (IOException e) {
5007
28dee2489196 6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents: 5004
diff changeset
   604
            log.error("error.reading.file", filename, JavacFileManager.getMessage(e));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
06bc494ca11e Initial load
duke
parents:
diff changeset
   609
    /** Parse contents of input stream.
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
     *  @param filename     The name of the file from which input stream comes.
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14058
diff changeset
   611
     *  @param content      The characters to be parsed.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
    protected JCCompilationUnit parse(JavaFileObject filename, CharSequence content) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
        long msec = now();
24069
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 23810
diff changeset
   615
        JCCompilationUnit tree = make.TopLevel(List.<JCTree>nil());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
        if (content != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   617
            if (verbose) {
8630
cd9eefe597f6 6966736: javac verbose output is inconsistent
jjg
parents: 8624
diff changeset
   618
                log.printVerbose("parsing.started", filename);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   619
            }
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11867
diff changeset
   620
            if (!taskListener.isEmpty()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
                TaskEvent e = new TaskEvent(TaskEvent.Kind.PARSE, filename);
06bc494ca11e Initial load
duke
parents:
diff changeset
   622
                taskListener.started(e);
15562
e05336e44a9e 8007344: javac may not make tree end positions and/or doc comments available to processors and listeners
jjg
parents: 15385
diff changeset
   623
                keepComments = true;
e05336e44a9e 8007344: javac may not make tree end positions and/or doc comments available to processors and listeners
jjg
parents: 15385
diff changeset
   624
                genEndPos = true;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   625
            }
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 1046
diff changeset
   626
            Parser parser = parserFactory.newParser(content, keepComments(), genEndPos, lineDebugInfo);
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 1046
diff changeset
   627
            tree = parser.parseCompilationUnit();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
            if (verbose) {
8630
cd9eefe597f6 6966736: javac verbose output is inconsistent
jjg
parents: 8624
diff changeset
   629
                log.printVerbose("parsing.done", Long.toString(elapsed(msec)));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   630
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   631
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
06bc494ca11e Initial load
duke
parents:
diff changeset
   633
        tree.sourcefile = filename;
06bc494ca11e Initial load
duke
parents:
diff changeset
   634
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11867
diff changeset
   635
        if (content != null && !taskListener.isEmpty()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   636
            TaskEvent e = new TaskEvent(TaskEvent.Kind.PARSE, tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   637
            taskListener.finished(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   638
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   639
06bc494ca11e Initial load
duke
parents:
diff changeset
   640
        return tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
   641
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
    // where
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
        public boolean keepComments = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
        protected boolean keepComments() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
            return keepComments || sourceOutput || stubOutput;
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   647
06bc494ca11e Initial load
duke
parents:
diff changeset
   648
06bc494ca11e Initial load
duke
parents:
diff changeset
   649
    /** Parse contents of file.
06bc494ca11e Initial load
duke
parents:
diff changeset
   650
     *  @param filename     The name of the file to be parsed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   651
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   652
    @Deprecated
6581
f58f0ce45802 6980707: Reduce use of IOException in JavaCompiler
jjg
parents: 6572
diff changeset
   653
    public JCTree.JCCompilationUnit parse(String filename) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   654
        JavacFileManager fm = (JavacFileManager)fileManager;
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
        return parse(fm.getJavaFileObjectsFromStrings(List.of(filename)).iterator().next());
06bc494ca11e Initial load
duke
parents:
diff changeset
   656
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   657
06bc494ca11e Initial load
duke
parents:
diff changeset
   658
    /** Parse contents of file.
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
     *  @param filename     The name of the file to be parsed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   660
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
    public JCTree.JCCompilationUnit parse(JavaFileObject filename) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   662
        JavaFileObject prev = log.useSource(filename);
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
            JCTree.JCCompilationUnit t = parse(filename, readSource(filename));
06bc494ca11e Initial load
duke
parents:
diff changeset
   665
            if (t.endPositions != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   666
                log.setEndPosTable(filename, t.endPositions);
06bc494ca11e Initial load
duke
parents:
diff changeset
   667
            return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
   668
        } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   669
            log.useSource(prev);
06bc494ca11e Initial load
duke
parents:
diff changeset
   670
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   672
8851
e630c590eb10 6930508: Passing nested class names on javac command line interfere with subsequent name -> class lookup
jjg
parents: 8845
diff changeset
   673
    /** Resolve an identifier which may be the binary name of a class or
e630c590eb10 6930508: Passing nested class names on javac command line interfere with subsequent name -> class lookup
jjg
parents: 8845
diff changeset
   674
     * the Java name of a class or package.
e630c590eb10 6930508: Passing nested class names on javac command line interfere with subsequent name -> class lookup
jjg
parents: 8845
diff changeset
   675
     * @param name      The name to resolve
e630c590eb10 6930508: Passing nested class names on javac command line interfere with subsequent name -> class lookup
jjg
parents: 8845
diff changeset
   676
     */
e630c590eb10 6930508: Passing nested class names on javac command line interfere with subsequent name -> class lookup
jjg
parents: 8845
diff changeset
   677
    public Symbol resolveBinaryNameOrIdent(String name) {
e630c590eb10 6930508: Passing nested class names on javac command line interfere with subsequent name -> class lookup
jjg
parents: 8845
diff changeset
   678
        try {
e630c590eb10 6930508: Passing nested class names on javac command line interfere with subsequent name -> class lookup
jjg
parents: 8845
diff changeset
   679
            Name flatname = names.fromString(name.replace("/", "."));
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24392
diff changeset
   680
            return finder.loadClass(flatname);
8851
e630c590eb10 6930508: Passing nested class names on javac command line interfere with subsequent name -> class lookup
jjg
parents: 8845
diff changeset
   681
        } catch (CompletionFailure ignore) {
e630c590eb10 6930508: Passing nested class names on javac command line interfere with subsequent name -> class lookup
jjg
parents: 8845
diff changeset
   682
            return resolveIdent(name);
e630c590eb10 6930508: Passing nested class names on javac command line interfere with subsequent name -> class lookup
jjg
parents: 8845
diff changeset
   683
        }
e630c590eb10 6930508: Passing nested class names on javac command line interfere with subsequent name -> class lookup
jjg
parents: 8845
diff changeset
   684
    }
e630c590eb10 6930508: Passing nested class names on javac command line interfere with subsequent name -> class lookup
jjg
parents: 8845
diff changeset
   685
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   686
    /** Resolve an identifier.
06bc494ca11e Initial load
duke
parents:
diff changeset
   687
     * @param name      The identifier to resolve
06bc494ca11e Initial load
duke
parents:
diff changeset
   688
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   689
    public Symbol resolveIdent(String name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   690
        if (name.equals(""))
06bc494ca11e Initial load
duke
parents:
diff changeset
   691
            return syms.errSymbol;
06bc494ca11e Initial load
duke
parents:
diff changeset
   692
        JavaFileObject prev = log.useSource(null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   693
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   694
            JCExpression tree = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   695
            for (String s : name.split("\\.", -1)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   696
                if (!SourceVersion.isIdentifier(s)) // TODO: check for keywords
06bc494ca11e Initial load
duke
parents:
diff changeset
   697
                    return syms.errSymbol;
06bc494ca11e Initial load
duke
parents:
diff changeset
   698
                tree = (tree == null) ? make.Ident(names.fromString(s))
06bc494ca11e Initial load
duke
parents:
diff changeset
   699
                                      : make.Select(tree, names.fromString(s));
06bc494ca11e Initial load
duke
parents:
diff changeset
   700
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   701
            JCCompilationUnit toplevel =
24069
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 23810
diff changeset
   702
                make.TopLevel(List.<JCTree>nil());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   703
            toplevel.packge = syms.unnamedPackage;
06bc494ca11e Initial load
duke
parents:
diff changeset
   704
            return attr.attribIdent(tree, toplevel);
06bc494ca11e Initial load
duke
parents:
diff changeset
   705
        } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   706
            log.useSource(prev);
06bc494ca11e Initial load
duke
parents:
diff changeset
   707
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   708
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   709
06bc494ca11e Initial load
duke
parents:
diff changeset
   710
    /** Emit plain Java source for a class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   711
     *  @param env    The attribution environment of the outermost class
06bc494ca11e Initial load
duke
parents:
diff changeset
   712
     *                containing this class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   713
     *  @param cdef   The class definition to be printed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   714
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   715
    JavaFileObject printSource(Env<AttrContext> env, JCClassDecl cdef) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   716
        JavaFileObject outFile
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
            = fileManager.getJavaFileForOutput(CLASS_OUTPUT,
06bc494ca11e Initial load
duke
parents:
diff changeset
   718
                                               cdef.sym.flatname.toString(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   719
                                               JavaFileObject.Kind.SOURCE,
06bc494ca11e Initial load
duke
parents:
diff changeset
   720
                                               null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   721
        if (inputFiles.contains(outFile)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   722
            log.error(cdef.pos(), "source.cant.overwrite.input.file", outFile);
06bc494ca11e Initial load
duke
parents:
diff changeset
   723
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   724
        } else {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 21497
diff changeset
   725
            try (BufferedWriter out = new BufferedWriter(outFile.openWriter())) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   726
                new Pretty(out, true).printUnit(env.toplevel, cdef);
06bc494ca11e Initial load
duke
parents:
diff changeset
   727
                if (verbose)
8630
cd9eefe597f6 6966736: javac verbose output is inconsistent
jjg
parents: 8624
diff changeset
   728
                    log.printVerbose("wrote.file", outFile);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   729
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   730
            return outFile;
20617
00537d91b0cd 8025970: Spurious characters in JavaCompiler
jjg
parents: 20616
diff changeset
   731
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   732
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   733
06bc494ca11e Initial load
duke
parents:
diff changeset
   734
    /** Generate code and emit a class file for a given class
06bc494ca11e Initial load
duke
parents:
diff changeset
   735
     *  @param env    The attribution environment of the outermost class
06bc494ca11e Initial load
duke
parents:
diff changeset
   736
     *                containing this class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   737
     *  @param cdef   The class definition from which code is generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
   738
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   739
    JavaFileObject genCode(Env<AttrContext> env, JCClassDecl cdef) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   740
        try {
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
   741
            if (gen.genClass(env, cdef) && (errorCount() == 0))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   742
                return writer.writeClass(cdef.sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   743
        } catch (ClassWriter.PoolOverflow ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   744
            log.error(cdef.pos(), "limit.pool");
06bc494ca11e Initial load
duke
parents:
diff changeset
   745
        } catch (ClassWriter.StringOverflow ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   746
            log.error(cdef.pos(), "limit.string.overflow",
06bc494ca11e Initial load
duke
parents:
diff changeset
   747
                      ex.value.substring(0, 20));
06bc494ca11e Initial load
duke
parents:
diff changeset
   748
        } catch (CompletionFailure ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   749
            chk.completionError(cdef.pos(), ex);
06bc494ca11e Initial load
duke
parents:
diff changeset
   750
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   751
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   752
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   753
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24392
diff changeset
   754
    /** Compile a source file that has been accessed by the class finder.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   755
     *  @param c          The class the source file of which needs to be compiled.
06bc494ca11e Initial load
duke
parents:
diff changeset
   756
     */
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24392
diff changeset
   757
    private void readSourceFile(ClassSymbol c) throws CompletionFailure {
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24392
diff changeset
   758
        readSourceFile(null, c);
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   759
    }
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   760
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24392
diff changeset
   761
    /** Compile a ClassSymbol from source, optionally using the given compilation unit as
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   762
     *  the source tree.
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24392
diff changeset
   763
     *  @param tree the compilation unit in which the given ClassSymbol resides,
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   764
     *              or null if should be parsed from source
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   765
     *  @param c    the ClassSymbol to complete
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   766
     */
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24392
diff changeset
   767
    public void readSourceFile(JCCompilationUnit tree, ClassSymbol c) throws CompletionFailure {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   768
        if (completionFailureName == c.fullname) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   769
            throw new CompletionFailure(c, "user-selected completion failure by class name");
06bc494ca11e Initial load
duke
parents:
diff changeset
   770
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   771
        JavaFileObject filename = c.classfile;
06bc494ca11e Initial load
duke
parents:
diff changeset
   772
        JavaFileObject prev = log.useSource(filename);
06bc494ca11e Initial load
duke
parents:
diff changeset
   773
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   774
        if (tree == null) {
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   775
            try {
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   776
                tree = parse(filename, filename.getCharContent(false));
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   777
            } catch (IOException e) {
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   778
                log.error("error.reading.file", filename, JavacFileManager.getMessage(e));
24069
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 23810
diff changeset
   779
                tree = make.TopLevel(List.<JCTree>nil());
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   780
            } finally {
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   781
                log.useSource(prev);
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   782
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   783
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   784
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11867
diff changeset
   785
        if (!taskListener.isEmpty()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   786
            TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   787
            taskListener.started(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   788
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   789
06bc494ca11e Initial load
duke
parents:
diff changeset
   790
        enter.complete(List.of(tree), c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   791
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11867
diff changeset
   792
        if (!taskListener.isEmpty()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   793
            TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   794
            taskListener.finished(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   795
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   796
06bc494ca11e Initial load
duke
parents:
diff changeset
   797
        if (enter.getEnv(c) == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   798
            boolean isPkgInfo =
06bc494ca11e Initial load
duke
parents:
diff changeset
   799
                tree.sourcefile.isNameCompatible("package-info",
06bc494ca11e Initial load
duke
parents:
diff changeset
   800
                                                 JavaFileObject.Kind.SOURCE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   801
            if (isPkgInfo) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   802
                if (enter.getEnv(tree.packge) == null) {
169
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
   803
                    JCDiagnostic diag =
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
   804
                        diagFactory.fragment("file.does.not.contain.package",
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   805
                                                 c.location());
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24392
diff changeset
   806
                    throw new ClassFinder.BadClassFile(c, filename, diag, diagFactory);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   807
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   808
            } else {
169
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
   809
                JCDiagnostic diag =
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
   810
                        diagFactory.fragment("file.doesnt.contain.class",
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
   811
                                            c.getQualifiedName());
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24392
diff changeset
   812
                throw new ClassFinder.BadClassFile(c, filename, diag, diagFactory);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   813
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   814
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   815
06bc494ca11e Initial load
duke
parents:
diff changeset
   816
        implicitSourceFilesRead = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   817
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   818
06bc494ca11e Initial load
duke
parents:
diff changeset
   819
    /** Track when the JavaCompiler has been used to compile something. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   820
    private boolean hasBeenUsed = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   821
    private long start_msec = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   822
    public long elapsed_msec = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   823
06bc494ca11e Initial load
duke
parents:
diff changeset
   824
    public void compile(List<JavaFileObject> sourceFileObject)
06bc494ca11e Initial load
duke
parents:
diff changeset
   825
        throws Throwable {
06bc494ca11e Initial load
duke
parents:
diff changeset
   826
        compile(sourceFileObject, List.<String>nil(), null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   827
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   828
06bc494ca11e Initial load
duke
parents:
diff changeset
   829
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   830
     * Main method: compile a list of files, return all compiled classes
06bc494ca11e Initial load
duke
parents:
diff changeset
   831
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   832
     * @param sourceFileObjects file objects to be compiled
06bc494ca11e Initial load
duke
parents:
diff changeset
   833
     * @param classnames class names to process for annotations
06bc494ca11e Initial load
duke
parents:
diff changeset
   834
     * @param processors user provided annotation processors to bypass
06bc494ca11e Initial load
duke
parents:
diff changeset
   835
     * discovery, {@code null} means that no processors were provided
06bc494ca11e Initial load
duke
parents:
diff changeset
   836
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   837
    public void compile(List<JavaFileObject> sourceFileObjects,
06bc494ca11e Initial load
duke
parents:
diff changeset
   838
                        List<String> classnames,
06bc494ca11e Initial load
duke
parents:
diff changeset
   839
                        Iterable<? extends Processor> processors)
06bc494ca11e Initial load
duke
parents:
diff changeset
   840
    {
24898
88fa65d2ac87 8033414: javac Plugin to receive notification (before and) after the compilation.
jlahoda
parents: 24897
diff changeset
   841
        if (!taskListener.isEmpty()) {
88fa65d2ac87 8033414: javac Plugin to receive notification (before and) after the compilation.
jlahoda
parents: 24897
diff changeset
   842
            taskListener.started(new TaskEvent(TaskEvent.Kind.COMPILATION));
88fa65d2ac87 8033414: javac Plugin to receive notification (before and) after the compilation.
jlahoda
parents: 24897
diff changeset
   843
        }
88fa65d2ac87 8033414: javac Plugin to receive notification (before and) after the compilation.
jlahoda
parents: 24897
diff changeset
   844
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   845
        if (processors != null && processors.iterator().hasNext())
06bc494ca11e Initial load
duke
parents:
diff changeset
   846
            explicitAnnotationProcessingRequested = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   847
        // as a JavaCompiler can only be used once, throw an exception if
06bc494ca11e Initial load
duke
parents:
diff changeset
   848
        // it has been used before.
06bc494ca11e Initial load
duke
parents:
diff changeset
   849
        if (hasBeenUsed)
06bc494ca11e Initial load
duke
parents:
diff changeset
   850
            throw new AssertionError("attempt to reuse JavaCompiler");
06bc494ca11e Initial load
duke
parents:
diff changeset
   851
        hasBeenUsed = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   852
8618
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents: 8614
diff changeset
   853
        // forcibly set the equivalent of -Xlint:-options, so that no further
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents: 8614
diff changeset
   854
        // warnings about command line options are generated from this point on
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 11053
diff changeset
   855
        options.put(XLINT_CUSTOM.text + "-" + LintCategory.OPTIONS.option, "true");
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 11053
diff changeset
   856
        options.remove(XLINT_CUSTOM.text + LintCategory.OPTIONS.option);
8618
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents: 8614
diff changeset
   857
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   858
        start_msec = now();
7335
8b390fd27190 6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents: 7076
diff changeset
   859
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   860
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   861
            initProcessAnnotations(processors);
06bc494ca11e Initial load
duke
parents:
diff changeset
   862
06bc494ca11e Initial load
duke
parents:
diff changeset
   863
            // These method calls must be chained to avoid memory leaks
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   864
            processAnnotations(
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   865
                enterTrees(stopIfError(CompileState.PARSE, parseFiles(sourceFileObjects))),
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   866
                classnames);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   867
23115
97722ad6c874 8030714: The steps attribute, flow and desugar are unnecessary for implicit classes when compiling with -implicit:none
alundblad
parents: 22165
diff changeset
   868
            // If it's safe to do so, skip attr / flow / gen for implicit classes
97722ad6c874 8030714: The steps attribute, flow and desugar are unnecessary for implicit classes when compiling with -implicit:none
alundblad
parents: 22165
diff changeset
   869
            if (taskListener.isEmpty() &&
97722ad6c874 8030714: The steps attribute, flow and desugar are unnecessary for implicit classes when compiling with -implicit:none
alundblad
parents: 22165
diff changeset
   870
                    implicitSourcePolicy == ImplicitSourcePolicy.NONE) {
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   871
                todo.retainFiles(inputFiles);
23115
97722ad6c874 8030714: The steps attribute, flow and desugar are unnecessary for implicit classes when compiling with -implicit:none
alundblad
parents: 22165
diff changeset
   872
            }
97722ad6c874 8030714: The steps attribute, flow and desugar are unnecessary for implicit classes when compiling with -implicit:none
alundblad
parents: 22165
diff changeset
   873
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   874
            switch (compilePolicy) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   875
            case ATTR_ONLY:
06bc494ca11e Initial load
duke
parents:
diff changeset
   876
                attribute(todo);
06bc494ca11e Initial load
duke
parents:
diff changeset
   877
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   878
06bc494ca11e Initial load
duke
parents:
diff changeset
   879
            case CHECK_ONLY:
06bc494ca11e Initial load
duke
parents:
diff changeset
   880
                flow(attribute(todo));
06bc494ca11e Initial load
duke
parents:
diff changeset
   881
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   882
06bc494ca11e Initial load
duke
parents:
diff changeset
   883
            case SIMPLE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   884
                generate(desugar(flow(attribute(todo))));
06bc494ca11e Initial load
duke
parents:
diff changeset
   885
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   886
1355
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   887
            case BY_FILE: {
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   888
                    Queue<Queue<Env<AttrContext>>> q = todo.groupByFile();
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
   889
                    while (!q.isEmpty() && !shouldStop(CompileState.ATTR)) {
1355
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   890
                        generate(desugar(flow(attribute(q.remove()))));
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   891
                    }
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   892
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   893
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   894
06bc494ca11e Initial load
duke
parents:
diff changeset
   895
            case BY_TODO:
1355
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   896
                while (!todo.isEmpty())
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
   897
                    generate(desugar(flow(attribute(todo.remove()))));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   898
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   899
06bc494ca11e Initial load
duke
parents:
diff changeset
   900
            default:
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7335
diff changeset
   901
                Assert.error("unknown compile policy");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   902
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   903
        } catch (Abort ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   904
            if (devVerbose)
7335
8b390fd27190 6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents: 7076
diff changeset
   905
                ex.printStackTrace(System.err);
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   906
        } finally {
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   907
            if (verbose) {
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   908
                elapsed_msec = elapsed(start_msec);
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   909
                log.printVerbose("total", Long.toString(elapsed_msec));
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   910
            }
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   911
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   912
            reportDeferredDiagnostics();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   913
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   914
            if (!log.hasDiagnosticListener()) {
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   915
                printCount("error", errorCount());
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   916
                printCount("warn", warningCount());
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   917
            }
24898
88fa65d2ac87 8033414: javac Plugin to receive notification (before and) after the compilation.
jlahoda
parents: 24897
diff changeset
   918
            if (!taskListener.isEmpty()) {
88fa65d2ac87 8033414: javac Plugin to receive notification (before and) after the compilation.
jlahoda
parents: 24897
diff changeset
   919
                taskListener.finished(new TaskEvent(TaskEvent.Kind.COMPILATION));
88fa65d2ac87 8033414: javac Plugin to receive notification (before and) after the compilation.
jlahoda
parents: 24897
diff changeset
   920
            }
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   921
            close();
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   922
            if (procEnvImpl != null)
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
   923
                procEnvImpl.close();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   924
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   925
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   926
14957
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
   927
    /**
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
   928
     * Set needRootClasses to true, in JavaCompiler subclass constructor
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
   929
     * that want to collect public apis of classes supplied on the command line.
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
   930
     */
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
   931
    protected boolean needRootClasses = false;
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
   932
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
   933
    /**
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
   934
     * The list of classes explicitly supplied on the command line for compilation.
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
   935
     * Not always populated.
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
   936
     */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   937
    private List<JCClassDecl> rootClasses;
06bc494ca11e Initial load
duke
parents:
diff changeset
   938
06bc494ca11e Initial load
duke
parents:
diff changeset
   939
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   940
     * Parses a list of files.
06bc494ca11e Initial load
duke
parents:
diff changeset
   941
     */
6581
f58f0ce45802 6980707: Reduce use of IOException in JavaCompiler
jjg
parents: 6572
diff changeset
   942
   public List<JCCompilationUnit> parseFiles(Iterable<JavaFileObject> fileObjects) {
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
   943
       if (shouldStop(CompileState.PARSE))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   944
           return List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   945
06bc494ca11e Initial load
duke
parents:
diff changeset
   946
        //parse all files
20249
93f8eae31092 6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents: 19921
diff changeset
   947
        ListBuffer<JCCompilationUnit> trees = new ListBuffer<>();
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   948
        Set<JavaFileObject> filesSoFar = new HashSet<>();
6596
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents: 6594
diff changeset
   949
        for (JavaFileObject fileObject : fileObjects) {
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents: 6594
diff changeset
   950
            if (!filesSoFar.contains(fileObject)) {
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents: 6594
diff changeset
   951
                filesSoFar.add(fileObject);
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents: 6594
diff changeset
   952
                trees.append(parse(fileObject));
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents: 6594
diff changeset
   953
            }
3274cf9d4873 6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents: 6594
diff changeset
   954
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   955
        return trees.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
   956
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   957
06bc494ca11e Initial load
duke
parents:
diff changeset
   958
    /**
14050
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   959
     * Enter the symbols found in a list of parse trees if the compilation
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   960
     * is expected to proceed beyond anno processing into attr.
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   961
     * As a side-effect, this puts elements on the "todo" list.
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   962
     * Also stores a list of all top level classes in rootClasses.
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   963
     */
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   964
    public List<JCCompilationUnit> enterTreesIfNeeded(List<JCCompilationUnit> roots) {
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   965
       if (shouldStop(CompileState.ATTR))
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   966
           return List.nil();
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   967
        return enterTrees(roots);
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   968
    }
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   969
9bfad4b4b6a2 7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents: 12213
diff changeset
   970
    /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   971
     * Enter the symbols found in a list of parse trees.
06bc494ca11e Initial load
duke
parents:
diff changeset
   972
     * As a side-effect, this puts elements on the "todo" list.
06bc494ca11e Initial load
duke
parents:
diff changeset
   973
     * Also stores a list of all top level classes in rootClasses.
06bc494ca11e Initial load
duke
parents:
diff changeset
   974
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   975
    public List<JCCompilationUnit> enterTrees(List<JCCompilationUnit> roots) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   976
        //enter symbols for all files
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11867
diff changeset
   977
        if (!taskListener.isEmpty()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   978
            for (JCCompilationUnit unit: roots) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   979
                TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, unit);
06bc494ca11e Initial load
duke
parents:
diff changeset
   980
                taskListener.started(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   981
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   982
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   983
06bc494ca11e Initial load
duke
parents:
diff changeset
   984
        enter.main(roots);
06bc494ca11e Initial load
duke
parents:
diff changeset
   985
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11867
diff changeset
   986
        if (!taskListener.isEmpty()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   987
            for (JCCompilationUnit unit: roots) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   988
                TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, unit);
06bc494ca11e Initial load
duke
parents:
diff changeset
   989
                taskListener.finished(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   990
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   991
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   992
14957
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
   993
        // If generating source, or if tracking public apis,
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
   994
        // then remember the classes declared in
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
   995
        // the original compilation units listed on the command line.
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
   996
        if (needRootClasses || sourceOutput || stubOutput) {
20249
93f8eae31092 6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents: 19921
diff changeset
   997
            ListBuffer<JCClassDecl> cdefs = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   998
            for (JCCompilationUnit unit : roots) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   999
                for (List<JCTree> defs = unit.defs;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1000
                     defs.nonEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1001
                     defs = defs.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1002
                    if (defs.head instanceof JCClassDecl)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1003
                        cdefs.append((JCClassDecl)defs.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1004
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1005
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1006
            rootClasses = cdefs.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1007
        }
6572
4ca2051ff71a 6935638: -implicit:none prevents compilation with annotation processing
jjg
parents: 6355
diff changeset
  1008
4ca2051ff71a 6935638: -implicit:none prevents compilation with annotation processing
jjg
parents: 6355
diff changeset
  1009
        // Ensure the input files have been recorded. Although this is normally
4ca2051ff71a 6935638: -implicit:none prevents compilation with annotation processing
jjg
parents: 6355
diff changeset
  1010
        // done by readSource, it may not have been done if the trees were read
4ca2051ff71a 6935638: -implicit:none prevents compilation with annotation processing
jjg
parents: 6355
diff changeset
  1011
        // in a prior round of annotation processing, and the trees have been
4ca2051ff71a 6935638: -implicit:none prevents compilation with annotation processing
jjg
parents: 6355
diff changeset
  1012
        // cleaned and are being reused.
4ca2051ff71a 6935638: -implicit:none prevents compilation with annotation processing
jjg
parents: 6355
diff changeset
  1013
        for (JCCompilationUnit unit : roots) {
4ca2051ff71a 6935638: -implicit:none prevents compilation with annotation processing
jjg
parents: 6355
diff changeset
  1014
            inputFiles.add(unit.sourcefile);
4ca2051ff71a 6935638: -implicit:none prevents compilation with annotation processing
jjg
parents: 6355
diff changeset
  1015
        }
4ca2051ff71a 6935638: -implicit:none prevents compilation with annotation processing
jjg
parents: 6355
diff changeset
  1016
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1017
        return roots;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1018
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1019
06bc494ca11e Initial load
duke
parents:
diff changeset
  1020
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1021
     * Set to true to enable skeleton annotation processing code.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1022
     * Currently, we assume this variable will be replaced more
06bc494ca11e Initial load
duke
parents:
diff changeset
  1023
     * advanced logic to figure out if annotation processing is
06bc494ca11e Initial load
duke
parents:
diff changeset
  1024
     * needed.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1025
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1026
    boolean processAnnotations = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1027
14538
384681be798f 8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents: 14365
diff changeset
  1028
    Log.DeferredDiagnosticHandler deferredDiagnosticHandler;
384681be798f 8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents: 14365
diff changeset
  1029
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1030
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1031
     * Object to handle annotation processing.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1032
     */
3656
d4e34b76b0c3 6558476: com/sun/tools/javac/Main.compile don't release file handles on return
jjg
parents: 3557
diff changeset
  1033
    private JavacProcessingEnvironment procEnvImpl = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1034
06bc494ca11e Initial load
duke
parents:
diff changeset
  1035
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1036
     * Check if we should process annotations.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1037
     * If so, and if no scanner is yet registered, then set up the DocCommentScanner
06bc494ca11e Initial load
duke
parents:
diff changeset
  1038
     * to catch doc comments, and set keepComments so the parser records them in
06bc494ca11e Initial load
duke
parents:
diff changeset
  1039
     * the compilation unit.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1040
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1041
     * @param processors user provided annotation processors to bypass
06bc494ca11e Initial load
duke
parents:
diff changeset
  1042
     * discovery, {@code null} means that no processors were provided
06bc494ca11e Initial load
duke
parents:
diff changeset
  1043
     */
6581
f58f0ce45802 6980707: Reduce use of IOException in JavaCompiler
jjg
parents: 6572
diff changeset
  1044
    public void initProcessAnnotations(Iterable<? extends Processor> processors) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1045
        // Process annotations if processing is not disabled and there
06bc494ca11e Initial load
duke
parents:
diff changeset
  1046
        // is at least one Processor available.
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
  1047
        if (options.isSet(PROC, "none")) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1048
            processAnnotations = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1049
        } else if (procEnvImpl == null) {
14548
aa687b312c97 8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents: 14538
diff changeset
  1050
            procEnvImpl = JavacProcessingEnvironment.instance(context);
aa687b312c97 8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents: 14538
diff changeset
  1051
            procEnvImpl.setProcessors(processors);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1052
            processAnnotations = procEnvImpl.atLeastOneProcessor();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1053
06bc494ca11e Initial load
duke
parents:
diff changeset
  1054
            if (processAnnotations) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1055
                options.put("save-parameter-names", "save-parameter-names");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1056
                reader.saveParameterNames = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1057
                keepComments = true;
6716
71df48777dd1 6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents: 6596
diff changeset
  1058
                genEndPos = true;
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11867
diff changeset
  1059
                if (!taskListener.isEmpty())
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1060
                    taskListener.started(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING));
14538
384681be798f 8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents: 14365
diff changeset
  1061
                deferredDiagnosticHandler = new Log.DeferredDiagnosticHandler(log);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1062
            } else { // free resources
06bc494ca11e Initial load
duke
parents:
diff changeset
  1063
                procEnvImpl.close();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1064
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1065
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1066
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1067
06bc494ca11e Initial load
duke
parents:
diff changeset
  1068
    // TODO: called by JavacTaskImpl
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
  1069
    public void processAnnotations(List<JCCompilationUnit> roots) {
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
  1070
        processAnnotations(roots, List.<String>nil());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1071
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1072
06bc494ca11e Initial load
duke
parents:
diff changeset
  1073
    /**
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11867
diff changeset
  1074
     * Process any annotations found in the specified compilation units.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1075
     * @param roots a list of compilation units
06bc494ca11e Initial load
duke
parents:
diff changeset
  1076
     * @return an instance of the compiler in which to complete the compilation
06bc494ca11e Initial load
duke
parents:
diff changeset
  1077
     */
6582
c7a4fb5a2f86 6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents: 6581
diff changeset
  1078
    // Implementation note: when this method is called, log.deferredDiagnostics
c7a4fb5a2f86 6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents: 6581
diff changeset
  1079
    // will have been set true by initProcessAnnotations, meaning that any diagnostics
c7a4fb5a2f86 6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents: 6581
diff changeset
  1080
    // that are reported will go into the log.deferredDiagnostics queue.
c7a4fb5a2f86 6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents: 6581
diff changeset
  1081
    // By the time this method exits, log.deferDiagnostics must be set back to false,
c7a4fb5a2f86 6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents: 6581
diff changeset
  1082
    // and all deferredDiagnostics must have been handled: i.e. either reported
c7a4fb5a2f86 6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents: 6581
diff changeset
  1083
    // or determined to be transient, and therefore suppressed.
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
  1084
    public void processAnnotations(List<JCCompilationUnit> roots,
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
  1085
                                   List<String> classnames) {
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1086
        if (shouldStop(CompileState.PROCESS)) {
6355
f01ebbf5a5f7 6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents: 6156
diff changeset
  1087
            // Errors were encountered.
6582
c7a4fb5a2f86 6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents: 6581
diff changeset
  1088
            // Unless all the errors are resolve errors, the errors were parse errors
6355
f01ebbf5a5f7 6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents: 6156
diff changeset
  1089
            // or other errors during enter which cannot be fixed by running
f01ebbf5a5f7 6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents: 6156
diff changeset
  1090
            // any annotation processors.
6582
c7a4fb5a2f86 6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents: 6581
diff changeset
  1091
            if (unrecoverableError()) {
14538
384681be798f 8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents: 14365
diff changeset
  1092
                deferredDiagnosticHandler.reportDeferredDiagnostics();
384681be798f 8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents: 14365
diff changeset
  1093
                log.popDiagnosticHandler(deferredDiagnosticHandler);
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
  1094
                return ;
6582
c7a4fb5a2f86 6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents: 6581
diff changeset
  1095
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1096
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1097
06bc494ca11e Initial load
duke
parents:
diff changeset
  1098
        // ASSERT: processAnnotations and procEnvImpl should have been set up by
06bc494ca11e Initial load
duke
parents:
diff changeset
  1099
        // by initProcessAnnotations
06bc494ca11e Initial load
duke
parents:
diff changeset
  1100
06bc494ca11e Initial load
duke
parents:
diff changeset
  1101
        // NOTE: The !classnames.isEmpty() checks should be refactored to Main.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1102
06bc494ca11e Initial load
duke
parents:
diff changeset
  1103
        if (!processAnnotations) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1104
            // If there are no annotation processors present, and
06bc494ca11e Initial load
duke
parents:
diff changeset
  1105
            // annotation processing is to occur with compilation,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1106
            // emit a warning.
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
  1107
            if (options.isSet(PROC, "only")) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1108
                log.warning("proc.proc-only.requested.no.procs");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1109
                todo.clear();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1110
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1111
            // If not processing annotations, classnames must be empty
06bc494ca11e Initial load
duke
parents:
diff changeset
  1112
            if (!classnames.isEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1113
                log.error("proc.no.explicit.annotation.processing.requested",
06bc494ca11e Initial load
duke
parents:
diff changeset
  1114
                          classnames);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1115
            }
14538
384681be798f 8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents: 14365
diff changeset
  1116
            Assert.checkNull(deferredDiagnosticHandler);
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
  1117
            return ; // continue regular compilation
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1118
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1119
14538
384681be798f 8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents: 14365
diff changeset
  1120
        Assert.checkNonNull(deferredDiagnosticHandler);
384681be798f 8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents: 14365
diff changeset
  1121
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1122
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1123
            List<ClassSymbol> classSymbols = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1124
            List<PackageSymbol> pckSymbols = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1125
            if (!classnames.isEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1126
                 // Check for explicit request for annotation
06bc494ca11e Initial load
duke
parents:
diff changeset
  1127
                 // processing
06bc494ca11e Initial load
duke
parents:
diff changeset
  1128
                if (!explicitAnnotationProcessingRequested()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1129
                    log.error("proc.no.explicit.annotation.processing.requested",
06bc494ca11e Initial load
duke
parents:
diff changeset
  1130
                              classnames);
14538
384681be798f 8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents: 14365
diff changeset
  1131
                    deferredDiagnosticHandler.reportDeferredDiagnostics();
384681be798f 8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents: 14365
diff changeset
  1132
                    log.popDiagnosticHandler(deferredDiagnosticHandler);
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
  1133
                    return ; // TODO: Will this halt compilation?
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1134
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1135
                    boolean errors = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1136
                    for (String nameStr : classnames) {
8851
e630c590eb10 6930508: Passing nested class names on javac command line interfere with subsequent name -> class lookup
jjg
parents: 8845
diff changeset
  1137
                        Symbol sym = resolveBinaryNameOrIdent(nameStr);
11867
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents: 11314
diff changeset
  1138
                        if (sym == null ||
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents: 11314
diff changeset
  1139
                            (sym.kind == Kinds.PCK && !processPcks) ||
1fa9d18707da 7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents: 11314
diff changeset
  1140
                            sym.kind == Kinds.ABSENT_TYP) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1141
                            log.error("proc.cant.find.class", nameStr);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1142
                            errors = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1143
                            continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1144
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1145
                        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1146
                            if (sym.kind == Kinds.PCK)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1147
                                sym.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1148
                            if (sym.exists()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1149
                                if (sym.kind == Kinds.PCK)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1150
                                    pckSymbols = pckSymbols.prepend((PackageSymbol)sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1151
                                else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1152
                                    classSymbols = classSymbols.prepend((ClassSymbol)sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1153
                                continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1154
                            }
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7335
diff changeset
  1155
                            Assert.check(sym.kind == Kinds.PCK);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1156
                            log.warning("proc.package.does.not.exist", nameStr);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1157
                            pckSymbols = pckSymbols.prepend((PackageSymbol)sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1158
                        } catch (CompletionFailure e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1159
                            log.error("proc.cant.find.class", nameStr);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1160
                            errors = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1161
                            continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1162
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1163
                    }
6582
c7a4fb5a2f86 6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents: 6581
diff changeset
  1164
                    if (errors) {
14538
384681be798f 8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents: 14365
diff changeset
  1165
                        deferredDiagnosticHandler.reportDeferredDiagnostics();
384681be798f 8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents: 14365
diff changeset
  1166
                        log.popDiagnosticHandler(deferredDiagnosticHandler);
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
  1167
                        return ;
6582
c7a4fb5a2f86 6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents: 6581
diff changeset
  1168
                    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1169
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1170
            }
3656
d4e34b76b0c3 6558476: com/sun/tools/javac/Main.compile don't release file handles on return
jjg
parents: 3557
diff changeset
  1171
            try {
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
  1172
                annotationProcessingOccurred =
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
  1173
                        procEnvImpl.doProcessing(roots,
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
  1174
                                                 classSymbols,
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
  1175
                                                 pckSymbols,
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
  1176
                                                 deferredDiagnosticHandler);
6582
c7a4fb5a2f86 6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents: 6581
diff changeset
  1177
                // doProcessing will have handled deferred diagnostics
3656
d4e34b76b0c3 6558476: com/sun/tools/javac/Main.compile don't release file handles on return
jjg
parents: 3557
diff changeset
  1178
            } finally {
d4e34b76b0c3 6558476: com/sun/tools/javac/Main.compile don't release file handles on return
jjg
parents: 3557
diff changeset
  1179
                procEnvImpl.close();
d4e34b76b0c3 6558476: com/sun/tools/javac/Main.compile don't release file handles on return
jjg
parents: 3557
diff changeset
  1180
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1181
        } catch (CompletionFailure ex) {
169
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1182
            log.error("cant.access", ex.sym, ex.getDetailValue());
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
  1183
            if (deferredDiagnosticHandler != null) {
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
  1184
                deferredDiagnosticHandler.reportDeferredDiagnostics();
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
  1185
                log.popDiagnosticHandler(deferredDiagnosticHandler);
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
  1186
            }
6582
c7a4fb5a2f86 6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents: 6581
diff changeset
  1187
        }
c7a4fb5a2f86 6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents: 6581
diff changeset
  1188
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1189
6582
c7a4fb5a2f86 6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents: 6581
diff changeset
  1190
    private boolean unrecoverableError() {
14538
384681be798f 8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents: 14365
diff changeset
  1191
        if (deferredDiagnosticHandler != null) {
384681be798f 8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents: 14365
diff changeset
  1192
            for (JCDiagnostic d: deferredDiagnosticHandler.getDiagnostics()) {
384681be798f 8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents: 14365
diff changeset
  1193
                if (d.getKind() == JCDiagnostic.Kind.ERROR && !d.isFlagSet(RECOVERABLE))
384681be798f 8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents: 14365
diff changeset
  1194
                    return true;
384681be798f 8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents: 14365
diff changeset
  1195
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1196
        }
6582
c7a4fb5a2f86 6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents: 6581
diff changeset
  1197
        return false;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1198
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1199
06bc494ca11e Initial load
duke
parents:
diff changeset
  1200
    boolean explicitAnnotationProcessingRequested() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1201
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
  1202
            explicitAnnotationProcessingRequested ||
8623
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents: 8618
diff changeset
  1203
            explicitAnnotationProcessingRequested(options);
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents: 8618
diff changeset
  1204
    }
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents: 8618
diff changeset
  1205
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents: 8618
diff changeset
  1206
    static boolean explicitAnnotationProcessingRequested(Options options) {
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents: 8618
diff changeset
  1207
        return
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
  1208
            options.isSet(PROCESSOR) ||
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
  1209
            options.isSet(PROCESSORPATH) ||
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
  1210
            options.isSet(PROC, "only") ||
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6716
diff changeset
  1211
            options.isSet(XPRINT);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1212
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1213
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
  1214
    public void setDeferredDiagnosticHandler(Log.DeferredDiagnosticHandler deferredDiagnosticHandler) {
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
  1215
        this.deferredDiagnosticHandler = deferredDiagnosticHandler;
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
  1216
    }
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
  1217
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1218
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1219
     * Attribute a list of parse trees, such as found on the "todo" list.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1220
     * Note that attributing classes may cause additional files to be
06bc494ca11e Initial load
duke
parents:
diff changeset
  1221
     * parsed and entered via the SourceCompleter.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1222
     * Attribution of the entries in the list does not stop if any errors occur.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1223
     * @returns a list of environments for attributd classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1224
     */
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 735
diff changeset
  1225
    public Queue<Env<AttrContext>> attribute(Queue<Env<AttrContext>> envs) {
20249
93f8eae31092 6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents: 19921
diff changeset
  1226
        ListBuffer<Env<AttrContext>> results = new ListBuffer<>();
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 735
diff changeset
  1227
        while (!envs.isEmpty())
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 735
diff changeset
  1228
            results.append(attribute(envs.remove()));
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1229
        return stopIfError(CompileState.ATTR, results);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1230
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1231
06bc494ca11e Initial load
duke
parents:
diff changeset
  1232
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1233
     * Attribute a parse tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1234
     * @returns the attributed parse tree
06bc494ca11e Initial load
duke
parents:
diff changeset
  1235
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1236
    public Env<AttrContext> attribute(Env<AttrContext> env) {
936
1d395a623f16 6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents: 864
diff changeset
  1237
        if (compileStates.isDone(env, CompileState.ATTR))
1d395a623f16 6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents: 864
diff changeset
  1238
            return env;
1d395a623f16 6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents: 864
diff changeset
  1239
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1240
        if (verboseCompilePolicy)
6143
79b7dee406cc 6966732: replace use of static Log.getLocalizedString with non-static alternative where possible
jjg
parents: 6031
diff changeset
  1241
            printNote("[attribute " + env.enclClass.sym + "]");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1242
        if (verbose)
8630
cd9eefe597f6 6966736: javac verbose output is inconsistent
jjg
parents: 8624
diff changeset
  1243
            log.printVerbose("checking.attribution", env.enclClass.sym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1244
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11867
diff changeset
  1245
        if (!taskListener.isEmpty()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1246
            TaskEvent e = new TaskEvent(TaskEvent.Kind.ANALYZE, env.toplevel, env.enclClass.sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1247
            taskListener.started(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1248
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1249
06bc494ca11e Initial load
duke
parents:
diff changeset
  1250
        JavaFileObject prev = log.useSource(
06bc494ca11e Initial load
duke
parents:
diff changeset
  1251
                                  env.enclClass.sym.sourcefile != null ?
06bc494ca11e Initial load
duke
parents:
diff changeset
  1252
                                  env.enclClass.sym.sourcefile :
06bc494ca11e Initial load
duke
parents:
diff changeset
  1253
                                  env.toplevel.sourcefile);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1254
        try {
8845
42fb82dfbf52 6993311: annotations on packages are not validated
jjg
parents: 8630
diff changeset
  1255
            attr.attrib(env);
6594
d43f068fba19 6970584: Flow.java should be more error-friendly
mcimadamore
parents: 6582
diff changeset
  1256
            if (errorCount() > 0 && !shouldStop(CompileState.ATTR)) {
d43f068fba19 6970584: Flow.java should be more error-friendly
mcimadamore
parents: 6582
diff changeset
  1257
                //if in fail-over mode, ensure that AST expression nodes
d43f068fba19 6970584: Flow.java should be more error-friendly
mcimadamore
parents: 6582
diff changeset
  1258
                //are correctly initialized (e.g. they have a type/symbol)
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1259
                attr.postAttr(env.tree);
6594
d43f068fba19 6970584: Flow.java should be more error-friendly
mcimadamore
parents: 6582
diff changeset
  1260
            }
936
1d395a623f16 6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents: 864
diff changeset
  1261
            compileStates.put(env, CompileState.ATTR);
14957
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
  1262
            if (rootClasses != null && rootClasses.contains(env.enclClass)) {
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
  1263
                // This was a class that was explicitly supplied for compilation.
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
  1264
                // If we want to capture the public api of this class,
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
  1265
                // then now is a good time to do it.
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
  1266
                reportPublicApi(env.enclClass.sym);
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
  1267
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1268
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1269
        finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1270
            log.useSource(prev);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1271
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1272
06bc494ca11e Initial load
duke
parents:
diff changeset
  1273
        return env;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1274
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1275
14957
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
  1276
    /** Report the public api of a class that was supplied explicitly for compilation,
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
  1277
     *  for example on the command line to javac.
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
  1278
     * @param sym The symbol of the class.
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
  1279
     */
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
  1280
    public void reportPublicApi(ClassSymbol sym) {
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
  1281
       // Override to collect the reported public api.
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
  1282
    }
ea7808ffcf6d 8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents: 14952
diff changeset
  1283
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1284
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1285
     * Perform dataflow checks on attributed parse trees.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1286
     * These include checks for definite assignment and unreachable statements.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1287
     * If any errors occur, an empty list will be returned.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1288
     * @returns the list of attributed parse trees
06bc494ca11e Initial load
duke
parents:
diff changeset
  1289
     */
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 735
diff changeset
  1290
    public Queue<Env<AttrContext>> flow(Queue<Env<AttrContext>> envs) {
20249
93f8eae31092 6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents: 19921
diff changeset
  1291
        ListBuffer<Env<AttrContext>> results = new ListBuffer<>();
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 735
diff changeset
  1292
        for (Env<AttrContext> env: envs) {
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 735
diff changeset
  1293
            flow(env, results);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1294
        }
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1295
        return stopIfError(CompileState.FLOW, results);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1296
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1297
06bc494ca11e Initial load
duke
parents:
diff changeset
  1298
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1299
     * Perform dataflow checks on an attributed parse tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1300
     */
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 735
diff changeset
  1301
    public Queue<Env<AttrContext>> flow(Env<AttrContext> env) {
20249
93f8eae31092 6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents: 19921
diff changeset
  1302
        ListBuffer<Env<AttrContext>> results = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1303
        flow(env, results);
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1304
        return stopIfError(CompileState.FLOW, results);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1305
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1306
06bc494ca11e Initial load
duke
parents:
diff changeset
  1307
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1308
     * Perform dataflow checks on an attributed parse tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1309
     */
1355
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
  1310
    protected void flow(Env<AttrContext> env, Queue<Env<AttrContext>> results) {
24392
aca305440fb9 8040822: Duplicated notifications can be sent to TaskListener
jlahoda
parents: 24069
diff changeset
  1311
        if (compileStates.isDone(env, CompileState.FLOW)) {
aca305440fb9 8040822: Duplicated notifications can be sent to TaskListener
jlahoda
parents: 24069
diff changeset
  1312
            results.add(env);
aca305440fb9 8040822: Duplicated notifications can be sent to TaskListener
jlahoda
parents: 24069
diff changeset
  1313
            return;
aca305440fb9 8040822: Duplicated notifications can be sent to TaskListener
jlahoda
parents: 24069
diff changeset
  1314
        }
aca305440fb9 8040822: Duplicated notifications can be sent to TaskListener
jlahoda
parents: 24069
diff changeset
  1315
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1316
        try {
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1317
            if (shouldStop(CompileState.FLOW))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1318
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1319
24392
aca305440fb9 8040822: Duplicated notifications can be sent to TaskListener
jlahoda
parents: 24069
diff changeset
  1320
            if (relax) {
1355
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
  1321
                results.add(env);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1322
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1323
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1324
06bc494ca11e Initial load
duke
parents:
diff changeset
  1325
            if (verboseCompilePolicy)
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1326
                printNote("[flow " + env.enclClass.sym + "]");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1327
            JavaFileObject prev = log.useSource(
06bc494ca11e Initial load
duke
parents:
diff changeset
  1328
                                                env.enclClass.sym.sourcefile != null ?
06bc494ca11e Initial load
duke
parents:
diff changeset
  1329
                                                env.enclClass.sym.sourcefile :
06bc494ca11e Initial load
duke
parents:
diff changeset
  1330
                                                env.toplevel.sourcefile);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1331
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1332
                make.at(Position.FIRSTPOS);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1333
                TreeMaker localMake = make.forToplevel(env.toplevel);
6156
e15c221efaac 6970833: Try-with-resource implementation throws an NPE during Flow analysis
mcimadamore
parents: 6143
diff changeset
  1334
                flow.analyzeTree(env, localMake);
936
1d395a623f16 6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents: 864
diff changeset
  1335
                compileStates.put(env, CompileState.FLOW);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1336
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1337
                if (shouldStop(CompileState.FLOW))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1338
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1339
1355
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
  1340
                results.add(env);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1341
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1342
            finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1343
                log.useSource(prev);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1344
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1345
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1346
        finally {
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11867
diff changeset
  1347
            if (!taskListener.isEmpty()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1348
                TaskEvent e = new TaskEvent(TaskEvent.Kind.ANALYZE, env.toplevel, env.enclClass.sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1349
                taskListener.finished(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1350
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1351
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1352
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1353
06bc494ca11e Initial load
duke
parents:
diff changeset
  1354
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1355
     * Prepare attributed parse trees, in conjunction with their attribution contexts,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1356
     * for source or code generation.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1357
     * If any errors occur, an empty list will be returned.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1358
     * @returns a list containing the classes to be generated
06bc494ca11e Initial load
duke
parents:
diff changeset
  1359
     */
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 735
diff changeset
  1360
    public Queue<Pair<Env<AttrContext>, JCClassDecl>> desugar(Queue<Env<AttrContext>> envs) {
20249
93f8eae31092 6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents: 19921
diff changeset
  1361
        ListBuffer<Pair<Env<AttrContext>, JCClassDecl>> results = new ListBuffer<>();
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 735
diff changeset
  1362
        for (Env<AttrContext> env: envs)
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 735
diff changeset
  1363
            desugar(env, results);
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1364
        return stopIfError(CompileState.FLOW, results);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1365
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1366
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
  1367
    HashMap<Env<AttrContext>, Queue<Pair<Env<AttrContext>, JCClassDecl>>> desugaredEnvs = new HashMap<>();
3557
a803afefa115 6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents: 3151
diff changeset
  1368
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1369
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1370
     * Prepare attributed parse trees, in conjunction with their attribution contexts,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1371
     * for source or code generation. If the file was not listed on the command line,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1372
     * the current implicitSourcePolicy is taken into account.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1373
     * The preparation stops as soon as an error is found.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1374
     */
936
1d395a623f16 6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents: 864
diff changeset
  1375
    protected void desugar(final Env<AttrContext> env, Queue<Pair<Env<AttrContext>, JCClassDecl>> results) {
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1376
        if (shouldStop(CompileState.TRANSTYPES))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1377
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1378
06bc494ca11e Initial load
duke
parents:
diff changeset
  1379
        if (implicitSourcePolicy == ImplicitSourcePolicy.NONE
06bc494ca11e Initial load
duke
parents:
diff changeset
  1380
                && !inputFiles.contains(env.toplevel.sourcefile)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1381
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1382
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1383
3557
a803afefa115 6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents: 3151
diff changeset
  1384
        if (compileStates.isDone(env, CompileState.LOWER)) {
a803afefa115 6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents: 3151
diff changeset
  1385
            results.addAll(desugaredEnvs.get(env));
a803afefa115 6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents: 3151
diff changeset
  1386
            return;
a803afefa115 6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents: 3151
diff changeset
  1387
        }
a803afefa115 6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents: 3151
diff changeset
  1388
936
1d395a623f16 6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents: 864
diff changeset
  1389
        /**
3557
a803afefa115 6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents: 3151
diff changeset
  1390
         * Ensure that superclasses of C are desugared before C itself. This is
a803afefa115 6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents: 3151
diff changeset
  1391
         * required for two reasons: (i) as erasure (TransTypes) destroys
a803afefa115 6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents: 3151
diff changeset
  1392
         * information needed in flow analysis and (ii) as some checks carried
a803afefa115 6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents: 3151
diff changeset
  1393
         * out during lowering require that all synthetic fields/methods have
a803afefa115 6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents: 3151
diff changeset
  1394
         * already been added to C and its superclasses.
936
1d395a623f16 6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents: 864
diff changeset
  1395
         */
1d395a623f16 6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents: 864
diff changeset
  1396
        class ScanNested extends TreeScanner {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
  1397
            Set<Env<AttrContext>> dependencies = new LinkedHashSet<>();
21497
ad075a07ee79 8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents: 20617
diff changeset
  1398
            protected boolean hasLambdas;
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1399
            @Override
936
1d395a623f16 6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents: 864
diff changeset
  1400
            public void visitClassDef(JCClassDecl node) {
1d395a623f16 6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents: 864
diff changeset
  1401
                Type st = types.supertype(node.sym.type);
16968
19f0da2d3143 8010659: Javac Crashes while building OpenJFX
vromero
parents: 15562
diff changeset
  1402
                boolean envForSuperTypeFound = false;
19f0da2d3143 8010659: Javac Crashes while building OpenJFX
vromero
parents: 15562
diff changeset
  1403
                while (!envForSuperTypeFound && st.hasTag(CLASS)) {
936
1d395a623f16 6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents: 864
diff changeset
  1404
                    ClassSymbol c = st.tsym.outermostClass();
1d395a623f16 6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents: 864
diff changeset
  1405
                    Env<AttrContext> stEnv = enter.getEnv(c);
1046
e395ce284cbf 6734819: Javac performs flows analysis on already translated classes
mcimadamore
parents: 936
diff changeset
  1406
                    if (stEnv != null && env != stEnv) {
16968
19f0da2d3143 8010659: Javac Crashes while building OpenJFX
vromero
parents: 15562
diff changeset
  1407
                        if (dependencies.add(stEnv)) {
21497
ad075a07ee79 8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents: 20617
diff changeset
  1408
                            boolean prevHasLambdas = hasLambdas;
ad075a07ee79 8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents: 20617
diff changeset
  1409
                            try {
ad075a07ee79 8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents: 20617
diff changeset
  1410
                                scan(stEnv.tree);
ad075a07ee79 8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents: 20617
diff changeset
  1411
                            } finally {
ad075a07ee79 8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents: 20617
diff changeset
  1412
                                /*
ad075a07ee79 8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents: 20617
diff changeset
  1413
                                 * ignore any updates to hasLambdas made during
ad075a07ee79 8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents: 20617
diff changeset
  1414
                                 * the nested scan, this ensures an initalized
ad075a07ee79 8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents: 20617
diff changeset
  1415
                                 * LambdaToMethod is available only to those
ad075a07ee79 8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents: 20617
diff changeset
  1416
                                 * classes that contain lambdas
ad075a07ee79 8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents: 20617
diff changeset
  1417
                                 */
ad075a07ee79 8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents: 20617
diff changeset
  1418
                                hasLambdas = prevHasLambdas;
ad075a07ee79 8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents: 20617
diff changeset
  1419
                            }
16968
19f0da2d3143 8010659: Javac Crashes while building OpenJFX
vromero
parents: 15562
diff changeset
  1420
                        }
19f0da2d3143 8010659: Javac Crashes while building OpenJFX
vromero
parents: 15562
diff changeset
  1421
                        envForSuperTypeFound = true;
1046
e395ce284cbf 6734819: Javac performs flows analysis on already translated classes
mcimadamore
parents: 936
diff changeset
  1422
                    }
16968
19f0da2d3143 8010659: Javac Crashes while building OpenJFX
vromero
parents: 15562
diff changeset
  1423
                    st = types.supertype(st);
936
1d395a623f16 6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents: 864
diff changeset
  1424
                }
1d395a623f16 6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents: 864
diff changeset
  1425
                super.visitClassDef(node);
1d395a623f16 6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents: 864
diff changeset
  1426
            }
21497
ad075a07ee79 8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents: 20617
diff changeset
  1427
            @Override
ad075a07ee79 8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents: 20617
diff changeset
  1428
            public void visitLambda(JCLambda tree) {
ad075a07ee79 8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents: 20617
diff changeset
  1429
                hasLambdas = true;
ad075a07ee79 8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents: 20617
diff changeset
  1430
                super.visitLambda(tree);
ad075a07ee79 8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents: 20617
diff changeset
  1431
            }
ad075a07ee79 8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents: 20617
diff changeset
  1432
            @Override
ad075a07ee79 8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents: 20617
diff changeset
  1433
            public void visitReference(JCMemberReference tree) {
ad075a07ee79 8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents: 20617
diff changeset
  1434
                hasLambdas = true;
ad075a07ee79 8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents: 20617
diff changeset
  1435
                super.visitReference(tree);
ad075a07ee79 8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents: 20617
diff changeset
  1436
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1437
        }
936
1d395a623f16 6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents: 864
diff changeset
  1438
        ScanNested scanner = new ScanNested();
1d395a623f16 6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents: 864
diff changeset
  1439
        scanner.scan(env.tree);
1d395a623f16 6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents: 864
diff changeset
  1440
        for (Env<AttrContext> dep: scanner.dependencies) {
3557
a803afefa115 6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents: 3151
diff changeset
  1441
        if (!compileStates.isDone(dep, CompileState.FLOW))
a803afefa115 6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents: 3151
diff changeset
  1442
            desugaredEnvs.put(dep, desugar(flow(attribute(dep))));
936
1d395a623f16 6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents: 864
diff changeset
  1443
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1444
1046
e395ce284cbf 6734819: Javac performs flows analysis on already translated classes
mcimadamore
parents: 936
diff changeset
  1445
        //We need to check for error another time as more classes might
e395ce284cbf 6734819: Javac performs flows analysis on already translated classes
mcimadamore
parents: 936
diff changeset
  1446
        //have been attributed and analyzed at this stage
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1447
        if (shouldStop(CompileState.TRANSTYPES))
1046
e395ce284cbf 6734819: Javac performs flows analysis on already translated classes
mcimadamore
parents: 936
diff changeset
  1448
            return;
e395ce284cbf 6734819: Javac performs flows analysis on already translated classes
mcimadamore
parents: 936
diff changeset
  1449
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1450
        if (verboseCompilePolicy)
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1451
            printNote("[desugar " + env.enclClass.sym + "]");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1452
06bc494ca11e Initial load
duke
parents:
diff changeset
  1453
        JavaFileObject prev = log.useSource(env.enclClass.sym.sourcefile != null ?
06bc494ca11e Initial load
duke
parents:
diff changeset
  1454
                                  env.enclClass.sym.sourcefile :
06bc494ca11e Initial load
duke
parents:
diff changeset
  1455
                                  env.toplevel.sourcefile);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1456
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1457
            //save tree prior to rewriting
06bc494ca11e Initial load
duke
parents:
diff changeset
  1458
            JCTree untranslated = env.tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1459
06bc494ca11e Initial load
duke
parents:
diff changeset
  1460
            make.at(Position.FIRSTPOS);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1461
            TreeMaker localMake = make.forToplevel(env.toplevel);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1462
24069
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 23810
diff changeset
  1463
            if (env.tree.hasTag(JCTree.Tag.PACKAGEDEF)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1464
                if (!(stubOutput || sourceOutput || printFlat)) {
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1465
                    if (shouldStop(CompileState.LOWER))
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1466
                        return;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1467
                    List<JCTree> pdef = lower.translateTopLevelClass(env, env.tree, localMake);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1468
                    if (pdef.head != null) {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7335
diff changeset
  1469
                        Assert.check(pdef.tail.isEmpty());
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
  1470
                        results.add(new Pair<>(env, (JCClassDecl)pdef.head));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1471
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1472
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1473
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1474
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1475
06bc494ca11e Initial load
duke
parents:
diff changeset
  1476
            if (stubOutput) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1477
                //emit stub Java source file, only for compilation
06bc494ca11e Initial load
duke
parents:
diff changeset
  1478
                //units enumerated explicitly on the command line
06bc494ca11e Initial load
duke
parents:
diff changeset
  1479
                JCClassDecl cdef = (JCClassDecl)env.tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1480
                if (untranslated instanceof JCClassDecl &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1481
                    rootClasses.contains((JCClassDecl)untranslated) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1482
                    ((cdef.mods.flags & (Flags.PROTECTED|Flags.PUBLIC)) != 0 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  1483
                     cdef.sym.packge().getQualifiedName() == names.java_lang)) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
  1484
                    results.add(new Pair<>(env, removeMethodBodies(cdef)));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1485
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1486
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1487
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1488
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1489
            if (shouldStop(CompileState.TRANSTYPES))
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1490
                return;
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1491
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1492
            env.tree = transTypes.translateTopLevelClass(env.tree, localMake);
3557
a803afefa115 6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents: 3151
diff changeset
  1493
            compileStates.put(env, CompileState.TRANSTYPES);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1494
21497
ad075a07ee79 8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents: 20617
diff changeset
  1495
            if (source.allowLambda() && scanner.hasLambdas) {
18394
e7e0700732ad 8016607: javac, avoid analyzing lambdas for source 7 compilation
vromero
parents: 17582
diff changeset
  1496
                if (shouldStop(CompileState.UNLAMBDA))
e7e0700732ad 8016607: javac, avoid analyzing lambdas for source 7 compilation
vromero
parents: 17582
diff changeset
  1497
                    return;
14365
20f388573215 8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents: 14359
diff changeset
  1498
21497
ad075a07ee79 8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents: 20617
diff changeset
  1499
                env.tree = LambdaToMethod.instance(context).translateTopLevelClass(env, env.tree, localMake);
18394
e7e0700732ad 8016607: javac, avoid analyzing lambdas for source 7 compilation
vromero
parents: 17582
diff changeset
  1500
                compileStates.put(env, CompileState.UNLAMBDA);
e7e0700732ad 8016607: javac, avoid analyzing lambdas for source 7 compilation
vromero
parents: 17582
diff changeset
  1501
            }
14365
20f388573215 8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents: 14359
diff changeset
  1502
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1503
            if (shouldStop(CompileState.LOWER))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1504
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1505
06bc494ca11e Initial load
duke
parents:
diff changeset
  1506
            if (sourceOutput) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1507
                //emit standard Java source file, only for compilation
06bc494ca11e Initial load
duke
parents:
diff changeset
  1508
                //units enumerated explicitly on the command line
06bc494ca11e Initial load
duke
parents:
diff changeset
  1509
                JCClassDecl cdef = (JCClassDecl)env.tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1510
                if (untranslated instanceof JCClassDecl &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1511
                    rootClasses.contains((JCClassDecl)untranslated)) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
  1512
                    results.add(new Pair<>(env, cdef));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1513
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1514
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1515
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1516
06bc494ca11e Initial load
duke
parents:
diff changeset
  1517
            //translate out inner classes
06bc494ca11e Initial load
duke
parents:
diff changeset
  1518
            List<JCTree> cdefs = lower.translateTopLevelClass(env, env.tree, localMake);
3557
a803afefa115 6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents: 3151
diff changeset
  1519
            compileStates.put(env, CompileState.LOWER);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1520
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1521
            if (shouldStop(CompileState.LOWER))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1522
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1523
06bc494ca11e Initial load
duke
parents:
diff changeset
  1524
            //generate code for each class
06bc494ca11e Initial load
duke
parents:
diff changeset
  1525
            for (List<JCTree> l = cdefs; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1526
                JCClassDecl cdef = (JCClassDecl)l.head;
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
  1527
                results.add(new Pair<>(env, cdef));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1528
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1529
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1530
        finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1531
            log.useSource(prev);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1532
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1533
06bc494ca11e Initial load
duke
parents:
diff changeset
  1534
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1535
06bc494ca11e Initial load
duke
parents:
diff changeset
  1536
    /** Generates the source or class file for a list of classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1537
     * The decision to generate a source file or a class file is
06bc494ca11e Initial load
duke
parents:
diff changeset
  1538
     * based upon the compiler's options.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1539
     * Generation stops if an error occurs while writing files.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1540
     */
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 735
diff changeset
  1541
    public void generate(Queue<Pair<Env<AttrContext>, JCClassDecl>> queue) {
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 735
diff changeset
  1542
        generate(queue, null);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1543
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1544
1355
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
  1545
    public void generate(Queue<Pair<Env<AttrContext>, JCClassDecl>> queue, Queue<JavaFileObject> results) {
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1546
        if (shouldStop(CompileState.GENERATE))
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1547
            return;
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1548
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1549
        boolean usePrintSource = (stubOutput || sourceOutput || printFlat);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1550
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 735
diff changeset
  1551
        for (Pair<Env<AttrContext>, JCClassDecl> x: queue) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1552
            Env<AttrContext> env = x.fst;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1553
            JCClassDecl cdef = x.snd;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1554
06bc494ca11e Initial load
duke
parents:
diff changeset
  1555
            if (verboseCompilePolicy) {
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1556
                printNote("[generate "
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1557
                               + (usePrintSource ? " source" : "code")
1355
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
  1558
                               + " " + cdef.sym + "]");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1559
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1560
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11867
diff changeset
  1561
            if (!taskListener.isEmpty()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1562
                TaskEvent e = new TaskEvent(TaskEvent.Kind.GENERATE, env.toplevel, cdef.sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1563
                taskListener.started(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1564
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1565
06bc494ca11e Initial load
duke
parents:
diff changeset
  1566
            JavaFileObject prev = log.useSource(env.enclClass.sym.sourcefile != null ?
06bc494ca11e Initial load
duke
parents:
diff changeset
  1567
                                      env.enclClass.sym.sourcefile :
06bc494ca11e Initial load
duke
parents:
diff changeset
  1568
                                      env.toplevel.sourcefile);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1569
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1570
                JavaFileObject file;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1571
                if (usePrintSource)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1572
                    file = printSource(env, cdef);
12213
516b112d6c68 7150368: javac should include basic ability to generate native headers
jjg
parents: 12016
diff changeset
  1573
                else {
516b112d6c68 7150368: javac should include basic ability to generate native headers
jjg
parents: 12016
diff changeset
  1574
                    if (fileManager.hasLocation(StandardLocation.NATIVE_HEADER_OUTPUT)
516b112d6c68 7150368: javac should include basic ability to generate native headers
jjg
parents: 12016
diff changeset
  1575
                            && jniWriter.needsHeader(cdef.sym)) {
516b112d6c68 7150368: javac should include basic ability to generate native headers
jjg
parents: 12016
diff changeset
  1576
                        jniWriter.write(cdef.sym);
516b112d6c68 7150368: javac should include basic ability to generate native headers
jjg
parents: 12016
diff changeset
  1577
                    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1578
                    file = genCode(env, cdef);
12213
516b112d6c68 7150368: javac should include basic ability to generate native headers
jjg
parents: 12016
diff changeset
  1579
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1580
                if (results != null && file != null)
1355
74cc97efef51 6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents: 1260
diff changeset
  1581
                    results.add(file);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1582
            } catch (IOException ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1583
                log.error(cdef.pos(), "class.cant.write",
06bc494ca11e Initial load
duke
parents:
diff changeset
  1584
                          cdef.sym, ex.getMessage());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1585
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1586
            } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1587
                log.useSource(prev);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1588
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1589
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11867
diff changeset
  1590
            if (!taskListener.isEmpty()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1591
                TaskEvent e = new TaskEvent(TaskEvent.Kind.GENERATE, env.toplevel, cdef.sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1592
                taskListener.finished(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1593
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1594
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1595
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1596
06bc494ca11e Initial load
duke
parents:
diff changeset
  1597
        // where
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 735
diff changeset
  1598
        Map<JCCompilationUnit, Queue<Env<AttrContext>>> groupByFile(Queue<Env<AttrContext>> envs) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1599
            // use a LinkedHashMap to preserve the order of the original list as much as possible
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
  1600
            Map<JCCompilationUnit, Queue<Env<AttrContext>>> map = new LinkedHashMap<>();
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 735
diff changeset
  1601
            for (Env<AttrContext> env: envs) {
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 735
diff changeset
  1602
                Queue<Env<AttrContext>> sublist = map.get(env.toplevel);
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 735
diff changeset
  1603
                if (sublist == null) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
  1604
                    sublist = new ListBuffer<>();
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 735
diff changeset
  1605
                    map.put(env.toplevel, sublist);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1606
                }
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 735
diff changeset
  1607
                sublist.add(env);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1608
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1609
            return map;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1610
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1611
06bc494ca11e Initial load
duke
parents:
diff changeset
  1612
        JCClassDecl removeMethodBodies(JCClassDecl cdef) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1613
            final boolean isInterface = (cdef.mods.flags & Flags.INTERFACE) != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1614
            class MethodBodyRemover extends TreeTranslator {
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1615
                @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1616
                public void visitMethodDef(JCMethodDecl tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1617
                    tree.mods.flags &= ~Flags.SYNCHRONIZED;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1618
                    for (JCVariableDecl vd : tree.params)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1619
                        vd.mods.flags &= ~Flags.FINAL;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1620
                    tree.body = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1621
                    super.visitMethodDef(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1622
                }
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1623
                @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1624
                public void visitVarDef(JCVariableDecl tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1625
                    if (tree.init != null && tree.init.type.constValue() == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1626
                        tree.init = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1627
                    super.visitVarDef(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1628
                }
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1629
                @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1630
                public void visitClassDef(JCClassDecl tree) {
20249
93f8eae31092 6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents: 19921
diff changeset
  1631
                    ListBuffer<JCTree> newdefs = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1632
                    for (List<JCTree> it = tree.defs; it.tail != null; it = it.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1633
                        JCTree t = it.head;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1634
                        switch (t.getTag()) {
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10637
diff changeset
  1635
                        case CLASSDEF:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1636
                            if (isInterface ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  1637
                                (((JCClassDecl) t).mods.flags & (Flags.PROTECTED|Flags.PUBLIC)) != 0 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  1638
                                (((JCClassDecl) t).mods.flags & (Flags.PRIVATE)) == 0 && ((JCClassDecl) t).sym.packge().getQualifiedName() == names.java_lang)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1639
                                newdefs.append(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1640
                            break;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10637
diff changeset
  1641
                        case METHODDEF:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1642
                            if (isInterface ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  1643
                                (((JCMethodDecl) t).mods.flags & (Flags.PROTECTED|Flags.PUBLIC)) != 0 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  1644
                                ((JCMethodDecl) t).sym.name == names.init ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  1645
                                (((JCMethodDecl) t).mods.flags & (Flags.PRIVATE)) == 0 && ((JCMethodDecl) t).sym.packge().getQualifiedName() == names.java_lang)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1646
                                newdefs.append(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1647
                            break;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10637
diff changeset
  1648
                        case VARDEF:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1649
                            if (isInterface || (((JCVariableDecl) t).mods.flags & (Flags.PROTECTED|Flags.PUBLIC)) != 0 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  1650
                                (((JCVariableDecl) t).mods.flags & (Flags.PRIVATE)) == 0 && ((JCVariableDecl) t).sym.packge().getQualifiedName() == names.java_lang)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1651
                                newdefs.append(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1652
                            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1653
                        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1654
                            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1655
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1656
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1657
                    tree.defs = newdefs.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1658
                    super.visitClassDef(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1659
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1660
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1661
            MethodBodyRemover r = new MethodBodyRemover();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1662
            return r.translate(cdef);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1663
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1664
06bc494ca11e Initial load
duke
parents:
diff changeset
  1665
    public void reportDeferredDiagnostics() {
8624
7db12f12a04e 6986892: confusing warning given after errors in annotation processing
jjg
parents: 8623
diff changeset
  1666
        if (errorCount() == 0
7db12f12a04e 6986892: confusing warning given after errors in annotation processing
jjg
parents: 8623
diff changeset
  1667
                && annotationProcessingOccurred
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1668
                && implicitSourceFilesRead
06bc494ca11e Initial load
duke
parents:
diff changeset
  1669
                && implicitSourcePolicy == ImplicitSourcePolicy.UNSET) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1670
            if (explicitAnnotationProcessingRequested())
06bc494ca11e Initial load
duke
parents:
diff changeset
  1671
                log.warning("proc.use.implicit");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1672
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1673
                log.warning("proc.use.proc.or.implicit");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1674
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1675
        chk.reportDeferredDiagnostics();
17582
4079713129dd 8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents: 17578
diff changeset
  1676
        if (log.compressedOutput) {
4079713129dd 8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents: 17578
diff changeset
  1677
            log.mandatoryNote(null, "compressed.diags");
4079713129dd 8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents: 17578
diff changeset
  1678
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1679
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1680
06bc494ca11e Initial load
duke
parents:
diff changeset
  1681
    /** Close the compiler, flushing the logs
06bc494ca11e Initial load
duke
parents:
diff changeset
  1682
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1683
    public void close() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1684
        rootClasses = null;
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24392
diff changeset
  1685
        finder = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1686
        reader = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1687
        make = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1688
        writer = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1689
        enter = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1690
        if (todo != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1691
            todo.clear();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1692
        todo = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1693
        parserFactory = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1694
        syms = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1695
        source = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1696
        attr = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1697
        chk = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1698
        gen = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1699
        flow = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1700
        transTypes = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1701
        lower = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1702
        annotate = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1703
        types = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1704
06bc494ca11e Initial load
duke
parents:
diff changeset
  1705
        log.flush();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1706
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1707
            fileManager.flush();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1708
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1709
            throw new Abort(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1710
        } finally {
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
  1711
            if (names != null)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1712
                names.dispose();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1713
            names = null;
10637
2ea5fbb913ac 7092965: javac should not close processorClassLoader before end of compilation
jjg
parents: 8851
diff changeset
  1714
2ea5fbb913ac 7092965: javac should not close processorClassLoader before end of compilation
jjg
parents: 8851
diff changeset
  1715
            for (Closeable c: closeables) {
2ea5fbb913ac 7092965: javac should not close processorClassLoader before end of compilation
jjg
parents: 8851
diff changeset
  1716
                try {
2ea5fbb913ac 7092965: javac should not close processorClassLoader before end of compilation
jjg
parents: 8851
diff changeset
  1717
                    c.close();
2ea5fbb913ac 7092965: javac should not close processorClassLoader before end of compilation
jjg
parents: 8851
diff changeset
  1718
                } catch (IOException e) {
2ea5fbb913ac 7092965: javac should not close processorClassLoader before end of compilation
jjg
parents: 8851
diff changeset
  1719
                    // When javac uses JDK 7 as a baseline, this code would be
2ea5fbb913ac 7092965: javac should not close processorClassLoader before end of compilation
jjg
parents: 8851
diff changeset
  1720
                    // better written to set any/all exceptions from all the
2ea5fbb913ac 7092965: javac should not close processorClassLoader before end of compilation
jjg
parents: 8851
diff changeset
  1721
                    // Closeables as suppressed exceptions on the FatalError
2ea5fbb913ac 7092965: javac should not close processorClassLoader before end of compilation
jjg
parents: 8851
diff changeset
  1722
                    // that is thrown.
2ea5fbb913ac 7092965: javac should not close processorClassLoader before end of compilation
jjg
parents: 8851
diff changeset
  1723
                    JCDiagnostic msg = diagFactory.fragment("fatal.err.cant.close");
2ea5fbb913ac 7092965: javac should not close processorClassLoader before end of compilation
jjg
parents: 8851
diff changeset
  1724
                    throw new FatalError(msg, e);
2ea5fbb913ac 7092965: javac should not close processorClassLoader before end of compilation
jjg
parents: 8851
diff changeset
  1725
                }
2ea5fbb913ac 7092965: javac should not close processorClassLoader before end of compilation
jjg
parents: 8851
diff changeset
  1726
            }
17551
03f330c02d97 8004082: test/tools/javac/plugin/showtype/Test.java fails on windows: jtreg can't delete plugin.jar
jjg
parents: 16968
diff changeset
  1727
            closeables = List.nil();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1728
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1729
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1730
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1731
    protected void printNote(String lines) {
11053
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
  1732
        log.printRawLines(Log.WriterKind.NOTICE, lines);
2514
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1733
    }
f8929e3790b4 6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents: 2212
diff changeset
  1734
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1735
    /** Print numbers of errors and warnings.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1736
     */
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14801
diff changeset
  1737
    public void printCount(String kind, int count) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1738
        if (count != 0) {
6143
79b7dee406cc 6966732: replace use of static Log.getLocalizedString with non-static alternative where possible
jjg
parents: 6031
diff changeset
  1739
            String key;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1740
            if (count == 1)
6143
79b7dee406cc 6966732: replace use of static Log.getLocalizedString with non-static alternative where possible
jjg
parents: 6031
diff changeset
  1741
                key = "count." + kind;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1742
            else
6143
79b7dee406cc 6966732: replace use of static Log.getLocalizedString with non-static alternative where possible
jjg
parents: 6031
diff changeset
  1743
                key = "count." + kind + ".plural";
11053
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
  1744
            log.printLines(WriterKind.ERROR, key, String.valueOf(count));
11052
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 10950
diff changeset
  1745
            log.flush(Log.WriterKind.ERROR);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1746
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1747
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1748
06bc494ca11e Initial load
duke
parents:
diff changeset
  1749
    private static long now() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1750
        return System.currentTimeMillis();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1751
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1752
06bc494ca11e Initial load
duke
parents:
diff changeset
  1753
    private static long elapsed(long then) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1754
        return now() - then;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1755
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1756
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
  1757
    public void newRound() {
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
  1758
        inputFiles.clear();
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23115
diff changeset
  1759
        todo.clear();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1760
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1761
}