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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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.DataInputStream;
  14. import java.io.DataOutputStream;
  15. import java.io.IOException;
  16. import java.lang.reflect.Member;
  17. import java.util.HashSet;
  18. import java.util.Set;
  19. import org.aspectj.lang.JoinPoint;
  20. import org.aspectj.util.FuzzyBoolean;
  21. import org.aspectj.weaver.ISourceContext;
  22. import org.aspectj.weaver.IntMap;
  23. import org.aspectj.weaver.ResolvedTypeX;
  24. import org.aspectj.weaver.Shadow;
  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. return left.match(shadow).and(right.match(shadow));
  47. }
  48. public FuzzyBoolean match(JoinPoint jp, JoinPoint.StaticPart encJP) {
  49. return left.match(jp,encJP).and(right.match(jp,encJP));
  50. }
  51. public FuzzyBoolean match(JoinPoint.StaticPart jpsp) {
  52. return left.match(jpsp).and(right.match(jpsp));
  53. }
  54. /* (non-Javadoc)
  55. * @see org.aspectj.weaver.tools.PointcutExpression#matchesDynamically(java.lang.Object, java.lang.Object, java.lang.Object[])
  56. */
  57. public boolean matchesDynamically(Object thisObject, Object targetObject,
  58. Object[] args) {
  59. return left.matchesDynamically(thisObject,targetObject,args) &&
  60. right.matchesDynamically(thisObject,targetObject,args);
  61. }
  62. /* (non-Javadoc)
  63. * @see org.aspectj.weaver.patterns.Pointcut#matchesStatically(java.lang.String, java.lang.reflect.Member, java.lang.Class, java.lang.Class, java.lang.reflect.Member)
  64. */
  65. public FuzzyBoolean matchesStatically(
  66. String joinpointKind, Member member, Class thisClass,
  67. Class targetClass, Member withinCode) {
  68. return left.matchesStatically(joinpointKind,member,thisClass,targetClass,withinCode)
  69. .and(
  70. right.matchesStatically(joinpointKind,member,thisClass,targetClass,withinCode));
  71. }
  72. public String toString() {
  73. return "(" + left.toString() + " && " + right.toString() + ")";
  74. }
  75. public boolean equals(Object other) {
  76. if (!(other instanceof AndPointcut)) return false;
  77. AndPointcut o = (AndPointcut)other;
  78. return o.left.equals(left) && o.right.equals(right);
  79. }
  80. public int hashCode() {
  81. int result = 19;
  82. result = 37*result + left.hashCode();
  83. result = 37*result + right.hashCode();
  84. return result;
  85. }
  86. public void resolveBindings(IScope scope, Bindings bindings) {
  87. left.resolveBindings(scope, bindings);
  88. right.resolveBindings(scope, bindings);
  89. }
  90. public void resolveBindingsFromRTTI() {
  91. left.resolveBindingsFromRTTI();
  92. right.resolveBindingsFromRTTI();
  93. }
  94. public void write(DataOutputStream s) throws IOException {
  95. s.writeByte(Pointcut.AND);
  96. left.write(s);
  97. right.write(s);
  98. writeLocation(s);
  99. }
  100. public static Pointcut read(DataInputStream s, ISourceContext context) throws IOException {
  101. AndPointcut ret = new AndPointcut(Pointcut.read(s, context), Pointcut.read(s, context));
  102. ret.readLocation(context, s);
  103. return ret;
  104. }
  105. protected Test findResidueInternal(Shadow shadow, ExposedState state) {
  106. return Test.makeAnd(left.findResidue(shadow, state), right.findResidue(shadow, state));
  107. }
  108. public Pointcut concretize1(ResolvedTypeX inAspect, IntMap bindings) {
  109. AndPointcut ret = new AndPointcut(left.concretize(inAspect, bindings),
  110. right.concretize(inAspect, bindings));
  111. ret.copyLocationFrom(this);
  112. return ret;
  113. }
  114. public Pointcut getLeft() {
  115. return left;
  116. }
  117. public Pointcut getRight() {
  118. return right;
  119. }
  120. }