From: aclement Date: Mon, 3 Mar 2008 17:24:10 +0000 (+0000) Subject: annotation value matching in decp X-Git-Tag: V1_6_0rc1~71 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2ca87769965dd971e58350e91301105cba94d3fd;p=aspectj.git annotation value matching in decp --- diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseAnnotationConvertor.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseAnnotationConvertor.java index 7bf79afe9..c10639409 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseAnnotationConvertor.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseAnnotationConvertor.java @@ -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()) { diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java index 84c74d190..a87a10f16 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java @@ -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(); diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseResolvedMember.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseResolvedMember.java index 98d75b42a..ad1fc45ec 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseResolvedMember.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseResolvedMember.java @@ -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);