langtools/src/share/classes/com/sun/tools/apt/main/JavaCompiler.java
author jjg
Thu, 10 Jun 2010 16:08:01 -0700
changeset 5847 1908176fd6e3
parent 5520 86e4b9a9da40
child 6716 71df48777dd1
permissions -rw-r--r--
6944312: Potential rebranding issues in openjdk/langtools repository sources Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3378
diff changeset
     2
 * Copyright (c) 2004, 2009, 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: 3378
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: 3378
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: 3378
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3378
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3378
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.apt.main;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.io.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.util.Map;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import javax.tools.JavaFileManager;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import javax.tools.JavaFileObject;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
731
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 10
diff changeset
    34
import com.sun.tools.javac.file.JavacFileManager;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import com.sun.tools.javac.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
import com.sun.tools.javac.code.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import com.sun.tools.javac.jvm.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
import com.sun.tools.javac.code.Symbol.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
import com.sun.tools.javac.tree.JCTree.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
import com.sun.tools.apt.comp.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
import com.sun.tools.apt.util.Bark;
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
import com.sun.mirror.apt.AnnotationProcessorFactory;
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
import com.sun.tools.javac.parser.DocCommentScanner;
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
/**
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    48
 *  <p><b>This is NOT part of any supported API.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 *  If you write code that depends on this, you do so at your own
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 *  risk.  This code and its internal interfaces are subject to change
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 *  or deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 */
3378
22011d9a9398 6381698: Warn of decommissioning of apt
darcy
parents: 2212
diff changeset
    53
@SuppressWarnings("deprecation")
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
public class JavaCompiler extends com.sun.tools.javac.main.JavaCompiler {
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    /** The context key for the compiler. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
    protected static final Context.Key<JavaCompiler> compilerKey =
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
        new Context.Key<JavaCompiler>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
    /** Get the JavaCompiler instance for this context. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    public static JavaCompiler instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
        JavaCompiler instance = context.get(compilerKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
        if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
            instance = new JavaCompiler(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
    java.util.Set<String> genSourceFileNames;
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    java.util.Set<String> genClassFileNames;
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    public java.util.Set<String> getSourceFileNames() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
        return genSourceFileNames;
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    /** List of names of generated class files.
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
    public java.util.Set<String> getClassFileNames() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
        return genClassFileNames;
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
    java.util.Set<java.io.File> aggregateGenFiles = java.util.Collections.emptySet();
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    public java.util.Set<java.io.File> getAggregateGenFiles() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
        return aggregateGenFiles;
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    /** The bark to be used for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
    Bark bark;
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
    /** The log to be used for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    Log log;
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    /** The annotation framework
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
    Apt apt;
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
    private static Context preRegister(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
        Bark.preRegister(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        // force the use of the scanner that captures Javadoc comments
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
        DocCommentScanner.Factory.preRegister(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        if (context.get(JavaFileManager.class) == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
            JavacFileManager.preRegister(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
        return context;
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    /** Construct a new compiler from a shared context.
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
    public JavaCompiler(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
        super(preRegister(context));
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
        context.put(compilerKey, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
        apt = Apt.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
        ClassReader classReader = ClassReader.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
        classReader.preferSource = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
        // TEMPORARY NOTE: bark==log, but while refactoring, we maintain their
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
        // original identities, to remember the original intent.
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        log = Log.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
        bark = Bark.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
        Options options = Options.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
        classOutput   = options.get("-retrofit")      == null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
        nocompile     = options.get("-nocompile")     != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
        print         = options.get("-print")         != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
        classesAsDecls= options.get("-XclassesAsDecls") != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
        genSourceFileNames = new java.util.LinkedHashSet<String>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
        genClassFileNames  = new java.util.LinkedHashSet<String>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
        // this forces a copy of the line map to be kept in the tree,
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
        // for use by com.sun.mirror.util.SourcePosition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
        lineDebugInfo = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
    /* Switches:
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
    /** Emit class files. This switch is always set, except for the first
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
     *  phase of retrofitting, where signatures are parsed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    public boolean classOutput;
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    /** The internal printing annotation processor should be used.
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
    public boolean print;
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
    /** Compilation should not be done after annotation processing.
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
    public boolean nocompile;
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
    /** Are class files being treated as declarations
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
    public boolean classesAsDecls;
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
    /** Try to open input stream with given name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
     *  Report an error if this fails.
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
     *  @param filename   The file name of the input stream to be opened.
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
    // PROVIDED FOR EXTREME BACKWARDS COMPATIBILITY
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    // There are some very obscure errors that can arise while translating
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
    // the contents of a file from bytes to characters. In Tiger, these
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
    // diagnostics were ignored. This method provides compatibility with
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
    // that behavior. It would be better to honor those diagnostics, in which
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
    // case, this method can be deleted.
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
    @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
    public CharSequence readSource(JavaFileObject filename) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
            inputFiles.add(filename);
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
            boolean prev = bark.setDiagnosticsIgnored(true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
                return filename.getCharContent(false);
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
            finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
                bark.setDiagnosticsIgnored(prev);
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
            bark.error(Position.NOPOS, "cant.read.file", filename);
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
    /** Parse contents of input stream.
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
     *  @param filename     The name of the file from which input stream comes.
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
     *  @param input        The input stream to be parsed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
    // PROVIDED FOR BACKWARDS COMPATIBILITY
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
    // In Tiger, diagnostics from the scanner and parser were ignored.
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
    // This method provides compatibility with that behavior.
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
    // It would be better to honor those diagnostics, in which
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
    // case, this method can be deleted.
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
    @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
    protected JCCompilationUnit parse(JavaFileObject filename, CharSequence content) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
        boolean prev = bark.setDiagnosticsIgnored(true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
            return super.parse(filename, content);
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
        finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
            bark.setDiagnosticsIgnored(prev);
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
    @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
    protected boolean keepComments() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
        return true;  // make doc comments available to mirror API impl.
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
    /** Track when the JavaCompiler has been used to compile something. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
    private boolean hasBeenUsed = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
    /** Main method: compile a list of files, return all compiled classes
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
     *  @param filenames     The names of all files to be compiled.
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
    public List<ClassSymbol> compile(List<String> filenames,
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
                                     Map<String, String> origOptions,
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
                                     ClassLoader aptCL,
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
                                     AnnotationProcessorFactory providedFactory,
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
                                     java.util.Set<Class<? extends AnnotationProcessorFactory> > productiveFactories,
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
                                     java.util.Set<java.io.File> aggregateGenFiles)
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
        throws Throwable {
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
        // as a JavaCompiler can only be used once, throw an exception if
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
        // it has been used before.
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
        assert !hasBeenUsed : "attempt to reuse JavaCompiler";
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
        hasBeenUsed = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
        this.aggregateGenFiles = aggregateGenFiles;
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
        long msec = System.currentTimeMillis();
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
        ListBuffer<ClassSymbol> classes = new ListBuffer<ClassSymbol>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
        try {
1870
57a1138dffc8 6795903: fix latent build warnings in langtools repository
jjg
parents: 735
diff changeset
   237
            JavacFileManager fm = (JavacFileManager)fileManager;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
            //parse all files
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
            ListBuffer<JCCompilationUnit> trees = new ListBuffer<JCCompilationUnit>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
            for (List<String> l = filenames; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
                if (classesAsDecls) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
                    if (! l.head.endsWith(".java") ) { // process as class file
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
                        ClassSymbol cs = reader.enterClass(names.fromString(l.head));
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
                        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
                            cs.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
                        } catch(Symbol.CompletionFailure cf) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
                            bark.aptError("CantFindClass", l);
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
                            continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
                        classes.append(cs); // add to list of classes
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
                        continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
                }
1870
57a1138dffc8 6795903: fix latent build warnings in langtools repository
jjg
parents: 735
diff changeset
   255
                JavaFileObject fo = fm.getJavaFileObjectsFromStrings(List.of(l.head)).iterator().next();
57a1138dffc8 6795903: fix latent build warnings in langtools repository
jjg
parents: 735
diff changeset
   256
                trees.append(parse(fo));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
            //enter symbols for all files
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
            List<JCCompilationUnit> roots = trees.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
            if (errorCount() == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
                boolean prev = bark.setDiagnosticsIgnored(true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
                try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
                    enter.main(roots);
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
                finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
                    bark.setDiagnosticsIgnored(prev);
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
            if (errorCount() == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
                apt.main(roots,
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
                         classes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
                         origOptions, aptCL,
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
                         providedFactory,
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
                         productiveFactories);
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
                genSourceFileNames.addAll(apt.getSourceFileNames());
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
                genClassFileNames.addAll(apt.getClassFileNames());
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
        } catch (Abort ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
        if (verbose)
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
            printVerbose("total", Long.toString(System.currentTimeMillis() - msec));
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
        chk.reportDeferredDiagnostics();
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
        printCount("error", errorCount());
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
        printCount("warn", warningCount());
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
        return classes.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
}