* ******************************************************************/
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;
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;
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...
}
} 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());
}
}
+ 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()) {
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();
}
// 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);