Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jdt-dev] Re: problem with ASTParser parser = ASTParser.newParser(AST.JLS3);

Right now the JDT/Core plugin needs to be initialize in order to use the 
DOM API.
Add yourself to the CC list of bug 
https://bugs.eclipse.org/bugs/show_bug.cgi?id=87852.

Olivier




zifu yang <zifu.yang@xxxxxxxxx> 
Sent by: jdt-dev-bounces@xxxxxxxxxxx
2005-10-22 17:47
Please respond to
"Eclipse JDT general developers list."


To
jdt-dev@xxxxxxxxxxx
cc

Subject
[jdt-dev] Re: problem with ASTParser parser = 
ASTParser.newParser(AST.JLS3);






I added the library needed for 
"java.lang.NoClassDefFoundError: org/eclipse/core/resources/IResource"
 
However, I got the new error message.  But the program can run in Eclipse 
3.0.      Eclipse 3.1 changed the usage model?
 
Exception in thread "main" java.lang.ExceptionInInitializerError
 at org.eclipse.jdt.core.JavaCore.getOptions(JavaCore.java:2401)
 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)
Caused by: java.lang.NullPointerException
 at 
org.eclipse.jdt.internal.core.search.indexing.IndexManager.getJavaPluginWorkingLocation(IndexManager.java:284)
 at org.eclipse.jdt.internal.core.search.indexing.IndexManager 
.<init>(IndexManager.java:50)
 at 
org.eclipse.jdt.internal.core.JavaModelManager.<init>(JavaModelManager.java:671)
 at 
org.eclipse.jdt.internal.core.JavaModelManager.<clinit>(JavaModelManager.java:649) 

 ... 6 more


 
On 10/22/05, zifu yang <zifu.yang@xxxxxxxxx> wrote: 
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 



-- 
best regards,
Zifu Yang _______________________________________________
jdt-dev mailing list
jdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jdt-dev




Back to the top