[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [ajdt-dev] Getting annotations from AdviceElement
|
Thank you both for your quick answers. I will try to detail my problem a little bit more:
I'm implementing a IncrementalBuilder and every time a Resource is visited I want to get the Annotations from both methods and advices (not pointcuts). When a resource is a java class I can get annotations from its methods just fine with:
ICompilationUnit cu =
(ICompilationUnit) JavaCore.create(resource);
IType[] types = cu.getTypes();
for (IType type : types) {
IMethod[] methods = type.getMethods();
for (IMethod method : methods) {
IAnnotation[] annotations =
method.getAnnotations();
(....)
}
}
But when I try something similar for Aspects like this:
IFile file = (IFile) resource;
ICompilationUnit cu = AJCompilationUnitManager.INSTANCE.getAJCompilationUnit(file);
ICompilationUnit mappedUnit = AJCompilationUnitManager.mapToAJCompilationUnit(cu);
if (mappedUnit instanceof AJCompilationUnit) {
AJCompilationUnit ajUnit =
(AJCompilationUnit) mappedUnit;
for (IType type : ajUnit.getAllTypes()){
if (type instanceof AspectElement) {
AspectElement aspect = (AspectElement) type;
AdviceElement[] advices = aspect.getAdvice();
for (int i = 0; i < advices.length; i++)
IAnnotation[] annotations = advices[i].getAnnotations();
(....)
}
}
}
}
I always get an empty array. My alternative right now is to use advice.getSource() and extract the annotations with regular expressions but this is a path a didn't want to take.
I'm using AJDT 1.6.0 btw.
Thanks Again,
André