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