Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » AJDT » How do I acquire AST of an .aj source file?
How do I acquire AST of an .aj source file? [message #595085] Wed, 18 October 2006 22:08
Eclipse UserFriend
Originally posted by:


I have a question about AJDT (or perhaps AJDE) API usage. I need to get
a use it to collect information about binary that get compiled from a
source file, and also source information for a binary type sufficient to
open the relevant source in an editor.

Here is a method that I use for parsing Java sources:

public void parseSource( final IFile sourceFile, final Map
sourceToBinary, final Map binaryToSource, IProgressMonitor monitor ) {
ASTParser parser = ASTParser.newParser( AST.JLS3 );
ICompilationUnit source = ( ICompilationUnit ) JavaCore.create(
sourceFile );
parser.setSource( source );
parser.setResolveBindings( true );
ASTNode ast = parser.createAST( monitor );
ast.accept( new ASTVisitor() {
public boolean visit( TypeDeclaration node ) {
registerType( node.resolveBinding() );
return true;

public boolean visit( AnonymousClassDeclaration node ) {
registerType( node.resolveBinding() );
return true;

private void registerType( ITypeBinding binding ) {
Set binarySet = ( Set ) sourceToBinary.get(
sourceFile.getFullPath() );
if ( binarySet == null ) {
binarySet = new HashSet();
sourceToBinary.put( sourceFile.getFullPath(), binarySet );
binarySet.add( binding.getBinaryName() );
binaryToSource.put( binding.getBinaryName(),
binding.getJavaElement().getHandleIdentifier() );
} );

I was trying to do the same for AspectJ sources but without success. My
first guess was flipping the imports from org.eclipse.ajdt to but it didn't work - I got a
ClassDefNotFound error without detail message inside JavaCore.create(..)
call, presumably during JavaModelManager.<clinit>. Weird, isn't it?

My second attempt involved AJCompilationUnitManager:

AJCompilationUnit source =
AJCompilationUnitManager.INSTANCE.getAJCompilationUnit( sourceFile );
parser.setCompilerOptions( source.getJavaProject().getOptions( true ) );
parser.setSource( source.getContents() );

But it's no good because the bindings don't get resolved. According to
my limited knowledge of JDT it is probably because
parser.setSource(ICompilationUnit) nor parser.setProject(IJavaProject)
were not called. I couldn't to that since AJCompilationUnit implements
ICompilationUnit from org.eclipse.jdt.core and not from

I'll be happy to do my own source digging, but please show me the
direction :)

Thanks in advance,
Previous Topic:OutOfMemoryError
Next Topic:How do I acquire AST of an .aj source file?
Goto Forum:

Current Time: Fri Apr 27 02:56:38 GMT 2018

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

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