import org.aspectj.org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation;
import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Argument;
+import org.aspectj.org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
+import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.Binding;
+import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
import org.aspectj.weaver.AnnotationX;
import org.aspectj.weaver.ResolvedMemberImpl;
import org.aspectj.weaver.ResolvedType;
import org.aspectj.weaver.UnresolvedType;
+import org.aspectj.weaver.World;
/**
* In the pipeline world, we can be weaving before all types have come through from compilation.
private static String[] NO_ARGS = new String[]{};
- private MethodBinding realBinding;
+ private Binding realBinding;
private String[] argumentNames;
+ private World w;
+ private ResolvedType[] cachedAnnotationTypes;
public EclipseResolvedMember(MethodBinding binding, Kind memberKind, ResolvedType realDeclaringType, int modifiers, UnresolvedType type, String string, UnresolvedType[] types, UnresolvedType[] types2) {
super(memberKind,realDeclaringType,modifiers,type,string,types,types2);
this.realBinding = binding;
+ this.w = realDeclaringType.getWorld();
+ }
+
+ public EclipseResolvedMember(FieldBinding binding, Kind field, ResolvedType realDeclaringType, int modifiers, ResolvedType type, String string, UnresolvedType[] none) {
+ super(field,realDeclaringType,modifiers,type,string,none);
+ this.realBinding = binding;
+ this.w = realDeclaringType.getWorld();
+ }
+
+
+ public boolean hasAnnotation(UnresolvedType ofType) {
+ ResolvedType[] annotationTypes = getAnnotationTypes();
+ if (annotationTypes==null) return false;
+ for (int i = 0; i < annotationTypes.length; i++) {
+ ResolvedType type = annotationTypes[i];
+ if (type.equals(ofType)) return true;
+ }
+ return false;
}
public AnnotationX[] getAnnotations() {
long abits = realBinding.getAnnotationTagBits(); // ensure resolved
- TypeDeclaration typeDecl = ((SourceTypeBinding)realBinding.declaringClass).scope.referenceContext;
- AbstractMethodDeclaration methodDecl = typeDecl.declarationOf(realBinding);
- Annotation[] annos = methodDecl.annotations; // this is what to add
+ Annotation[] annos = getEclipseAnnotations();
if (annos==null) return null;
- return super.getAnnotations();
+ // TODO errr missing in action - we need to implement this! Probably using something like EclipseAnnotationConvertor - itself not finished ;)
+ throw new RuntimeException("not yet implemented - please raise an AJ bug");
+// return super.getAnnotations();
}
public ResolvedType[] getAnnotationTypes() {
- long abits = realBinding.getAnnotationTagBits(); // ensure resolved
- TypeDeclaration typeDecl = ((SourceTypeBinding)realBinding.declaringClass).scope.referenceContext;
- AbstractMethodDeclaration methodDecl = typeDecl.declarationOf(realBinding);
- Annotation[] annos = methodDecl.annotations; // this is what to add
- if (annos==null) return null;
- return super.getAnnotationTypes();
+ if (cachedAnnotationTypes == null) {
+ long abits = realBinding.getAnnotationTagBits(); // ensure resolved
+ Annotation[] annos = getEclipseAnnotations();
+ if (annos==null) {
+ cachedAnnotationTypes = ResolvedType.EMPTY_RESOLVED_TYPE_ARRAY;
+ } else {
+ cachedAnnotationTypes = new ResolvedType[annos.length];
+ for (int i = 0; i < annos.length; i++) {
+ Annotation type = annos[i];
+ cachedAnnotationTypes[i] = w.resolve(UnresolvedType.forSignature(new String(type.resolvedType.signature())));
+ }
+ }
+ }
+ return cachedAnnotationTypes;
}
+
public String[] getParameterNames() {
if (argumentNames!=null) return argumentNames;
- TypeDeclaration typeDecl = ((SourceTypeBinding)realBinding.declaringClass).scope.referenceContext;
- AbstractMethodDeclaration methodDecl = typeDecl.declarationOf(realBinding);
+ TypeDeclaration typeDecl = getTypeDeclaration();
+ AbstractMethodDeclaration methodDecl = typeDecl.declarationOf((MethodBinding)realBinding);
Argument[] args = (methodDecl==null?null:methodDecl.arguments); // dont like this - why isnt the method found sometimes? is it because other errors are being reported?
if (args==null) {
argumentNames=NO_ARGS;
return argumentNames;
}
+ private Annotation[] getEclipseAnnotations() {
+ if (realBinding instanceof MethodBinding) {
+ AbstractMethodDeclaration methodDecl = getTypeDeclaration().declarationOf((MethodBinding)realBinding);
+ return methodDecl.annotations;
+ } else if (realBinding instanceof FieldBinding) {
+ FieldDeclaration fieldDecl = getTypeDeclaration().declarationOf((FieldBinding)realBinding);
+ return fieldDecl.annotations;
+ }
+ return null;
+ }
+
+ private TypeDeclaration getTypeDeclaration() {
+ if (realBinding instanceof MethodBinding) {
+ return ((SourceTypeBinding)((MethodBinding)realBinding).declaringClass).scope.referenceContext;
+
+ } else if (realBinding instanceof FieldBinding) {
+ return ((SourceTypeBinding)((FieldBinding)realBinding).declaringClass).scope.referenceContext;
+ }
+ return null;
+ }
+
}