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