Main中的main方法是javac的入口。
main中內(nèi)容很少,只有兩段分支代碼
if (args.length > 0 && args[0].equals("-Xjdb")) {
//....
} else{
System.exit(compile(args));
}
使用javac -Xjdb時(shí)會(huì)進(jìn)入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 類的對(duì)象(其實(shí)是構(gòu)建了一個(gè)編譯器實(shí)例),調(diào)用其compile方法,并把編譯時(shí)獲取的參數(shù)傳遞過(guò)去。
后面需要進(jìn)入com.sun.tools.javac.main.Main繼續(xù)跟蹤了。
main中內(nèi)容很少,只有兩段分支代碼
if (args.length > 0 && args[0].equals("-Xjdb")) {
//....
} else{
System.exit(compile(args));
}
使用javac -Xjdb時(shí)會(huì)進(jìn)入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 類的對(duì)象(其實(shí)是構(gòu)建了一個(gè)編譯器實(shí)例),調(diào)用其compile方法,并把編譯時(shí)獲取的參數(shù)傳遞過(guò)去。
后面需要進(jìn)入com.sun.tools.javac.main.Main繼續(xù)跟蹤了。

