You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AndPointcut.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Common Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/cpl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.patterns;
  13. import java.io.DataOutputStream;
  14. import java.io.IOException;
  15. import java.lang.reflect.Member;
  16. import java.util.HashSet;
  17. import java.util.Set;
  18. import org.aspectj.lang.JoinPoint;
  19. import org.aspectj.util.FuzzyBoolean;
  20. import org.aspectj.weaver.ISourceContext;
  21. import org.aspectj.weaver.IntMap;
  22. import org.aspectj.weaver.ResolvedTypeX;
  23. import org.aspectj.weaver.Shadow;
  24. import org.aspectj.weaver.VersionedDataInputStream;
  25. import org.aspectj.weaver.ast.Test;
  26. public class AndPointcut extends Pointcut {
  27. Pointcut left, right; // exposed for testing
  28. private Set couldMatchKinds;
  29. public AndPointcut(Pointcut left, Pointcut right) {
  30. super();
  31. this.left = left;
  32. this.right = right;
  33. this.pointcutKind = AND;
  34. setLocation(left.getSourceContext(), left.getStart(), right.getEnd());
  35. couldMatchKinds = new HashSet();
  36. couldMatchKinds.addAll(left.couldMatchKinds());
  37. couldMatchKinds.retainAll(right.couldMatchKinds());
  38. }
  39. public Set couldMatchKinds() {
  40. return couldMatchKinds;
  41. }
  42. public FuzzyBoolean fastMatch(FastMatchInfo type) {
  43. return left.fastMatch(type).and(right.fastMatch(type));
  44. }
  45. protected FuzzyBoolean matchInternal(Shadow shadow) {
  46. FuzzyBoolean leftMatch = left.match(shadow);
  47. if (leftMatch.alwaysFalse()) return leftMatch;
  48. return leftMatch.and(right.match(shadow));
  49. }
  50. public FuzzyBoolean match(JoinPoint jp, JoinPoint.StaticPart encJP) {
  51. return left.match(jp,encJP).and(right.match(jp,encJP));
  52. }
  53. public FuzzyBoolean match(JoinPoint.StaticPart jpsp) {
  54. return left.match(jpsp).and(right.match(jpsp));
  55. }
  56. /* (non-Javadoc)
  57. * @see org.aspectj.weaver.tools.PointcutExpression#matchesDynamically(java.lang.Object, java.lang.Object, java.lang.Object[])
  58. */
  59. public boolean matchesDynamically(Object thisObject, Object targetObject,
  60. Object[] args) {
  61. return left.matchesDynamically(thisObject,targetObject,args) &&
  62. right.matchesDynamically(thisObject,targetObject,args);
  63. }
  64. /* (non-Javadoc)
  65. * @see org.aspectj.weaver.patterns.Pointcut#matchesStatically(java.lang.String, java.lang.reflect.Member, java.lang.Class, java.lang.Class, java.lang.reflect.Member)
  66. */
  67. public FuzzyBoolean matchesStatically(
  68. String joinpointKind, Member member, Class thisClass,
  69. Class targetClass, Member withinCode) {
  70. return left.matchesStatically(joinpointKind,member,thisClass,targetClass,withinCode)
  71. .and(
  72. right.matchesStatically(joinpointKind,member,thisClass,targetClass,withinCode));
  73. }
  74. public String toString() {
  75. return "(" + left.toString() + " && " + right.toString() + ")";
  76. }
  77. public boolean equals(Object other) {
  78. if (!(other instanceof AndPointcut)) return false;
  79. AndPointcut o = (AndPointcut)other;
  80. return o.left.equals(left) && o.right.equals(right);
  81. }
  82. public int hashCode() {
  83. int result = 19;
  84. result = 37*result + left.hashCode();
  85. result = 37*result + right.hashCode();
  86. return result;
  87. }
  88. public void resolveBindings(IScope scope, Bindings bindings) {
  89. left.resolveBindings(scope, bindings);
  90. right.resolveBindings(scope, bindings);
  91. }
  92. public void resolveBindingsFromRTTI() {
  93. left.resolveBindingsFromRTTI();
  94. right.resolveBindingsFromRTTI();
  95. }
  96. public void write(DataOutputStream s) throws IOException {
  97. s.writeByte(Pointcut.AND);
  98. left.write(s);
  99. right.write(s);
  100. writeLocation(s);
  101. }
  102. public static Pointcut read(VersionedDataInputStream s, ISourceContext context) throws IOException {
  103. AndPointcut ret = new AndPointcut(Pointcut.read(s, context), Pointcut.read(s, context));
  104. ret.readLocation(context, s);
  105. return ret;
  106. }
  107. protected Test findResidueInternal(Shadow shadow, ExposedState state) {
  108. return Test.makeAnd(left.findResidue(shadow, state), right.findResidue(shadow, state));
  109. }
  110. public Pointcut concretize1(ResolvedTypeX inAspect, IntMap bindings) {
  111. AndPointcut ret = new AndPointcut(left.concretize(inAspect, bindings),
  112. right.concretize(inAspect, bindings));
  113. ret.copyLocationFrom(this);
  114. return ret;
  115. }
  116. public Pointcut getLeft() {
  117. return left;
  118. }
  119. public Pointcut getRight() {
  120. return right;
  121. }
  122. }