[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[jdt-dev] problem with ASTParser parser = ASTParser.newParser(AST.JLS3);
|
I tested a simple program under Eclipse 3.1.1,
However I got the following error. Can anybody help?
According to the document, the code should run correctly.
The error message indicates
ASTParser parser = ASTParser.newParser(AST.JLS3);
has problem.
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/core/resources/IResource
at org.eclipse.jdt.core.dom.ASTParser.initializeDefaults(ASTParser.java:222)
at org.eclipse.jdt.core.dom.ASTParser
.<init>(ASTParser.java:204)
at org.eclipse.jdt.core.dom.ASTParser.newParser(ASTParser.java:109)
at Test.runtest(Test.java:15)
at Test.main(Test.java:10)
Code:
import org.eclipse.jdt.core.dom.*;
import org.eclipse.jface.text.Document;
import org.eclipse.text.edits.TextEdit;
public class Test{
public static void main(String[] args){
Test t= new Test();
t.runtest();
}
void runtest(){
Document doc = new Document("import java.util.List;\nclass X {}\n");
ASTParser parser =
ASTParser.newParser(AST.JLS3);
parser.setResolveBindings(true);
parser.setSource(doc.get().toCharArray());
CompilationUnit cu = (CompilationUnit) parser.createAST(null);
cu.recordModifications();
AST ast =
cu.getAST();
ImportDeclaration id = ast.newImportDeclaration();
id.setName(ast.newName(new String[] {"java", "util", "Set"}));
cu.imports().add(id); // add import declaration at end
TextEdit edits = cu.rewrite(doc, null);
//UndoEdit undo = edits.apply(document);
}
}
--
best regards,
Zifu Yang