problem with ASTParser parser = ASTParser.newParser(AST.JLS3);

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

problem with ASTParser parser = ASTParser.newParser(AST.JLS3);

zifu yang
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

_______________________________________________
jdt-dev mailing list
[hidden email]
https://dev.eclipse.org/mailman/listinfo/jdt-dev
Reply | Threaded
Open this post in threaded view
|

Re: problem with ASTParser parser = ASTParser.newParser(AST.JLS3);

zifu yang
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 <[hidden email]> 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
[hidden email]
https://dev.eclipse.org/mailman/listinfo/jdt-dev
Reply | Threaded
Open this post in threaded view
|

Re: Re: problem with ASTParser parser = ASTParser.newParser(AST.JLS3);

Olivier Thomann
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 <[hidden email]>
Sent by: [hidden email]
2005-10-22 17:47
Please respond to
"Eclipse JDT general developers list."


To
[hidden email]
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 <[hidden email]> 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
[hidden email]
https://dev.eclipse.org/mailman/listinfo/jdt-dev


_______________________________________________
jdt-dev mailing list
[hidden email]
https://dev.eclipse.org/mailman/listinfo/jdt-dev