ASTParser 手动设置环境

ASTParser setting Environment manually

我正在尝试在 eclipse 插件之外使用 JDT 的 ASTParser,这意味着我无法通过 Java 模型(IProjectICompilationUnit 等)。相反,我需要使用 ASTParser.setEnvironment(classpathEntries, sourcepathEntries, encoding, includeVMPath)。理论上应该没问题,但我无法使源路径和类路径正常工作。

这些参数究竟采用了哪些参数?我假设类路径的 JAR 的绝对路径,以及所有源 (.java) 文件的绝对路径。但是,以下不起作用(以下错误):

public static void main(String[] args) {
    String[] sourceFilePaths = new String[] {"C:\Users\Aljoscha\Desktop\workspaceba\ExampleProject\src\examplepackage\ExampleClass.java"};

    String[] classpathEntries = new String[] {"C:\Program Files\Java\jdk1.8.0_31\src.zip"};
    String[] sourcepathEntries = new String[] {"C:\Users\Aljoscha\Desktop\workspaceba\ExampleProject\src\examplepackage\ExampleClass.java"};

    ASTParser parser = ASTParser.newParser(AST.JLS8);
    parser.setResolveBindings(true);
    parser.setBindingsRecovery(true);
    parser.setEnvironment(classpathEntries, sourcepathEntries, null, false);

    MyFileASTRequestor requestor = new MyFileASTRequestor();

    parser.createASTs(sourceFilePaths, null, null, requestor, null);
}

这给了我以下错误:

Exception in thread "main" java.lang.IllegalStateException: invalid environment settings
at org.eclipse.jdt.core.dom.ASTParser.getClasspath(ASTParser.java:261)
at org.eclipse.jdt.core.dom.ASTParser.createASTs(ASTParser.java:993)
at asg.Foo.main(Foo.java:22)

有谁知道要传递给 setEnvironment() 函数的内容吗?

classpathEntriessourcepathEntries 应该是文件夹,JAR或者ZIP。

顺便说一句,parser.createASTs(...)的参数bindingKeys不能是null