diff options
author | aclement <aclement> | 2008-12-10 19:15:12 +0000 |
---|---|---|
committer | aclement <aclement> | 2008-12-10 19:15:12 +0000 |
commit | 1fe66be046de4b3c13fdd40509ebd94fb13a5ae8 (patch) | |
tree | 99d5fafbf903a849492207a1bec3d2db758acd96 /org.aspectj.matcher/src | |
parent | 0e2298a8c7cf0b6c8baef5900d77dc28ff3e19ba (diff) | |
download | aspectj-1fe66be046de4b3c13fdd40509ebd94fb13a5ae8.tar.gz aspectj-1fe66be046de4b3c13fdd40509ebd94fb13a5ae8.zip |
more tests
Diffstat (limited to 'org.aspectj.matcher/src')
4 files changed, 509 insertions, 313 deletions
diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/internal/tools/StandardPointcutExpressionImpl.java b/org.aspectj.matcher/src/org/aspectj/weaver/internal/tools/StandardPointcutExpressionImpl.java index 2459366f0..1e9043752 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/internal/tools/StandardPointcutExpressionImpl.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/internal/tools/StandardPointcutExpressionImpl.java @@ -10,9 +10,7 @@ package org.aspectj.weaver.internal.tools; import java.lang.reflect.Constructor; -import java.lang.reflect.Field; import java.lang.reflect.Member; -import java.lang.reflect.Method; import org.aspectj.weaver.ResolvedMember; import org.aspectj.weaver.ResolvedType; @@ -35,9 +33,8 @@ import org.aspectj.weaver.patterns.ThisOrTargetPointcut; import org.aspectj.weaver.patterns.WithinAnnotationPointcut; import org.aspectj.weaver.patterns.WithinCodeAnnotationPointcut; import org.aspectj.weaver.reflect.ReflectionFastMatchInfo; -import org.aspectj.weaver.reflect.ReflectionShadow; -import org.aspectj.weaver.reflect.ShadowMatchImpl; import org.aspectj.weaver.reflect.StandardShadow; +import org.aspectj.weaver.reflect.StandardShadowMatchImpl; import org.aspectj.weaver.tools.DefaultMatchingContext; import org.aspectj.weaver.tools.MatchingContext; import org.aspectj.weaver.tools.PointcutParameter; @@ -93,179 +90,181 @@ public class StandardPointcutExpressionImpl implements StandardPointcutExpressio return new ExposedState(parameters.length); } - public ShadowMatch matchesMethodExecution(Method aMethod) { - return matchesExecution(aMethod); - } + // public ShadowMatch matchesMethodExecution(Method aMethod) { + // return matchesExecution(aMethod); + // } public ShadowMatch matchesMethodExecution(ResolvedMember aMethod) { return matchesExecution(aMethod); } public ShadowMatch matchesConstructorExecution(Constructor aConstructor) { - return matchesExecution(aConstructor); + return null; + // return matchesExecution(aConstructor); } - private ShadowMatch matchesExecution(Member aMember) { - Shadow s = ReflectionShadow.makeExecutionShadow(world, aMember, this.matchContext); - ShadowMatchImpl sm = getShadowMatch(s); - sm.setSubject(aMember); - sm.setWithinCode(null); - sm.setWithinType(aMember.getDeclaringClass()); - return sm; - } + // private ShadowMatch matchesExecution(Member aMember) { + // Shadow s = ReflectionShadow.makeExecutionShadow(world, aMember, this.matchContext); + // ShadowMatchImpl sm = getShadowMatch(s); + // sm.setSubject(aMember); + // sm.setWithinCode(null); + // sm.setWithinType(aMember.getDeclaringClass()); + // return sm; + // } private ShadowMatch matchesExecution(ResolvedMember aMember) { Shadow s = StandardShadow.makeExecutionShadow(world, aMember, this.matchContext); - ShadowMatchImpl sm = getShadowMatch(s); - // sm.setSubject(aMember); - // sm.setWithinCode(null); - // sm.setWithinType(aMember.getDeclaringClass()); - return sm; - } - - public ShadowMatch matchesStaticInitialization(Class aClass) { - Shadow s = ReflectionShadow.makeStaticInitializationShadow(world, aClass, this.matchContext); - ShadowMatchImpl sm = getShadowMatch(s); - sm.setSubject(null); + StandardShadowMatchImpl sm = getShadowMatch(s); + sm.setSubject(aMember); sm.setWithinCode(null); - sm.setWithinType(aClass); + sm.setWithinType((ResolvedType) aMember.getDeclaringType()); return sm; } - public ShadowMatch matchesStaticInitialization(ResolvedType type) { - Shadow s = StandardShadow.makeStaticInitializationShadow(world, type, this.matchContext); - ShadowMatchImpl sm = getShadowMatch(s); + // public ShadowMatch matchesStaticInitialization(Class aClass) { + // Shadow s = ReflectionShadow.makeStaticInitializationShadow(world, aClass, this.matchContext); + // StandardShadowMatchImpl sm = getShadowMatch(s); + // sm.setSubject(null); + // sm.setWithinCode(null); + // sm.setWithinType(aClass); + // return sm; + // } + + public ShadowMatch matchesStaticInitialization(ResolvedType aType) { + Shadow s = StandardShadow.makeStaticInitializationShadow(world, aType, this.matchContext); + StandardShadowMatchImpl sm = getShadowMatch(s); sm.setSubject(null); sm.setWithinCode(null); - // sm.setWithinType(aClass); - return sm; - } - - public ShadowMatch matchesAdviceExecution(Method aMethod) { - Shadow s = ReflectionShadow.makeAdviceExecutionShadow(world, aMethod, this.matchContext); - ShadowMatchImpl sm = getShadowMatch(s); - sm.setSubject(aMethod); - sm.setWithinCode(null); - sm.setWithinType(aMethod.getDeclaringClass()); + sm.setWithinType(aType); return sm; } - public ShadowMatch matchesInitialization(Constructor aConstructor) { - Shadow s = ReflectionShadow.makeInitializationShadow(world, aConstructor, this.matchContext); - ShadowMatchImpl sm = getShadowMatch(s); - sm.setSubject(aConstructor); - sm.setWithinCode(null); - sm.setWithinType(aConstructor.getDeclaringClass()); - return sm; - } - - public ShadowMatch matchesPreInitialization(Constructor aConstructor) { - Shadow s = ReflectionShadow.makePreInitializationShadow(world, aConstructor, this.matchContext); - ShadowMatchImpl sm = getShadowMatch(s); - sm.setSubject(aConstructor); - sm.setWithinCode(null); - sm.setWithinType(aConstructor.getDeclaringClass()); - return sm; - } - - public ShadowMatch matchesMethodCall(Method aMethod, Member withinCode) { - Shadow s = ReflectionShadow.makeCallShadow(world, aMethod, withinCode, this.matchContext); - ShadowMatchImpl sm = getShadowMatch(s); + // public ShadowMatch matchesAdviceExecution(Method aMethod) { + // Shadow s = ReflectionShadow.makeAdviceExecutionShadow(world, aMethod, this.matchContext); + // StandardShadowMatchImpl sm = getShadowMatch(s); + // sm.setSubject(aMethod); + // sm.setWithinCode(null); + // sm.setWithinType(aMethod.getDeclaringClass()); + // return sm; + // } + // + // public ShadowMatch matchesInitialization(Constructor aConstructor) { + // Shadow s = ReflectionShadow.makeInitializationShadow(world, aConstructor, this.matchContext); + // StandardShadowMatchImpl sm = getShadowMatch(s); + // sm.setSubject(aConstructor); + // sm.setWithinCode(null); + // sm.setWithinType(aConstructor.getDeclaringClass()); + // return sm; + // } + // + // public ShadowMatch matchesPreInitialization(Constructor aConstructor) { + // Shadow s = ReflectionShadow.makePreInitializationShadow(world, aConstructor, this.matchContext); + // StandardShadowMatchImpl sm = getShadowMatch(s); + // sm.setSubject(aConstructor); + // sm.setWithinCode(null); + // sm.setWithinType(aConstructor.getDeclaringClass()); + // return sm; + // } + // + public ShadowMatch matchesMethodCall(ResolvedMember aMethod, ResolvedMember withinCode) { + Shadow s = StandardShadow.makeCallShadow(world, aMethod, withinCode, this.matchContext); + StandardShadowMatchImpl sm = getShadowMatch(s); sm.setSubject(aMethod); sm.setWithinCode(withinCode); - sm.setWithinType(withinCode.getDeclaringClass()); - return sm; - } - - public ShadowMatch matchesMethodCall(Method aMethod, Class callerType) { - Shadow s = ReflectionShadow.makeCallShadow(world, aMethod, callerType, this.matchContext); - ShadowMatchImpl sm = getShadowMatch(s); - sm.setSubject(aMethod); - sm.setWithinCode(null); - sm.setWithinType(callerType); - return sm; - } - - public ShadowMatch matchesConstructorCall(Constructor aConstructor, Class callerType) { - Shadow s = ReflectionShadow.makeCallShadow(world, aConstructor, callerType, this.matchContext); - ShadowMatchImpl sm = getShadowMatch(s); - sm.setSubject(aConstructor); - sm.setWithinCode(null); - sm.setWithinType(callerType); - return sm; - } - - public ShadowMatch matchesConstructorCall(Constructor aConstructor, Member withinCode) { - Shadow s = ReflectionShadow.makeCallShadow(world, aConstructor, withinCode, this.matchContext); - ShadowMatchImpl sm = getShadowMatch(s); - sm.setSubject(aConstructor); - sm.setWithinCode(withinCode); - sm.setWithinType(withinCode.getDeclaringClass()); - return sm; - } - - public ShadowMatch matchesHandler(Class exceptionType, Class handlingType) { - Shadow s = ReflectionShadow.makeHandlerShadow(world, exceptionType, handlingType, this.matchContext); - ShadowMatchImpl sm = getShadowMatch(s); - sm.setSubject(null); - sm.setWithinCode(null); - sm.setWithinType(handlingType); - return sm; - } - - public ShadowMatch matchesHandler(Class exceptionType, Member withinCode) { - Shadow s = ReflectionShadow.makeHandlerShadow(world, exceptionType, withinCode, this.matchContext); - ShadowMatchImpl sm = getShadowMatch(s); - sm.setSubject(null); - sm.setWithinCode(withinCode); - sm.setWithinType(withinCode.getDeclaringClass()); - return sm; - } - - public ShadowMatch matchesFieldGet(Field aField, Class withinType) { - Shadow s = ReflectionShadow.makeFieldGetShadow(world, aField, withinType, this.matchContext); - ShadowMatchImpl sm = getShadowMatch(s); - sm.setSubject(aField); - sm.setWithinCode(null); - sm.setWithinType(withinType); - return sm; - } - - public ShadowMatch matchesFieldGet(Field aField, Member withinCode) { - Shadow s = ReflectionShadow.makeFieldGetShadow(world, aField, withinCode, this.matchContext); - ShadowMatchImpl sm = getShadowMatch(s); - sm.setSubject(aField); - sm.setWithinCode(withinCode); - sm.setWithinType(withinCode.getDeclaringClass()); - return sm; - } - - public ShadowMatch matchesFieldSet(Field aField, Class withinType) { - Shadow s = ReflectionShadow.makeFieldSetShadow(world, aField, withinType, this.matchContext); - ShadowMatchImpl sm = getShadowMatch(s); - sm.setSubject(aField); - sm.setWithinCode(null); - sm.setWithinType(withinType); - return sm; - } - - public ShadowMatch matchesFieldSet(Field aField, Member withinCode) { - Shadow s = ReflectionShadow.makeFieldSetShadow(world, aField, withinCode, this.matchContext); - ShadowMatchImpl sm = getShadowMatch(s); - sm.setSubject(aField); - sm.setWithinCode(withinCode); - sm.setWithinType(withinCode.getDeclaringClass()); + sm.setWithinType((ResolvedType) withinCode.getDeclaringType()); return sm; } - private ShadowMatchImpl getShadowMatch(Shadow forShadow) { + // + // public ShadowMatch matchesMethodCall(Method aMethod, Class callerType) { + // Shadow s = ReflectionShadow.makeCallShadow(world, aMethod, callerType, this.matchContext); + // ShadowMatchImpl sm = getShadowMatch(s); + // sm.setSubject(aMethod); + // sm.setWithinCode(null); + // sm.setWithinType(callerType); + // return sm; + // } + // + // public ShadowMatch matchesConstructorCall(Constructor aConstructor, Class callerType) { + // Shadow s = ReflectionShadow.makeCallShadow(world, aConstructor, callerType, this.matchContext); + // ShadowMatchImpl sm = getShadowMatch(s); + // sm.setSubject(aConstructor); + // sm.setWithinCode(null); + // sm.setWithinType(callerType); + // return sm; + // } + // + // public ShadowMatch matchesConstructorCall(Constructor aConstructor, Member withinCode) { + // Shadow s = ReflectionShadow.makeCallShadow(world, aConstructor, withinCode, this.matchContext); + // ShadowMatchImpl sm = getShadowMatch(s); + // sm.setSubject(aConstructor); + // sm.setWithinCode(withinCode); + // sm.setWithinType(withinCode.getDeclaringClass()); + // return sm; + // } + // + // public ShadowMatch matchesHandler(Class exceptionType, Class handlingType) { + // Shadow s = ReflectionShadow.makeHandlerShadow(world, exceptionType, handlingType, this.matchContext); + // ShadowMatchImpl sm = getShadowMatch(s); + // sm.setSubject(null); + // sm.setWithinCode(null); + // sm.setWithinType(handlingType); + // return sm; + // } + // + // public ShadowMatch matchesHandler(Class exceptionType, Member withinCode) { + // Shadow s = ReflectionShadow.makeHandlerShadow(world, exceptionType, withinCode, this.matchContext); + // ShadowMatchImpl sm = getShadowMatch(s); + // sm.setSubject(null); + // sm.setWithinCode(withinCode); + // sm.setWithinType(withinCode.getDeclaringClass()); + // return sm; + // } + // + // public ShadowMatch matchesFieldGet(Field aField, Class withinType) { + // Shadow s = ReflectionShadow.makeFieldGetShadow(world, aField, withinType, this.matchContext); + // ShadowMatchImpl sm = getShadowMatch(s); + // sm.setSubject(aField); + // sm.setWithinCode(null); + // sm.setWithinType(withinType); + // return sm; + // } + // + // public ShadowMatch matchesFieldGet(Field aField, Member withinCode) { + // Shadow s = ReflectionShadow.makeFieldGetShadow(world, aField, withinCode, this.matchContext); + // ShadowMatchImpl sm = getShadowMatch(s); + // sm.setSubject(aField); + // sm.setWithinCode(withinCode); + // sm.setWithinType(withinCode.getDeclaringClass()); + // return sm; + // } + // + // public ShadowMatch matchesFieldSet(Field aField, Class withinType) { + // Shadow s = ReflectionShadow.makeFieldSetShadow(world, aField, withinType, this.matchContext); + // ShadowMatchImpl sm = getShadowMatch(s); + // sm.setSubject(aField); + // sm.setWithinCode(null); + // sm.setWithinType(withinType); + // return sm; + // } + // + // public ShadowMatch matchesFieldSet(Field aField, Member withinCode) { + // Shadow s = ReflectionShadow.makeFieldSetShadow(world, aField, withinCode, this.matchContext); + // StandardShadowMatchImpl sm = getShadowMatch(s); + // sm.setSubject(aField); + // sm.setWithinCode(withinCode); + // sm.setWithinType(withinCode.getDeclaringClass()); + // return sm; + // } + + private StandardShadowMatchImpl getShadowMatch(Shadow forShadow) { org.aspectj.util.FuzzyBoolean match = pointcut.match(forShadow); Test residueTest = Literal.TRUE; ExposedState state = getExposedState(); if (match.maybeTrue()) { residueTest = pointcut.findResidue(forShadow, state); } - ShadowMatchImpl sm = new ShadowMatchImpl(match, residueTest, state, parameters); + StandardShadowMatchImpl sm = new StandardShadowMatchImpl(match, residueTest, state, parameters); sm.setMatchingContext(this.matchContext); return sm; } diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/reflect/StandardShadow.java b/org.aspectj.matcher/src/org/aspectj/weaver/reflect/StandardShadow.java index 8e741b6c9..411ccdd91 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/reflect/StandardShadow.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/reflect/StandardShadow.java @@ -71,14 +71,15 @@ public class StandardShadow extends Shadow { return new StandardShadow(inWorld, kind, signature, null, enclosingType, null, withContext); } - public static Shadow makeCallShadow(World inWorld, java.lang.reflect.Member aMember, java.lang.reflect.Member withinCode, + public static Shadow makeCallShadow(World inWorld, ResolvedMember aMember, ResolvedMember withinCode, MatchingContext withContext) { Shadow enclosingShadow = makeExecutionShadow(inWorld, withinCode, withContext); - Member signature = ReflectionBasedReferenceTypeDelegateFactory.createResolvedMember(aMember, inWorld); - ResolvedMember enclosingMember = ReflectionBasedReferenceTypeDelegateFactory.createResolvedMember(withinCode, inWorld); - ResolvedType enclosingType = enclosingMember.getDeclaringType().resolve(inWorld); - Kind kind = aMember instanceof Method ? Shadow.MethodCall : Shadow.ConstructorCall; - return new StandardShadow(inWorld, kind, signature, enclosingShadow, enclosingType, enclosingMember, withContext); + // Member signature = ReflectionBasedReferenceTypeDelegateFactory.createResolvedMember(aMember, inWorld); + // ResolvedMember enclosingMember = ReflectionBasedReferenceTypeDelegateFactory.createResolvedMember(withinCode, inWorld); + // ResolvedType enclosingType = enclosingMember.getDeclaringType().resolve(inWorld); + Kind kind = !aMember.getName().equals("<init>") ? Shadow.MethodCall : Shadow.ConstructorCall; + return new StandardShadow(inWorld, kind, aMember, enclosingShadow, (ResolvedType) withinCode.getDeclaringType(), + withinCode, withContext); } public static Shadow makeCallShadow(World inWorld, java.lang.reflect.Member aMember, Class thisClass, diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/reflect/StandardShadowMatchImpl.java b/org.aspectj.matcher/src/org/aspectj/weaver/reflect/StandardShadowMatchImpl.java new file mode 100644 index 000000000..baeab0334 --- /dev/null +++ b/org.aspectj.matcher/src/org/aspectj/weaver/reflect/StandardShadowMatchImpl.java @@ -0,0 +1,196 @@ +/* ******************************************************************* + * Copyright (c) 2005 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: + * Adrian Colyer Initial implementation + * ******************************************************************/ +package org.aspectj.weaver.reflect; + +import org.aspectj.util.FuzzyBoolean; +import org.aspectj.weaver.ResolvedMember; +import org.aspectj.weaver.ResolvedType; +import org.aspectj.weaver.World; +import org.aspectj.weaver.ast.And; +import org.aspectj.weaver.ast.Call; +import org.aspectj.weaver.ast.FieldGetCall; +import org.aspectj.weaver.ast.HasAnnotation; +import org.aspectj.weaver.ast.ITestVisitor; +import org.aspectj.weaver.ast.Instanceof; +import org.aspectj.weaver.ast.Literal; +import org.aspectj.weaver.ast.Not; +import org.aspectj.weaver.ast.Or; +import org.aspectj.weaver.ast.Test; +import org.aspectj.weaver.internal.tools.MatchingContextBasedTest; +import org.aspectj.weaver.patterns.ExposedState; +import org.aspectj.weaver.tools.DefaultMatchingContext; +import org.aspectj.weaver.tools.JoinPointMatch; +import org.aspectj.weaver.tools.MatchingContext; +import org.aspectj.weaver.tools.PointcutParameter; +import org.aspectj.weaver.tools.ShadowMatch; + +/** + * @author colyer Implementation of ShadowMatch for reflection based worlds. + */ +public class StandardShadowMatchImpl implements ShadowMatch { + + private FuzzyBoolean match; + private ExposedState state; + private Test residualTest; + private PointcutParameter[] params; + private ResolvedMember withinCode; + private ResolvedMember subject; + private ResolvedType withinType; + private MatchingContext matchContext = new DefaultMatchingContext(); + + public StandardShadowMatchImpl(FuzzyBoolean match, Test test, ExposedState state, PointcutParameter[] params) { + this.match = match; + this.residualTest = test; + this.state = state; + this.params = params; + } + + public void setWithinCode(ResolvedMember aMember) { + this.withinCode = aMember; + } + + public void setSubject(ResolvedMember aMember) { + this.subject = aMember; + } + + public void setWithinType(ResolvedType aClass) { + this.withinType = aClass; + } + + public boolean alwaysMatches() { + return match.alwaysTrue(); + } + + public boolean maybeMatches() { + return match.maybeTrue(); + } + + public boolean neverMatches() { + return match.alwaysFalse(); + } + + public JoinPointMatch matchesJoinPoint(Object thisObject, Object targetObject, Object[] args) { + if (neverMatches()) + return JoinPointMatchImpl.NO_MATCH; + if (new RuntimeTestEvaluator(residualTest, thisObject, targetObject, args, this.matchContext).matches()) { + return new JoinPointMatchImpl(getPointcutParameters(thisObject, targetObject, args)); + } else { + return JoinPointMatchImpl.NO_MATCH; + } + } + + /* + * (non-Javadoc) + * + * @see org.aspectj.weaver.tools.ShadowMatch#setMatchingContext(org.aspectj.weaver.tools.MatchingContext) + */ + public void setMatchingContext(MatchingContext aMatchContext) { + this.matchContext = aMatchContext; + } + + private PointcutParameter[] getPointcutParameters(Object thisObject, Object targetObject, Object[] args) { + // Var[] vars = state.vars; + // PointcutParameterImpl[] bindings = new PointcutParameterImpl[params.length]; + // for (int i = 0; i < bindings.length; i++) { + // bindings[i] = new PointcutParameterImpl(params[i].getName(), params[i].getType()); + // bindings[i].setBinding(((ReflectionVar) vars[i]).getBindingAtJoinPoint(thisObject, targetObject, args, subject, + // withinCode, withinType)); + // } + // return bindings; + return null; + } + + private static class RuntimeTestEvaluator implements ITestVisitor { + + private boolean matches = true; + private final Test test; + private final Object thisObject; + private final Object targetObject; + private final Object[] args; + private final MatchingContext matchContext; + + public RuntimeTestEvaluator(Test aTest, Object thisObject, Object targetObject, Object[] args, MatchingContext context) { + this.test = aTest; + this.thisObject = thisObject; + this.targetObject = targetObject; + this.args = args; + this.matchContext = context; + } + + public boolean matches() { + test.accept(this); + return matches; + } + + public void visit(And e) { + boolean leftMatches = new RuntimeTestEvaluator(e.getLeft(), thisObject, targetObject, args, matchContext).matches(); + if (!leftMatches) { + matches = false; + } else { + matches = new RuntimeTestEvaluator(e.getRight(), thisObject, targetObject, args, matchContext).matches(); + } + } + + public void visit(Instanceof i) { + ReflectionVar v = (ReflectionVar) i.getVar(); + Object value = v.getBindingAtJoinPoint(thisObject, targetObject, args); + World world = v.getType().getWorld(); + ResolvedType desiredType = i.getType().resolve(world); + ResolvedType actualType = world.resolve(value.getClass().getName()); + matches = desiredType.isAssignableFrom(actualType); + } + + public void visit(MatchingContextBasedTest matchingContextTest) { + matches = matchingContextTest.matches(this.matchContext); + } + + public void visit(Not not) { + matches = !new RuntimeTestEvaluator(not.getBody(), thisObject, targetObject, args, matchContext).matches(); + } + + public void visit(Or or) { + boolean leftMatches = new RuntimeTestEvaluator(or.getLeft(), thisObject, targetObject, args, matchContext).matches(); + if (leftMatches) { + matches = true; + } else { + matches = new RuntimeTestEvaluator(or.getRight(), thisObject, targetObject, args, matchContext).matches(); + } + } + + public void visit(Literal literal) { + if (literal == Literal.FALSE) { + matches = false; + } else { + matches = true; + } + } + + public void visit(Call call) { + throw new UnsupportedOperationException("Can't evaluate call test at runtime"); + } + + public void visit(FieldGetCall fieldGetCall) { + throw new UnsupportedOperationException("Can't evaluate fieldGetCall test at runtime"); + } + + public void visit(HasAnnotation hasAnnotation) { + ReflectionVar v = (ReflectionVar) hasAnnotation.getVar(); + Object value = v.getBindingAtJoinPoint(thisObject, targetObject, args); + World world = v.getType().getWorld(); + ResolvedType actualVarType = world.resolve(value.getClass().getName()); + ResolvedType requiredAnnotationType = hasAnnotation.getAnnotationType().resolve(world); + matches = actualVarType.hasAnnotation(requiredAnnotationType); + } + + } + +} diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/tools/StandardPointcutExpression.java b/org.aspectj.matcher/src/org/aspectj/weaver/tools/StandardPointcutExpression.java index 3d5534944..63d908bd2 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/tools/StandardPointcutExpression.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/tools/StandardPointcutExpression.java @@ -10,11 +10,6 @@ package org.aspectj.weaver.tools; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Member; -import java.lang.reflect.Method; - import org.aspectj.weaver.ResolvedMember; import org.aspectj.weaver.ResolvedType; @@ -51,26 +46,17 @@ public interface StandardPointcutExpression { * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches join points representing the * execution of the method. */ - ShadowMatch matchesMethodExecution(Method aMethod); - - /** - * Determine whether or not this pointcut matches the execution of a given method. - * - * @param aMethod the method being executed - * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches join points representing the - * execution of the method. - */ ShadowMatch matchesMethodExecution(ResolvedMember aMethod); - /** - * Determine whether or not this pointcut matches the execution of a given constructor. - * - * @param aConstructor the constructor being executed - * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches join points representing the - * execution of the constructor. - */ - ShadowMatch matchesConstructorExecution(Constructor aConstructor); - + // /** + // * Determine whether or not this pointcut matches the execution of a given constructor. + // * + // * @param aConstructor the constructor being executed + // * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches join points representing the + // * execution of the constructor. + // */ + // ShadowMatch matchesConstructorExecution(Constructor aConstructor); + // /** * Determine whether or not this pointcut matches the static initialization of the given class. * @@ -78,45 +64,48 @@ public interface StandardPointcutExpression { * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matchs join points representing the static * initialization of the given type */ - ShadowMatch matchesStaticInitialization(Class aClass); - - /** - * Determine whether or not this pointcut matches the static initialization of the given class. - * - * @param aClass the class being statically initialized - * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matchs join points representing the static - * initialization of the given type - */ - ShadowMatch matchesStaticInitialization(ResolvedType type); - - /** - * Determine whether or not this pointcut matches the execution of a given piece of advice. - * - * @param anAdviceMethod a method representing the advice being executed - * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches join points representing the - * execution of the advice. - */ - ShadowMatch matchesAdviceExecution(Method anAdviceMethod); - - /** - * Determine whether or not this pointcut matches the initialization of an object initiated by a call to the given constructor. - * - * @param aConstructor the constructor initiating the initialization - * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches join points representing - * initialization via the given constructor. - */ - ShadowMatch matchesInitialization(Constructor aConstructor); - - /** - * Determine whether or not this pointcut matches the pre-initialization of an object initiated by a call to the given - * constructor. - * - * @param aConstructor the constructor initiating the initialization - * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches join points representing - * pre-initialization via the given constructor. - */ - ShadowMatch matchesPreInitialization(Constructor aConstructor); - + ShadowMatch matchesStaticInitialization(ResolvedType aType); + + // + // /** + // * Determine whether or not this pointcut matches the static initialization of the given class. + // * + // * @param aClass the class being statically initialized + // * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matchs join points representing the + // static + // * initialization of the given type + // */ + // ShadowMatch matchesStaticInitialization(ResolvedType type); + // + // /** + // * Determine whether or not this pointcut matches the execution of a given piece of advice. + // * + // * @param anAdviceMethod a method representing the advice being executed + // * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches join points representing the + // * execution of the advice. + // */ + // ShadowMatch matchesAdviceExecution(Method anAdviceMethod); + // + // /** + // * Determine whether or not this pointcut matches the initialization of an object initiated by a call to the given + // constructor. + // * + // * @param aConstructor the constructor initiating the initialization + // * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches join points representing + // * initialization via the given constructor. + // */ + // ShadowMatch matchesInitialization(Constructor aConstructor); + // + // /** + // * Determine whether or not this pointcut matches the pre-initialization of an object initiated by a call to the given + // * constructor. + // * + // * @param aConstructor the constructor initiating the initialization + // * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches join points representing + // * pre-initialization via the given constructor. + // */ + // ShadowMatch matchesPreInitialization(Constructor aConstructor); + // /** * Determine whether or not this pointcut matches a method call to the given method, made during the execution of the given * method or constructor. @@ -126,105 +115,116 @@ public interface StandardPointcutExpression { * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches join points representing a call to * this method during the execution of the given member. */ - ShadowMatch matchesMethodCall(Method aMethod, Member withinCode); - - /** - * Determine whether or not this pointcut matches a method call to the given method, made outside of the scope of any method or - * constructor, but within the callerType (for example, during static initialization of the type). - * - * @param aMethod the method being called - * @param callerType the declared type of the caller - * @param receiverType the declared type of the recipient of the call - * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches join points representing a call to - * this method during the execution of the given member. - */ - ShadowMatch matchesMethodCall(Method aMethod, Class callerType); - - /** - * Determine whether or not this pointcut matches a method call to the given constructor, made during the execution of the given - * method or constructor. - * - * @param aConstructor the constructor being called - * @param withinCode the Method or Constructor from within which the call is made - * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches join points representing a call to - * this constructor during the execution of the given member. - */ - ShadowMatch matchesConstructorCall(Constructor aConstructor, Member withinCode); - - /** - * Determine whether or not this pointcut matches a method call to the given constructor, made outside of the scope of any - * method or constructor, but within the callerType. - * - * @param aConstructor the cosstructor being called - * @param callerType the declared type of the caller - * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches join points representing a call to - * this constructor during the execution of the given member. - */ - ShadowMatch matchesConstructorCall(Constructor aConstructor, Class callerType); - - /** - * Determine whether or not this pointcut matches the execution of a given exception handler within the given method or - * constructor - * - * @param exceptionType the static type of the exception being handled - * @param withinCode the method or constructor in which the catch block is declared - * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches join points representing the - * handling of the given exception - */ - ShadowMatch matchesHandler(Class exceptionType, Member withinCode); - - /** - * Determine whether or not this pointcut matches the execution of a given exception handler outside of the scope of any method - * or constructor, but within the handling type. - * - * @param exceptionType the static type of the exception being handled - * @param handlingType the type in which the handler block is executing - * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches join points representing the - * handling of the given exception - */ - ShadowMatch matchesHandler(Class exceptionType, Class handlingType); - - /** - * Determine whether or not this pointcut matches a set of the given field from within the given method or constructor. - * - * @param aField the field being updated - * @param withinCode the Method or Constructor owning the call site - * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches field set join points for the given - * field and call site. - */ - ShadowMatch matchesFieldSet(Field aField, Member withinCode); - - /** - * Determine whether or not this pointcut matches a set of the given field outside of the scope of any method or constructor, - * but within the given type (for example, during static initialization). - * - * @param aField the field being updated - * @param withinType the type owning the call site - * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches field set join points for the given - * field and call site. - */ - ShadowMatch matchesFieldSet(Field aField, Class withinType); - - /** - * Determine whether or not this pointcut matches a get of the given field from within the given method or constructor. - * - * @param aField the field being updated - * @param withinCode the Method or Constructor owning the call site - * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches field get join points for the given - * field and call site. - */ - ShadowMatch matchesFieldGet(Field aField, Member withinCode); - - /** - * Determine whether or not this pointcut matches a get of the given field outside of the scope of any method or constructor, - * but within the given type (for example, during static initialization). - * - * @param aField the field being accessed - * @param withinType the type owning the call site - * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches field get join points for the given - * field and call site. - */ - ShadowMatch matchesFieldGet(Field aField, Class withinType); + ShadowMatch matchesMethodCall(ResolvedMember aMethod, ResolvedMember withinCode); + + // + // /** + // * Determine whether or not this pointcut matches a method call to the given method, made outside of the scope of any method + // or + // * constructor, but within the callerType (for example, during static initialization of the type). + // * + // * @param aMethod the method being called + // * @param callerType the declared type of the caller + // * @param receiverType the declared type of the recipient of the call + // * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches join points representing a call + // to + // * this method during the execution of the given member. + // */ + // ShadowMatch matchesMethodCall(Method aMethod, Class callerType); + // + // /** + // * Determine whether or not this pointcut matches a method call to the given constructor, made during the execution of the + // given + // * method or constructor. + // * + // * @param aConstructor the constructor being called + // * @param withinCode the Method or Constructor from within which the call is made + // * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches join points representing a call + // to + // * this constructor during the execution of the given member. + // */ + // ShadowMatch matchesConstructorCall(Constructor aConstructor, Member withinCode); + // + // /** + // * Determine whether or not this pointcut matches a method call to the given constructor, made outside of the scope of any + // * method or constructor, but within the callerType. + // * + // * @param aConstructor the cosstructor being called + // * @param callerType the declared type of the caller + // * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches join points representing a call + // to + // * this constructor during the execution of the given member. + // */ + // ShadowMatch matchesConstructorCall(Constructor aConstructor, Class callerType); + // + // /** + // * Determine whether or not this pointcut matches the execution of a given exception handler within the given method or + // * constructor + // * + // * @param exceptionType the static type of the exception being handled + // * @param withinCode the method or constructor in which the catch block is declared + // * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches join points representing the + // * handling of the given exception + // */ + // ShadowMatch matchesHandler(Class exceptionType, Member withinCode); + // + // /** + // * Determine whether or not this pointcut matches the execution of a given exception handler outside of the scope of any + // method + // * or constructor, but within the handling type. + // * + // * @param exceptionType the static type of the exception being handled + // * @param handlingType the type in which the handler block is executing + // * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches join points representing the + // * handling of the given exception + // */ + // ShadowMatch matchesHandler(Class exceptionType, Class handlingType); + // + // /** + // * Determine whether or not this pointcut matches a set of the given field from within the given method or constructor. + // * + // * @param aField the field being updated + // * @param withinCode the Method or Constructor owning the call site + // * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches field set join points for the + // given + // * field and call site. + // */ + // ShadowMatch matchesFieldSet(Field aField, Member withinCode); + // + // /** + // * Determine whether or not this pointcut matches a set of the given field outside of the scope of any method or constructor, + // * but within the given type (for example, during static initialization). + // * + // * @param aField the field being updated + // * @param withinType the type owning the call site + // * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches field set join points for the + // given + // * field and call site. + // */ + // ShadowMatch matchesFieldSet(Field aField, Class withinType); + // + // /** + // * Determine whether or not this pointcut matches a get of the given field from within the given method or constructor. + // * + // * @param aField the field being updated + // * @param withinCode the Method or Constructor owning the call site + // * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches field get join points for the + // given + // * field and call site. + // */ + // ShadowMatch matchesFieldGet(Field aField, Member withinCode); + // + // /** + // * Determine whether or not this pointcut matches a get of the given field outside of the scope of any method or constructor, + // * but within the given type (for example, during static initialization). + // * + // * @param aField the field being accessed + // * @param withinType the type owning the call site + // * @return a ShadowMatch indicating whether the pointcut always, sometimes, or never matches field get join points for the + // given + // * field and call site. + // */ + // ShadowMatch matchesFieldGet(Field aField, Class withinType); /** * Return a string representation of this pointcut expression. |