]> source.dussan.org Git - aspectj.git/commitdiff
annotation value matching in decp
authoraclement <aclement>
Mon, 3 Mar 2008 17:24:10 +0000 (17:24 +0000)
committeraclement <aclement>
Mon, 3 Mar 2008 17:24:10 +0000 (17:24 +0000)
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseAnnotationConvertor.java
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 7bf79afe9ca0f06ddaeab8ed0cf0a310484802e4..c10639409654cb76dbf60619e4587d1fc5651d27 100644 (file)
@@ -11,6 +11,8 @@
  * ******************************************************************/
 package org.aspectj.ajdt.internal.compiler.lookup;
 
+import org.aspectj.apache.bcel.classfile.annotation.ElementValue;
+import org.aspectj.apache.bcel.classfile.annotation.SimpleElementValue;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayInitializer;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression;
@@ -20,6 +22,8 @@ import org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.SingleNameReference;
 import org.aspectj.org.eclipse.jdt.internal.compiler.impl.Constant;
+import org.aspectj.org.eclipse.jdt.internal.compiler.impl.IntConstant;
+import org.aspectj.org.eclipse.jdt.internal.compiler.impl.BooleanConstant;
 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.TagBits;
@@ -31,6 +35,7 @@ import org.aspectj.weaver.AnnotationX;
 import org.aspectj.weaver.ArrayAnnotationValue;
 import org.aspectj.weaver.EnumAnnotationValue;
 import org.aspectj.weaver.ResolvedType;
+import org.aspectj.weaver.SimpleAnnotationValue;
 import org.aspectj.weaver.World;
 
 // not yet used...
@@ -119,6 +124,10 @@ public class EclipseAnnotationConvertor {
                                }
                        } else {
                                if (constant != null && constant != Constant.NotAConstant) {
+                                       if (constant instanceof IntConstant || constant instanceof BooleanConstant) {
+                                               AnnotationValue av = generateElementValueForConstantExpression(defaultValue, defaultValueBinding);
+                                               return av;
+                                       }
                                        throw new MissingImplementationException(
                                                    "Please raise an AspectJ bug.  AspectJ does not know how to convert this annotation value ["+defaultValue+"]");
 //                                     generateElementValue(attributeOffset, defaultValue, constant, memberValuePairReturnType.leafComponentType());
@@ -130,6 +139,20 @@ public class EclipseAnnotationConvertor {
                }
        }
        
+       private static AnnotationValue generateElementValueForConstantExpression(Expression defaultValue, TypeBinding defaultValueBinding) {
+               if (defaultValueBinding != null) {
+                       Constant c = defaultValue.constant;
+                       if (c instanceof IntConstant) {
+                               IntConstant iConstant = (IntConstant)c;
+                               return new SimpleAnnotationValue(ElementValue.PRIMITIVE_INT,new Integer(iConstant.intValue()));
+                       } else if (c instanceof BooleanConstant) {
+                               BooleanConstant iConstant = (BooleanConstant)c;
+                               return new SimpleAnnotationValue(ElementValue.PRIMITIVE_BOOLEAN,new Boolean(iConstant.booleanValue()));
+                       }
+               }
+               return null;
+       }
+       
        private static AnnotationValue generateElementValueForNonConstantExpression(Expression defaultValue, TypeBinding defaultValueBinding) {
                if (defaultValueBinding != null) {
                        if (defaultValueBinding.isEnum()) {
index 84c74d1903c7551b9e935d834aaad6e9127ab26a..a87a10f16c41b4bc66d4ebe046f94191b3e1c7b9 100644 (file)
@@ -528,7 +528,7 @@ public class EclipseFactory {
                        fromBinding(binding.returnType),
                        new String(binding.selector),
                        fromBindings(binding.parameters),
-                       fromBindings(binding.thrownExceptions)
+                       fromBindings(binding.thrownExceptions),this
                        );
                if (binding.isVarargs()) {
                        ret.setVarargsMethod();
index 98d75b42af4374257697113f29a00fddc850bd76..ad1fc45ec04fa34c1a8dc994c2f8be6c02918334 100644 (file)
@@ -43,10 +43,12 @@ public class EclipseResolvedMember extends ResolvedMemberImpl {
        private String[] argumentNames;
        private World w;
        private ResolvedType[] cachedAnnotationTypes;
+       private EclipseFactory eclipseFactory;
        
-       public EclipseResolvedMember(MethodBinding binding, Kind memberKind, ResolvedType realDeclaringType, int modifiers, UnresolvedType type, String string, UnresolvedType[] types, UnresolvedType[] types2) {
+       public EclipseResolvedMember(MethodBinding binding, Kind memberKind, ResolvedType realDeclaringType, int modifiers, UnresolvedType type, String string, UnresolvedType[] types, UnresolvedType[] types2, EclipseFactory eclipseFactory) {
                super(memberKind,realDeclaringType,modifiers,type,string,types,types2);
                this.realBinding = binding;
+               this.eclipseFactory = eclipseFactory;
                this.w = realDeclaringType.getWorld();
        }
 
@@ -76,6 +78,22 @@ public class EclipseResolvedMember extends ResolvedMemberImpl {
 //             return super.getAnnotations();
        }
        
+
+       public AnnotationX getAnnotationOfType(UnresolvedType ofType) {
+               long abits = realBinding.getAnnotationTagBits(); // ensure resolved
+               Annotation[] annos = getEclipseAnnotations();
+               if (annos==null) return null;
+               for (int i = 0; i < annos.length; i++) {
+                       Annotation anno = annos[i];
+                       UnresolvedType ut = UnresolvedType.forSignature(new String(anno.resolvedType.signature()));
+                       if (w.resolve(ut).equals(ofType)) {
+                               // Found the one
+                               return EclipseAnnotationConvertor.convertEclipseAnnotation(anno,w,eclipseFactory);
+                       }
+               }
+               return null;
+       }
+       
        public String getAnnotationDefaultValue() {
                if (realBinding instanceof MethodBinding) {
                        AbstractMethodDeclaration methodDecl = getTypeDeclaration().declarationOf((MethodBinding)realBinding);