Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] How to get the super AspectElement from a given AspectElement


Thanks Andy, I got it to work now. In case somebody else ever needs something similar, below is some code that could be useful, maybe you could add it to AsmManager. It does a recursive collect, flatten and filter over the entire structure. In my case I call it as follows:

findElementsOfKind (compiler .getModel().getHierarchy().getRoot(),IProgramElement.Kind.ASPECT)

public Set<IProgramElement> findElementsOfKind(IProgramElement container, IProgramElement.Kind kind){
	HashSet<IProgramElement> retval = new HashSet<IProgramElement>();

	if(container.getKind() == kind)
		retval.add(container);
		
	for(Object child : container.getChildren()){
		if (child instanceof IProgramElement){
Set<IProgramElement> grandchildren = findElementsOfKind((IProgramElement)child,kind);
			for(IProgramElement gc : grandchildren)
				retval.add(gc);
		}
	}
	return retval;
}

Note that for my case the recursive collect traverses too deep so this could be optimized, but I prefer to keep it generic.

On 25 Nov 2009, at 16:31, Andy Clement wrote:

AsmManager.getHierarchy().getRoot()... then getChildren() for each
IProgramElement

Andy

2009/11/25 Johan Fabry <jfabry@xxxxxxxxxxxxx>:
Hi Andy,

I'd love to walk over the model and just ask if a type is an aspect. It's just that I dont know how to do this. When trying to find a way the best that I could come up with was via the AsmManager method getHierarchy(), but there I cannot get a hold of the types because the typeMap is private. How
should I walk the model to get the types?

On 25 Nov 2009, at 15:15, Andy Clement wrote:

I can't recall the entire way that structure model works right now.
Why not walk the model and ask which types are aspects?  Surely that
will work? I might even take a patch to change the structure model to provide what you need if you change it to be how you would like it to
be.

cheers,
Andy


--
Johan Fabry
jfabry@xxxxxxxxxxxxx - http://dcc.uchile.cl/~jfabry
PLEIAD Lab - Computer Science Department (DCC) - University of Chile



_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users

--
Johan Fabry
jfabry@xxxxxxxxxxxxx - http://dcc.uchile.cl/~jfabry
PLEIAD Lab - Computer Science Department (DCC) - University of Chile





Back to the top