[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-dev] State of AjAST


i fought my way through the current AST of AspectJ and tried to add
pointcuts to aspects by selecting methods in the outline-view. My main
source for this was
https://bugs.eclipse.org/bugs/show_bug.cgi?id=110465 and
org.aspectj.ajdt.core CVS sourcecode and the junit-tests. 

I got all the way down from the selected method to my sample .aj file,
its aspectj sourcecode and the corresponding ast-object. So i can
create the dummy DefaultPointcut, but i can't add it to the
bodyDeclaration of the type. By doing this I get a ClassCastException.

I modified AjASTTest to show the problem. here is what i got:


// helper method
private AjAST createAjAST(int astlevel) {
	AST ast = createCU(AST.JLS3).getAST();
	assertTrue("the ast should be an instance of AjAST",ast instanceof AjAST);
	return (AjAST)ast;
// helper method
private CompilationUnit createCU(int astlevel) {
	if (astlevel != AST.JLS2 && astlevel != AST.JLS3) {
		fail("need to pass AST.JLS2 or AST.JLS3 as an argument");
	String source = "";
	ASTParser parser = ASTParser.newParser(astlevel);
	parser.setCompilerOptions(new HashMap());
	CompilationUnit cu = (CompilationUnit) parser.createAST(null);
	return cu;

public void testAddToAST() {
	CompilationUnit cu = createCU(AST.JLS3);
	AjAST ajast = (AjAST) cu.getAST();
	// aspect
	AspectDeclaration ad = ajast.newAspectDeclaration();
	// method
	MethodDeclaration md = ajast.newMethodDeclaration();
	// pc
	DefaultPointcut p = ajast.newDefaultPointcut();
	ad.bodyDeclarations().add(p); // classcastexception


Am i doing something wrong or is this as far as i can get with the
current state of AST for AspectJ?

thanks for any help on this.