我想检测有关导入语句的错误。但编译单元似乎检测到类声明本身内部的错误。
我正在试验的代码如下:
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import org.apache.commons.*;
public class Bad {
Random r1 = new Random();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
int x = new Random().nextInt(3);
double y = new Random().nextDouble();
int z = 10
}
我没有在我的项目中添加 apache commons。我可以在我的 astview 中看到两个错误,如下所示。
1) E[90, 10] The import org.apache cannot be resolved
2)E[323, 2] Syntax error, insert ";" to complete FieldDeclaration
但是当我尝试打印使用CompilationUnit
它的问题数量时,它只返回一个,消息如下
1)Syntax error, insert ";" to complete FieldDeclaration
如何使用编译单元以编程方式获取导入错误?或者有什么办法我可以做到这一点?提前致谢。