]> source.dussan.org Git - aspectj.git/commitdiff
Fix for 157057: expanded EclipseResolvedMember to work for fields as well as methods...
authoraclement <aclement>
Thu, 14 Sep 2006 14:54:19 +0000 (14:54 +0000)
committeraclement <aclement>
Thu, 14 Sep 2006 14:54:19 +0000 (14:54 +0000)
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseResolvedMember.java

index f9ca2c98a18bc408eb345aa5b3e00bdb3d1f5aa5..69f13ce99b0abc213ddfe3d79421b2d1fef61488 100644 (file)
@@ -551,13 +551,14 @@ public class EclipseFactory {
                // AMC these next two lines shouldn't be needed once we sort out generic types properly in the world map
                ResolvedType realDeclaringType = world.resolve(fromBinding(receiverType));
                if (realDeclaringType.isRawType()) realDeclaringType = realDeclaringType.getGenericType();
-               return new ResolvedMemberImpl(
-                       Member.FIELD,
-                       realDeclaringType,
-                       binding.modifiers,
-                       world.resolve(fromBinding(binding.type)),
-                       new String(binding.name),
-                       UnresolvedType.NONE);
+               ResolvedMemberImpl ret =  new EclipseResolvedMember(binding,
+                               Member.FIELD,
+                               realDeclaringType,
+                               binding.modifiers,
+                               world.resolve(fromBinding(binding.type)),
+                               new String(binding.name),
+                               UnresolvedType.NONE);
+               return ret;
        }
        
        public TypeBinding makeTypeBinding(UnresolvedType typeX) {
index 38dca6826e9c50eae3a0d28b5306bdfc811be156..7ea58fa425b8f491010af1f7b494f9c08c142cf1 100644 (file)
@@ -14,13 +14,17 @@ package org.aspectj.ajdt.internal.compiler.lookup;
 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.
@@ -32,37 +36,66 @@ public class EclipseResolvedMember extends ResolvedMemberImpl {
        
        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;
@@ -75,4 +108,25 @@ public class EclipseResolvedMember extends ResolvedMemberImpl {
                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;
+       }
+       
 }