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 User
Originally posted by: Rafal.Krzewski.caltha.pl

Hello,

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
org.aspectj.org.eclipse.ajdt 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
org.aspectj.org.eclipse.jdt.core

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

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


Current Time: Fri Oct 31 10:55:55 GMT 2014

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

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