java - 如何解决 JLS3 无法解决或不是 Eclipse 中的字段错误?
问题描述
import java.util.Map;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.*;
public class AST {
public static void maain(String arge[]) {
String str = "someString";
char[] source = str.toCharArray();
ASTParser parser = ASTParser.newParser(AST.JLS3); // handles JDK 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6
parser.setSource(source);
// In order to parse 1.5 code, some compiler options need to be set to 1.5
Map options = JavaCore.getOptions();
JavaCore.setComplianceOptions(JavaCore.VERSION_1_5, options);
parser.setCompilerOptions(options);
CompilationUnit result = (CompilationUnit) parser.createAST(null);
}
}
我正在尝试在 Eclipse 中使用 AST PARSER 解析 java 代码。如何解决“JLS3 无法解析或不是字段”错误?
解决方案
您已经调用了您的类AST
,因此编译器正在JLS3
您的AST
类中查找,而不是 JDTorg.eclipse.jdt.core.dom.AST
类。
您可以将您的AST
类重命名为不冲突的名称,也可以使用 JDT 类的全名:
ASTParser.newParser(org.eclipse.jdt.core.dom.AST.JLS3);
推荐阅读
- matlab - 在matlab上调制音频波形时出现矩阵尺寸错误
- c# - 将方法绑定到委托类型 DependencyProperty
- r - 与科学记数法 kableExtra table R markdown html 结合时,十进制后的数字不一致
- php - laravel 的数字格式验证规则
- visual-foxpro - 选择别名未更改为正确的别名
- php - 在嵌套的 if 语句中打破 foreach
- python - uWSGI 最大请求与 Flask (Python) 垃圾收集
- javascript - 我需要把这个选择变成一个复选框
- javascript - 从父域访问在子域上设置的 cookie
- java - 防止数组列表重叠?