]> source.dussan.org Git - aspectj.git/commitdiff
chewed by formatter
authoraclement <aclement>
Thu, 4 Sep 2008 19:09:30 +0000 (19:09 +0000)
committeraclement <aclement>
Thu, 4 Sep 2008 19:09:30 +0000 (19:09 +0000)
weaver/src/org/aspectj/weaver/patterns/AnnotationPointcut.java

index 365a5154fa376ff13032c0600601bd6e54fea10b..5b58c3fe002ea48aa430d11834d69bec02b282b0 100644 (file)
@@ -46,31 +46,22 @@ import org.aspectj.weaver.bcel.BcelTypeMunger;
 /**
  * @annotation(@Foo) or @annotation(foo)
  * 
- * Matches any join point where the subject of the join point has an
- * annotation matching the annotationTypePattern:
+ *                      Matches any join point where the subject of the join point has an annotation matching the
+ *                      annotationTypePattern:
  * 
- * Join Point Kind          Subject
- * ================================
- * method call              the target method
- * method execution         the method
- * constructor call         the constructor
- * constructor execution    the constructor
- * get                      the target field
- * set                      the target field
- * adviceexecution          the advice
- * initialization           the constructor
- * preinitialization        the constructor
- * staticinitialization     the type being initialized
- * handler                  the declared type of the handled exception
+ *                      Join Point Kind Subject ================================ method call the target method method execution the
+ *                      method constructor call the constructor constructor execution the constructor get the target field set the
+ *                      target field adviceexecution the advice initialization the constructor preinitialization the constructor
+ *                      staticinitialization the type being initialized handler the declared type of the handled exception
  */
 public class AnnotationPointcut extends NameBindingPointcut {
 
        private ExactAnnotationTypePattern annotationTypePattern;
-    private String declarationText; 
-       
+       private String declarationText;
+
        public AnnotationPointcut(ExactAnnotationTypePattern type) {
                super();
-               this.annotationTypePattern =  type;
+               this.annotationTypePattern = type;
                this.pointcutKind = Pointcut.ANNOTATION;
                buildDeclarationText();
        }
@@ -80,21 +71,24 @@ public class AnnotationPointcut extends NameBindingPointcut {
                buildDeclarationText();
        }
 
-    public ExactAnnotationTypePattern getAnnotationTypePattern() {
-        return annotationTypePattern;
-    }
+       public ExactAnnotationTypePattern getAnnotationTypePattern() {
+               return annotationTypePattern;
+       }
 
        public int couldMatchKinds() {
                return Shadow.ALL_SHADOW_KINDS_BITS;
        }
-       
-       public Pointcut parameterizeWith(Map typeVariableMap,World w) {
-               AnnotationPointcut ret = new AnnotationPointcut((ExactAnnotationTypePattern)annotationTypePattern.parameterizeWith(typeVariableMap,w));
+
+       public Pointcut parameterizeWith(Map typeVariableMap, World w) {
+               AnnotationPointcut ret = new AnnotationPointcut((ExactAnnotationTypePattern) annotationTypePattern.parameterizeWith(
+                               typeVariableMap, w));
                ret.copyLocationFrom(this);
                return ret;
        }
-       
-       /* (non-Javadoc)
+
+       /*
+        * (non-Javadoc)
+        * 
         * @see org.aspectj.weaver.patterns.Pointcut#fastMatch(org.aspectj.weaver.patterns.FastMatchInfo)
         */
        public FuzzyBoolean fastMatch(FastMatchInfo info) {
@@ -104,8 +98,10 @@ public class AnnotationPointcut extends NameBindingPointcut {
                        return FuzzyBoolean.MAYBE;
                }
        }
-       
-       /* (non-Javadoc)
+
+       /*
+        * (non-Javadoc)
+        * 
         * @see org.aspectj.weaver.patterns.Pointcut#match(org.aspectj.weaver.Shadow)
         */
        protected FuzzyBoolean matchInternal(Shadow shadow) {
@@ -114,8 +110,8 @@ public class AnnotationPointcut extends NameBindingPointcut {
                ResolvedMember rMember = member.resolve(shadow.getIWorld());
 
                if (rMember == null) {
-                   if (member.getName().startsWith(NameMangler.PREFIX)) {
-                       return FuzzyBoolean.NO;
+                       if (member.getName().startsWith(NameMangler.PREFIX)) {
+                               return FuzzyBoolean.NO;
                        }
                        shadow.getIWorld().getLint().unresolvableMember.signal(member.toString(), getSourceLocation());
                        return FuzzyBoolean.NO;
@@ -124,46 +120,50 @@ public class AnnotationPointcut extends NameBindingPointcut {
                Shadow.Kind kind = shadow.getKind();
                if (kind == Shadow.StaticInitialization) {
                        toMatchAgainst = rMember.getDeclaringType().resolve(shadow.getIWorld());
-               } else if ( (kind == Shadow.ExceptionHandler)) {
+               } else if ((kind == Shadow.ExceptionHandler)) {
                        toMatchAgainst = rMember.getParameterTypes()[0].resolve(shadow.getIWorld());
                } else {
                        toMatchAgainst = rMember;
                        // FIXME asc I'd like to get rid of this bit of logic altogether, shame ITD fields don't have an effective sig attribute
                        // FIXME asc perf cache the result of discovering the member that contains the real annotations
                        if (rMember.isAnnotatedElsewhere()) {
-                         if (kind==Shadow.FieldGet || kind==Shadow.FieldSet) {
-                         List mungers = rMember.getDeclaringType().resolve(shadow.getIWorld()).getInterTypeMungers(); // FIXME asc should include supers with getInterTypeMungersIncludingSupers?
-                         for (Iterator iter = mungers.iterator(); iter.hasNext();) {
-                                       BcelTypeMunger typeMunger = (BcelTypeMunger) iter.next();
-                                       if (typeMunger.getMunger() instanceof NewFieldTypeMunger) {
-                                         ResolvedMember fakerm = typeMunger.getSignature();
-                                         if (fakerm.equals(member)) {
-                                           ResolvedMember ajcMethod = AjcMemberMaker.interFieldInitializer(fakerm,typeMunger.getAspectType());
-                                           ResolvedMember rmm       = findMethod(typeMunger.getAspectType(),ajcMethod);
-                                               toMatchAgainst = rmm;
-                                         }
+                               if (kind == Shadow.FieldGet || kind == Shadow.FieldSet) {
+                                       // FIXME asc should include supers with getInterTypeMungersIncludingSupers ?
+                                       List mungers = rMember.getDeclaringType().resolve(shadow.getIWorld()).getInterTypeMungers();
+                                       for (Iterator iter = mungers.iterator(); iter.hasNext();) {
+                                               BcelTypeMunger typeMunger = (BcelTypeMunger) iter.next();
+                                               if (typeMunger.getMunger() instanceof NewFieldTypeMunger) {
+                                                       ResolvedMember fakerm = typeMunger.getSignature();
+                                                       if (fakerm.equals(member)) {
+                                                               ResolvedMember ajcMethod = AjcMemberMaker.interFieldInitializer(fakerm, typeMunger.getAspectType());
+                                                               ResolvedMember rmm = findMethod(typeMunger.getAspectType(), ajcMethod);
+                                                               toMatchAgainst = rmm;
+                                                       }
+                                               }
                                        }
-                               }       
-                         }
+                               }
                        }
                }
-               
+
                annotationTypePattern.resolve(shadow.getIWorld());
                return annotationTypePattern.matches(toMatchAgainst);
        }
-       
+
        private ResolvedMember findMethod(ResolvedType aspectType, ResolvedMember ajcMethod) {
-              ResolvedMember decMethods[] = aspectType.getDeclaredMethods();
-              for (int i = 0; i < decMethods.length; i++) {
+               ResolvedMember decMethods[] = aspectType.getDeclaredMethods();
+               for (int i = 0; i < decMethods.length; i++) {
                        ResolvedMember member = decMethods[i];
-                       if (member.equals(ajcMethod)) return member;
-                  }
-                       return null;
+                       if (member.equals(ajcMethod))
+                               return member;
                }
-       
+               return null;
+       }
 
-       /* (non-Javadoc)
-        * @see org.aspectj.weaver.patterns.Pointcut#resolveBindings(org.aspectj.weaver.patterns.IScope, org.aspectj.weaver.patterns.Bindings)
+       /*
+        * (non-Javadoc)
+        * 
+        * @see org.aspectj.weaver.patterns.Pointcut#resolveBindings(org.aspectj.weaver.patterns.IScope,
+        * org.aspectj.weaver.patterns.Bindings)
         */
        protected void resolveBindings(IScope scope, Bindings bindings) {
                if (!scope.getWorld().isInJava5Mode()) {
@@ -171,70 +171,75 @@ public class AnnotationPointcut extends NameBindingPointcut {
                                        getSourceLocation()));
                        return;
                }
-               annotationTypePattern = (ExactAnnotationTypePattern) annotationTypePattern.resolveBindings(scope,bindings,true);
+               annotationTypePattern = (ExactAnnotationTypePattern) annotationTypePattern.resolveBindings(scope, bindings, true);
                // must be either a Var, or an annotation type pattern
        }
 
-       /* (non-Javadoc)
+       /*
+        * (non-Javadoc)
+        * 
         * @see org.aspectj.weaver.patterns.Pointcut#concretize1(org.aspectj.weaver.ResolvedType, org.aspectj.weaver.IntMap)
         */
        protected Pointcut concretize1(ResolvedType inAspect, ResolvedType declaringType, IntMap bindings) {
-               ExactAnnotationTypePattern newType = (ExactAnnotationTypePattern) annotationTypePattern.remapAdviceFormals(bindings);           
+               ExactAnnotationTypePattern newType = (ExactAnnotationTypePattern) annotationTypePattern.remapAdviceFormals(bindings);
                Pointcut ret = new AnnotationPointcut(newType, bindings.getEnclosingAdvice());
-        ret.copyLocationFrom(this);
-        return ret;
+               ret.copyLocationFrom(this);
+               return ret;
        }
 
        protected Test findResidueInternal(Shadow shadow, ExposedState state) {
                if (annotationTypePattern instanceof BindingAnnotationFieldTypePattern) {
-                   if (shadow.getKind() != Shadow.MethodExecution) {
-                shadow.getIWorld().getMessageHandler().handleMessage(
-                    MessageUtil.error("Annotation field binding is only supported at method-execution join points (compiler limitation)",
-                        getSourceLocation()));
-                return Literal.TRUE; // exit quickly, error will prevent weaving
-            }
-            BindingAnnotationFieldTypePattern btp = (BindingAnnotationFieldTypePattern) annotationTypePattern;
-            UnresolvedType formalType = btp.getFormalType().resolve(shadow.getIWorld());
-            UnresolvedType annoType = btp.getAnnotationType();
-            // TODO 2 need to sort out appropriate creation of the AnnotationAccessFieldVar - what happens for
-            // reflective (ReflectionShadow) access to types?
-            AnnotationAccessVar var = (AnnotationAccessVar) shadow.getKindedAnnotationVar(annoType);
-            if (var == null) {
-                throw new BCException("Unexpected problem locating annotation at join point '" + shadow + "'");
-            }
-            state.set(btp.getFormalIndex(), new AnnotationAccessFieldVar(var, (ResolvedType) formalType));
-        } else if (annotationTypePattern instanceof BindingAnnotationTypePattern) {
-                       BindingAnnotationTypePattern btp = (BindingAnnotationTypePattern)annotationTypePattern;
+                       if (shadow.getKind() != Shadow.MethodExecution) {
+                               shadow.getIWorld().getMessageHandler().handleMessage(
+                                               MessageUtil.error(
+                                                               "Annotation field binding is only supported at method-execution join points (compiler limitation)",
+                                                               getSourceLocation()));
+                               return Literal.TRUE; // exit quickly, error will prevent weaving
+                       }
+                       BindingAnnotationFieldTypePattern btp = (BindingAnnotationFieldTypePattern) annotationTypePattern;
+                       ResolvedType formalType = btp.getFormalType().resolve(shadow.getIWorld());
+                       UnresolvedType annoType = btp.getAnnotationType();
+                       // TODO 2 need to sort out appropriate creation of the AnnotationAccessFieldVar - what happens for
+                       // reflective (ReflectionShadow) access to types?
+                       AnnotationAccessVar var = (AnnotationAccessVar) shadow.getKindedAnnotationVar(annoType);
+                       if (var == null) {
+                               throw new BCException("Unexpected problem locating annotation at join point '" + shadow + "'");
+                       }
+                       state.set(btp.getFormalIndex(), new AnnotationAccessFieldVar(var, (ResolvedType) formalType));
+               } else if (annotationTypePattern instanceof BindingAnnotationTypePattern) {
+                       BindingAnnotationTypePattern btp = (BindingAnnotationTypePattern) annotationTypePattern;
                        UnresolvedType annotationType = btp.getAnnotationType();
                        Var var = shadow.getKindedAnnotationVar(annotationType);
-                       
-                       // At this point, var *could* be null.  The only reason this could happen (if we aren't failing...)
+
+                       // At this point, var *could* be null. The only reason this could happen (if we aren't failing...)
                        // is if another binding annotation designator elsewhere in the pointcut is going to expose the annotation
-                       // eg.  (execution(* a*(..)) && @annotation(foo)) || (execution(* b*(..)) && @this(foo))
+                       // eg. (execution(* a*(..)) && @annotation(foo)) || (execution(* b*(..)) && @this(foo))
                        // where sometimes @annotation will be providing the value, and sometimes
                        // @this will be providing the value (see pr138223)
-                       
+
                        // If we are here for other indecipherable reasons (it's not the case above...) then
                        // you might want to uncomment this next bit of code to collect the diagnostics
-//                     if (var == null) throw new BCException("Impossible! annotation=["+annotationType+
-//                                                                    "]  shadow=["+shadow+" at "+shadow.getSourceLocation()+
-//                                                                                              "]    pointcut is at ["+getSourceLocation()+"]");
-                       if (var==null) {
-                               if (matchInternal(shadow).alwaysTrue()) 
+                       // if (var == null) throw new BCException("Impossible! annotation=["+annotationType+
+                       // "]  shadow=["+shadow+" at "+shadow.getSourceLocation()+
+                       // "]    pointcut is at ["+getSourceLocation()+"]");
+                       if (var == null) {
+                               if (matchInternal(shadow).alwaysTrue())
                                        return Literal.TRUE;
-                               else 
+                               else
                                        return Literal.FALSE;
                        }
-                       state.set(btp.getFormalIndex(),var);
+                       state.set(btp.getFormalIndex(), var);
                }
-               
-               if (matchInternal(shadow).alwaysTrue()) 
+
+               if (matchInternal(shadow).alwaysTrue())
                        return Literal.TRUE;
-               else 
+               else
                        return Literal.FALSE;
        }
 
-       /* (non-Javadoc)
+       /*
+        * (non-Javadoc)
+        * 
         * @see org.aspectj.weaver.patterns.NameBindingPointcut#getBindingAnnotationTypePatterns()
         */
        public List getBindingAnnotationTypePatterns() {
@@ -242,17 +247,22 @@ public class AnnotationPointcut extends NameBindingPointcut {
                        List l = new ArrayList();
                        l.add(annotationTypePattern);
                        return l;
-               } else return Collections.EMPTY_LIST;
+               } else
+                       return Collections.EMPTY_LIST;
        }
-       
-       /* (non-Javadoc)
+
+       /*
+        * (non-Javadoc)
+        * 
         * @see org.aspectj.weaver.patterns.NameBindingPointcut#getBindingTypePatterns()
         */
        public List getBindingTypePatterns() {
                return Collections.EMPTY_LIST;
        }
-       
-       /* (non-Javadoc)
+
+       /*
+        * (non-Javadoc)
+        * 
         * @see org.aspectj.weaver.patterns.PatternNode#write(java.io.DataOutputStream)
         */
        public void write(DataOutputStream s) throws IOException {
@@ -263,23 +273,24 @@ public class AnnotationPointcut extends NameBindingPointcut {
 
        public static Pointcut read(VersionedDataInputStream s, ISourceContext context) throws IOException {
                AnnotationTypePattern type = AnnotationTypePattern.read(s, context);
-               AnnotationPointcut ret = new AnnotationPointcut((ExactAnnotationTypePattern)type);
+               AnnotationPointcut ret = new AnnotationPointcut((ExactAnnotationTypePattern) type);
                ret.readLocation(context, s);
                return ret;
        }
 
        public boolean equals(Object other) {
-               if (!(other instanceof AnnotationPointcut)) return false;
-               AnnotationPointcut o = (AnnotationPointcut)other;
+               if (!(other instanceof AnnotationPointcut))
+                       return false;
+               AnnotationPointcut o = (AnnotationPointcut) other;
                return o.annotationTypePattern.equals(this.annotationTypePattern);
        }
-    
-    public int hashCode() {
-        int result = 17;
-        result = 37*result + annotationTypePattern.hashCode();
-        return result;
-    }
-       
+
+       public int hashCode() {
+               int result = 17;
+               result = 37 * result + annotationTypePattern.hashCode();
+               return result;
+       }
+
        public void buildDeclarationText() {
                StringBuffer buf = new StringBuffer();
                buf.append("@annotation(");
@@ -288,13 +299,13 @@ public class AnnotationPointcut extends NameBindingPointcut {
                buf.append(")");
                this.declarationText = buf.toString();
        }
-       
+
        public String toString() {
                return this.declarationText;
        }
 
-    public Object accept(PatternNodeVisitor visitor, Object data) {
-        return visitor.visit(this, data);
-    }
+       public Object accept(PatternNodeVisitor visitor, Object data) {
+               return visitor.visit(this, data);
+       }
 
 }