Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Abstract syntax tree
Abstract syntax tree [message #519142] Sun, 07 March 2010 01:38 Go to next message
Eclipse UserFriend
Hello

I would like to use the Abstract syntax tree of eclipse in order to count the number of methods, casts, etc in java classes

but until now, I'm not able to run any example using the AST
I would like to run the following example:

package astexplorer;
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(ASTParser.K_COMPILATION_UNIT);
  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);
 }

}


first, I found problems to know what jars I have to include to my project.
then, I added the following jars :
aspectjtools-1.2.jar
core-3.2.0.658.jar
eclipse-jface-2.1.0.jar
swt.jar

but I still have problems with
mpilationUnit) parser.createAST(null);
  

and

cu.rewrite(doc, null)


I've got a compilation error indicating that the methods are undefined for the type CompilationUnit

Could you indicate to me if I added the right jars and if I have to do other thigs in order to use The AST of eclipse.
thank you
Re: Abstract syntax tree [message #519392 is a reply to message #519142] Mon, 08 March 2010 12:25 Go to previous message
Eclipse UserFriend
You need more than that.
The best way to know what jars you need is to select org.eclipse.jdt.core inside a launching configuration and click on Add required bundles.
That way you should get a list of all bundles required to run the org.eclipse.jdt.core bundle.
--
Olivier
Previous Topic:runnable jar cannot load persistence.xml
Next Topic:How do I update the jar in a "Plugin project for existing jar archive" ?
Goto Forum:
  


Current Time: Tue Apr 15 00:43:23 EDT 2025

Powered by FUDForum. Page generated in 0.02112 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top