Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-dev] [ajdt structures]

Hello everybody,
  I found in eclipse help (JDT Core > Manipulating Java Code) an
example of how to create an AST from scratch. The example is something
like the one below:

//------------------------------------------------
IDocument doc = new Document("import java.util.List;");
ASTParser parser = ASTParser.newParser(AST.JLS2);
parser.setSource(doc.get().toCharArray());
CompilationUnit cU = (CompilationUnit) parser.createAST(null);
cU.recordModifications();
AST ast = cU.getAST();
	
PackageDeclaration packageDeclaration = ast.newPackageDeclaration();
packageDeclaration.setName(ast.newSimpleName("exemplo"));
cU.setPackage(packageDeclaration);

TypeDeclaration type = ast.newTypeDeclaration();
type.setInterface(false);
type.setModifiers(Modifier.PUBLIC);
type.setName(ast.newSimpleName("HelloWorld"));
cU.types().add(type);

TextEdit edits = cU.rewrite(doc, null);
edits.apply(doc);
//------------------------------------------------

I´d like to do the same thing with the ajdt structures. Any thoughts?

Thanks!

Alexandre


Back to the top