六号线晚报0604

2018-06-05  本文已影响0人  z0nk1n

天气:晴 风力:无风

tools.jar ---> javac

第一次遇到有项目里用到了tools.jar包,稍微研究下。

  1. com.sun.tools.javac.Main main方法点用main包Main类的compile方法编译java文件
    public static void main(String[] arg) throws Exception {
        System.exit(compile(arg));
    }

    public static int compile(String[] arg) {
        com.sun.tools.javac.main.Main arg0 = new com.sun.tools.javac.main.Main("javac");
        return arg0.compile(arg).exitCode;
    }

2.com.sun.tools.javac.main.Main

public Result compile(String[] arg0, String[] arg1, Context arg2, 
        List<JavaFileObject> arg3, Iterable<? extends Processor> arg4) {
       
        //做一些参数的文件判断,日志输出环境等
        //准备compile环境,加载内置插件
        //准备编译类和编译参数
        //编译,arg3, arg4都是空的对象
      ···
      arg5.compile(arg3, this.classnames.toList(), arg4);
      ···
    
    }
   ···
    this.delegateCompiler = this.processAnnotations(
            this.enterTrees(this.stopIfError(CompileState.PARSE, this.parseFiles(arg0))), arg1);
    this.delegateCompiler.compile2();
   ···
public void generate(Queue<Pair<Env<AttrContext>, JCClassDecl>> arg0, Queue<JavaFileObject> arg1) {
     ···
}

暂停睡觉~~~

上一篇 下一篇

猜你喜欢

热点阅读