在我的代码中,我打开我的file.java并用JavaParser解析他。
FileInputStream in = new FileInputStream(".../file.java");
CompilationUnit cu;
try {
// parse the file
cu = JavaParser.parse(in);
} finally {
in.close();
}
........
文件.java:
public class File{
public void ownMethod(){...}
public static void main(String[] args){
ownMethod(5); //Note the extra parameter
}
}
在file.java中有一个错误:该方法main
调用该方法ownMethod
有一个参数,但ownMethod
期望0个参数。JavaParser 未检测到此错误并使用此错误解析 file.java。我怎么知道(在我的代码中)file.java 是否没有错误?不使用java编译器是否可行?