且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Eclipse JDT ASTParser转换枚举声明节点不正确

更新时间:2023-01-09 10:10:24

当您回答自己时,您必须将编译器版本设置为一个较新的一个,因为默认值是1.3

As you answered yourself you have to set compiler version to a newer one because the default one is 1.3

Map options = JavaCore.getOptions();
System.out.println(options.get(JavaCore.COMPILER_SOURCE)); //outputs 1.3

但是(我认为)枚举声明只添加在1.5中,所以你必须设置它到1.5以上。另外我相信只需设置 COMPILER_SOURCE

However (I think) enum declaration was added only in 1.5 so you have to set it to 1.5 or above. Also I believe it's enough to set only COMPILER_SOURCE

Map options = JavaCore.getOptions();
options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); //or newer version
parser.setCompilerOptions(options);