protected FuzzyBoolean matchInternal(Shadow shadow) { FuzzyBoolean leftMatch = left.match(shadow); if (leftMatch.alwaysFalse()) { return leftMatch; } return leftMatch.and(right.match(shadow)); }
public AndPointcut(Pointcut left, Pointcut right) { super(); this.left = left; this.right = right; this.pointcutKind = AND; setLocation(left.getSourceContext(), left.getStart(), right.getEnd()); couldMatchKinds = left.couldMatchKinds() & right.couldMatchKinds(); }
public Pointcut parameterizeWith(Map typeVariableMap, World w) { AndPointcut ret = new AndPointcut( left.parameterizeWith(typeVariableMap, w), right.parameterizeWith(typeVariableMap, w)); ret.copyLocationFrom(this); ret.m_ignoreUnboundBindingForNames = m_ignoreUnboundBindingForNames; return ret; }
public Pointcut concretize1(ResolvedType inAspect, ResolvedType declaringType, IntMap bindings) { AndPointcut ret = new AndPointcut( left.concretize(inAspect, declaringType, bindings), right.concretize(inAspect, declaringType, bindings)); ret.copyLocationFrom(this); ret.m_ignoreUnboundBindingForNames = m_ignoreUnboundBindingForNames; return ret; }
/** * Method checkSerialization. * * @param string */ private void checkSerialization(String string) throws IOException { Pointcut p = makePointcut(string); ByteArrayOutputStream bo = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(bo); p.write(out); out.close(); ByteArrayInputStream bi = new ByteArrayInputStream(bo.toByteArray()); VersionedDataInputStream in = new VersionedDataInputStream(bi); Pointcut newP = Pointcut.read(in, null); assertEquals("write/read", p, newP); }
/** * Compare 2 pointcuts based on an estimate of how expensive they may be to evaluate. * * <p>within * * @within staticinitialization [make sure this has a fast match method] adviceexecution handler * get, set withincode * @withincode execution, initialization, preinitialization call * @annotation this, target * @this, @target args * @args cflow, cflowbelow if */ public int compare(Pointcut p1, Pointcut p2) { // important property for a well-defined comparator if (p1.equals(p2)) { return 0; } int result = getScore(p1) - getScore(p2); if (result == 0) { // they have the same evaluation expense, but are not 'equal' // sort by hashCode int p1code = p1.hashCode(); int p2code = p2.hashCode(); if (p1code == p2code) { return 0; } else if (p1code < p2code) { return -1; } else { return +1; } } return result; }
@Test public void testGetAopProxy3() throws Exception { AopProxyUtil aopProxyUtil = new AopProxyUtil(); AroundAdvice aroundAdvice = new AroundAdviceImpl01(); Pointcut pointcut = new Pointcut(); pointcut.setName("xx"); pointcut.setExpression("execution(* *.add*(..))"); PointcutAndAdvice paa = new PointcutAndAdvice(pointcut, aroundAdvice); AroundAdvice aroundAdvice2 = new AroundAdviceImpl02(); Pointcut pointcut2 = new Pointcut(); pointcut2.setName("yy"); pointcut2.setExpression("execution(* *.add*(..))"); PointcutAndAdvice paa2 = new PointcutAndAdvice(pointcut2, aroundAdvice2); aopProxyUtil.addPointcutAndAdvice(paa); aopProxyUtil.addPointcutAndAdvice(paa2); UserService student = new UserServiceImpl(); UserService proxy = aopProxyUtil.getAopProxy(student); proxy.add(); proxy.find(); }
public FuzzyBoolean fastMatch(FastMatchInfo type) { return left.fastMatch(type).and(right.fastMatch(type)); }
protected Test findResidueInternal(Shadow shadow, ExposedState state) { return Test.makeAnd(left.findResidue(shadow, state), right.findResidue(shadow, state)); }
public static Pointcut read(VersionedDataInputStream s, ISourceContext context) throws IOException { AndPointcut ret = new AndPointcut(Pointcut.read(s, context), Pointcut.read(s, context)); ret.readLocation(context, s); return ret; }
public void write(CompressingDataOutputStream s) throws IOException { s.writeByte(Pointcut.AND); left.write(s); right.write(s); writeLocation(s); }
public void resolveBindings(IScope scope, Bindings bindings) { left.resolveBindings(scope, bindings); right.resolveBindings(scope, bindings); }
public int hashCode() { int result = 19; result = 37 * result + left.hashCode(); result = 37 * result + right.hashCode(); return result; }
public String toString() { return "(" + left.toString() + " && " + right.toString() + ")"; }
@Test public void testGetAopProxy4() throws Exception { AopProxyUtil aopProxyUtil = new AopProxyUtil(); BeforeAdvice beforeAdvice = new BeforeAdviceImpl01(); Pointcut pointcut = new Pointcut(); pointcut.setName("xx"); pointcut.setExpression("execution(* *.*(..))"); PointcutAndAdvice paa = new PointcutAndAdvice(pointcut, beforeAdvice); AroundAdvice aroundAdvice2 = new AroundAdviceImpl02(); Pointcut pointcut2 = new Pointcut(); pointcut2.setName("yy"); pointcut2.setExpression("execution(* *.*(..))"); PointcutAndAdvice paa2 = new PointcutAndAdvice(pointcut2, aroundAdvice2); ExceptionAdvice exceptionAdvice = new ExceptionAdviceImpl01(); Pointcut pointcut3 = new Pointcut(); pointcut3.setName("2yy"); pointcut3.setExpression("execution(* *.*(..))"); PointcutAndAdvice paa3 = new PointcutAndAdvice(pointcut3, exceptionAdvice); ExceptionAdvice exceptionAdvice2 = new ExceptionAdviceImpl02(); Pointcut pointcut4 = new Pointcut(); pointcut4.setName("4yy"); pointcut4.setExpression("execution(* *.*(..))"); PointcutAndAdvice paa4 = new PointcutAndAdvice(pointcut4, exceptionAdvice2); aopProxyUtil.addPointcutAndAdvice(paa); aopProxyUtil.addPointcutAndAdvice(paa2); aopProxyUtil.addPointcutAndAdvice(paa3); aopProxyUtil.addPointcutAndAdvice(paa4); UserService student = new UserServiceImpl(); UserService proxy = aopProxyUtil.getAopProxy(student); // proxy.add(); // proxy.find(); proxy.delete(); }
public Object traverse(PatternNodeVisitor visitor, Object data) { Object ret = accept(visitor, data); left.traverse(visitor, ret); right.traverse(visitor, ret); return ret; }
// a higher score means a more expensive evaluation private int getScore(Pointcut p) { if (p.couldMatchKinds() == Shadow.NO_SHADOW_KINDS_BITS) { return MATCHES_NOTHING; } if (p instanceof WithinPointcut) { return WITHIN; } if (p instanceof WithinAnnotationPointcut) { return ATWITHIN; } if (p instanceof KindedPointcut) { KindedPointcut kp = (KindedPointcut) p; Shadow.Kind kind = kp.getKind(); if (kind == Shadow.AdviceExecution) { return ADVICEEXECUTION; } else if ((kind == Shadow.ConstructorCall) || (kind == Shadow.MethodCall)) { TypePattern declaringTypePattern = kp.getSignature().getDeclaringType(); if (declaringTypePattern instanceof AnyTypePattern) { return CALL_WITHOUT_DECLARING_TYPE; } else { return CALL_WITH_DECLARING_TYPE; } } else if ((kind == Shadow.ConstructorExecution) || (kind == Shadow.MethodExecution) || (kind == Shadow.Initialization) || (kind == Shadow.PreInitialization)) { return EXE_INIT_PREINIT; } else if (kind == Shadow.ExceptionHandler) { return HANDLER; } else if ((kind == Shadow.FieldGet) || (kind == Shadow.FieldSet)) { return GET_OR_SET; } else if (kind == Shadow.StaticInitialization) { return STATICINIT; } else { return OTHER; } } if (p instanceof AnnotationPointcut) { return ANNOTATION; } if (p instanceof ArgsPointcut) { return ARGS; } if (p instanceof ArgsAnnotationPointcut) { return AT_ARGS; } if (p instanceof CflowPointcut || p instanceof ConcreteCflowPointcut) { return CFLOW; } if (p instanceof HandlerPointcut) { return HANDLER; } if (p instanceof IfPointcut) { return IF; } if (p instanceof ThisOrTargetPointcut) { return THIS_OR_TARGET; } if (p instanceof ThisOrTargetAnnotationPointcut) { return AT_THIS_OR_TARGET; } if (p instanceof WithincodePointcut) { return WITHINCODE; } if (p instanceof WithinCodeAnnotationPointcut) { return ATWITHINCODE; } if (p instanceof NotPointcut) { return getScore(((NotPointcut) p).getNegatedPointcut()); } if (p instanceof AndPointcut) { int leftScore = getScore(((AndPointcut) p).getLeft()); int rightScore = getScore(((AndPointcut) p).getRight()); if (leftScore < rightScore) { return leftScore; } else { return rightScore; } } if (p instanceof OrPointcut) { int leftScore = getScore(((OrPointcut) p).getLeft()); int rightScore = getScore(((OrPointcut) p).getRight()); if (leftScore > rightScore) { return leftScore; } else { return rightScore; } } return OTHER; }