[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[jdt-dev] problem with ASTParser parser = ASTParser.newParser(AST.JLS3);
|
- From: zifu yang <zifu.yang@xxxxxxxxx>
- Date: Sat, 22 Oct 2005 16:14:06 -0500
- Delivered-to: jdt-dev@eclipse.org
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type; b=SpEUAx6YRv23F/UikVc6jfZ6I97tAnql+b0jGIit31d3uU/cYM9Rwo1zuquHuTOs8lqpbgAwWfFgbXHdX9kQg1cVYJR8Hz5uoUIDWfsQ6amGk+1w98IR5FAMHs8WQqtOZP1t1S3KlDJ9TLUmuXCxJMIPmBELrtxBBBnGm/5AOao=
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