java從com.sun.tools.javac.Main開始

字號:

Main中的main方法是javac的入口。
    main中內(nèi)容很少,只有兩段分支代碼
    if (args.length > 0 && args[0].equals("-Xjdb")) {
    //....
    } else{
    System.exit(compile(args));
    }
    使用javac -Xjdb時會進入if部分,和調(diào)試有關(guān),暫且不去管它,直接考慮else部分即可。
    compile(args)是真正執(zhí)行編譯功能的地方。
    public static int compile(String[] args) {
    com.sun.tools.javac.main.Main compiler =
    new com.sun.tools.javac.main.Main("javac");
    return compiler.compile(args);
    }
    創(chuàng)建com.sun.tools.javac.main.Main 類的對象(其實是構(gòu)建了一個編譯器實例),調(diào)用其compile方法,并把編譯時獲取的參數(shù)傳遞過去。
    后面需要進入com.sun.tools.javac.main.Main繼續(xù)跟蹤了。