⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 javacompiler.java

📁 java编译器gjc源码 java编译环境
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/** * @(#)JavaCompiler.java	1.44 03/01/23 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package com.sun.tools.javac.v8;import java.io.*;import com.sun.tools.javac.v8.util.*;import com.sun.tools.javac.v8.code.*;import com.sun.tools.javac.v8.tree.*;import com.sun.tools.javac.v8.parser.*;import com.sun.tools.javac.v8.comp.*;import com.sun.tools.javac.v8.code.Symbol.*;import com.sun.tools.javac.v8.tree.Tree.*;/** * This class could be the main entry point for GJC when GJC is used as a *  component in a larger software system. It provides operations to *  construct a new compiler, and to run a new compiler on a set of source *  files. */public class JavaCompiler implements ClassReader.SourceCompleter {    private static final Context.Key compilerKey = new Context.Key();    /**     * The current version number as a string.     */    public static String version() {        return System.getProperty("java.version");    }    /**      * The log to be used for error reporting.      */    private Log log;    /**     * The tree factory module.     */    private TreeMaker make;    /**     * The class reader.     */    private ClassReader reader;    /**     * The class writer.     */    ClassWriter writer;    /**     * The module for the symbol table entry phases.     */    private Enter enter;    /**     * The module for code generation.     */    private Gen gen;    /**     * The name table.     */    private Name.Table names;    /**     * Save the context.     */    private Context context;    /**     * Construct a new compiler from a log, a symbol table and an options table.     */    public JavaCompiler(Context context) {        super();        context.put(compilerKey, this);        this.context = context;        names = Name.Table.instance(context);        log = Log.instance(context);        reader = ClassReader.instance(context);        make = TreeMaker.instance(context);        writer = ClassWriter.instance(context);        enter = Enter.instance(context);        todo = Todo.instance(context);        reader.sourceCompleter = this;        Options options = Options.instance(context);        verbose = options.get("-verbose") != null;        sourceOutput = options.get("-s") != null;        classOutput = options.get("-retrofit") == null;        printFlat = options.get("-printflat") != null;        deprecation = options.get("-deprecation") != null;        warnunchecked = options.get("-warnunchecked") != null;        attrParseOnly = options.get("-attrparseonly") != null;        encoding = (String) options.get("-encoding");        genCrt = options.get("-Xjcov") != null;    }    /**      * Construct a new compiler.      *  This will create a new symbol table module.      */    public static JavaCompiler make(Context context) {        try {            Symtab syms = Symtab.instance(context);        } catch (CompletionFailure ex) {            Log log = Log.instance(context);            log.error(Position.NOPOS, ex.getMessage());            return null;        }        return new JavaCompiler(context);    }    /**      * Verbose output.      */    public boolean verbose;    /**     * Emit plain Java source files rather than class files.     */    public boolean sourceOutput;    /**     * Generate attributed parse tree only.     */    public boolean attrParseOnly;    /**     * Emit class files. This switch is always set, except for the first     *  phase of retrofitting, where signatures are parsed.     */    public boolean classOutput;    /**     * Debug switch: Emit Java sources after inner class flattening.     */    public boolean printFlat;    /**     * Give detailed deprecation warnings.     */    public boolean deprecation;    /**     * Give detailed unchecked warnings.     */    public boolean warnunchecked;    /**     * Generate the CharacterRangeTable.     */    public boolean genCrt;    /**     * The encoding to be used for source input.     */    public String encoding;    /**     * A queue of all as yet unattributed classes.     */    private Todo todo;    /**     * The set of currently compiled inputfiles, needed to ensure     *  we don't accidentally overwrite an input file when -s is set.     *  initialized by `compile'.     */    Set inputFiles = Set.make();    /**     * The number of errors reported so far.     */    public int errorCount() {        return log.nerrors;    }    /**      * Try to open input stream with given name.      *  Report an error if this fails.      *  @param filename   The file name of the input stream to be opened.      */    public InputStream openSource(String filename) {        try {            File f = new File(filename);            inputFiles.put(f);            return new FileInputStream(f);        } catch (IOException e) {            log.error(Position.NOPOS, "cant.read.file", filename);            return null;        }    }    /**      * Parse contents of input stream.      *  @param filename     The name of the file from which input stream comes.      *  @param input        The input stream to be parsed.      */    public TopLevel parse(String filename, InputStream input) {        long msec = System.currentTimeMillis();        Name prev = log.useSource(names.fromString(filename));        TopLevel tree = make.TopLevel(null, Tree.emptyList);        if (input != null) {            if (verbose) {                printVerbose("parsing.started", filename);            }            try {                Scanner scanner = new Scanner(context, input, encoding);                input.close();                Parser parser = new Parser(context, scanner, keepComments(), genCrt);                tree = parser.compilationUnit();                if (verbose) {                    printVerbose("parsing.done",                            Long.toString(System.currentTimeMillis() - msec));                }            } catch (IOException e) {                log.error(Position.NOPOS, "error.reading.file", filename,                        e.toString());            }        }        log.useSource(prev);        tree.sourcefile = names.fromString(filename);        return tree;    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -