From: aclement Date: Mon, 31 Jan 2005 13:21:53 +0000 (+0000) Subject: Annotation Binding: works for @target and @annotation (when combined with call/execut... X-Git-Tag: Root_AspectJ5_Development~11 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=258675f5f4b3aeac9dce29937ed052e91dcdf8c5;p=aspectj.git Annotation Binding: works for @target and @annotation (when combined with call/execution, others to follow..) --- diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java b/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java index 3a738cd26..142ac4d9a 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java @@ -904,7 +904,11 @@ public class BcelShadow extends Shadow { throw new IllegalStateException("no target"); } initializeTargetAnnotationVars(); - return (Var) targetAnnotationVars.get(forAnnotationType); + Var v =(Var) targetAnnotationVars.get(forAnnotationType); + // Even if we can't find one, we have to return one as we might have this annotation at runtime + if (v==null) + v = new TypeAnnotationAccessVar(forAnnotationType.resolve(world),(BcelVar)getTargetVar()); + return v; } public Var getArgVar(int i) { initializeArgVars(); @@ -1278,6 +1282,11 @@ public class BcelShadow extends Shadow { targetAnnotationVars = thisAnnotationVars; } else { targetAnnotationVars = new HashMap(); + ResolvedTypeX[] rtx = this.getTargetType().resolve(world).getAnnotationTypes(); // what about annotations we havent gotten yet but we will get in subclasses? + for (int i = 0; i < rtx.length; i++) { + ResolvedTypeX typeX = rtx[i]; + targetAnnotationVars.put(typeX,new TypeAnnotationAccessVar(typeX,(BcelVar)getTargetVar())); + } // populate. } } @@ -1298,6 +1307,55 @@ public class BcelShadow extends Shadow { // Then create one BcelVar entry in the map for each annotation, keyed by // annotation type (TypeX). + // !!! Refactor these once all shadow kinds added - there is lots of commonality + if (getKind() == Shadow.MethodCall) { + ResolvedMember rm[] = this.getTargetType().getDeclaredMethods(world); + ResolvedMember found = null; + String searchString = getSignature().getName()+getSignature().getParameterSignature(); + for (int i = 0; i < rm.length; i++) { + ResolvedMember member = rm[i]; + if ((member.getName()+member.getParameterSignature()).equals(searchString)) { + found = member; + } + } + ResolvedTypeX[] anns = found.getAnnotationTypes(); + for (int i = 0; i < anns.length; i++) { + ResolvedTypeX typeX = anns[i]; + kindedAnnotationVars.put(typeX,new KindedAnnotationAccessVar(typeX.resolve(world),(BcelVar)getTargetVar(),getSignature())); + } + } + if (getKind() == Shadow.MethodExecution) { + ResolvedMember rm[] = this.getTargetType().getDeclaredMethods(world); + ResolvedMember found = null; + String searchString = getSignature().getName()+getSignature().getParameterSignature(); + for (int i = 0; i < rm.length; i++) { + ResolvedMember member = rm[i]; + if ((member.getName()+member.getParameterSignature()).equals(searchString)) { + found = member; + } + } + ResolvedTypeX[] anns = found.getAnnotationTypes(); + for (int i = 0; i < anns.length; i++) { + ResolvedTypeX typeX = anns[i]; + kindedAnnotationVars.put(typeX,new KindedAnnotationAccessVar(typeX.resolve(world),(BcelVar)getTargetVar(),getSignature())); + } + } +// if (getKind() == Shadow.FieldSet) { +// ResolvedMember rm[] = this.getTargetType().getDeclaredFields(world); +// ResolvedMember found = null; +// for (int i = 0; i < rm.length; i++) { +// ResolvedMember member = rm[i]; +// if ((member.getName()+member.getParameterSignature()).equals(getSignature().getName()+getSignature().getParameterSignature())) { +// found = member; +// } +// } +// ResolvedTypeX[] anns = found.getAnnotationTypes(); +// for (int i = 0; i < anns.length; i++) { +// ResolvedTypeX typeX = anns[i]; +// kindedAnnotationVars.put(typeX,new KindedAnnotationAccessVar(typeX.resolve(world),(BcelVar)getTargetVar(),getSignature())); +// } +// } + } public void initializeWithinAnnotationVars() { if (withinAnnotationVars != null) return;