Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

OrPointcut.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 OrPointcut extends Pointcut {
  27. private Pointcut left, right;
  28. private Set couldMatchKinds;
  29. public OrPointcut(Pointcut left, Pointcut right) {
  30. super();
  31. this.left = left;
  32. this.right = right;
  33. setLocation(left.getSourceContext(), left.getStart(), right.getEnd());
  34. this.pointcutKind = OR;
  35. this.couldMatchKinds = new HashSet(left.couldMatchKinds());
  36. this.couldMatchKinds.addAll(right.couldMatchKinds());
  37. }
  38. public Set couldMatchKinds() {
  39. return couldMatchKinds;
  40. }
  41. public FuzzyBoolean fastMatch(FastMatchInfo type) {
  42. return left.fastMatch(type).or(right.fastMatch(type));
  43. }
  44. protected FuzzyBoolean matchInternal(Shadow shadow) {
  45. return left.match(shadow).or(right.match(shadow));
  46. }
  47. public FuzzyBoolean match(JoinPoint jp, JoinPoint.StaticPart encJP) {
  48. return left.match(jp,encJP).or(right.match(jp,encJP));
  49. }
  50. public FuzzyBoolean match(JoinPoint.StaticPart jpsp) {
  51. return left.match(jpsp).or(right.match(jpsp));
  52. }
  53. /* (non-Javadoc)
  54. * @see org.aspectj.weaver.patterns.Pointcut#matchesDynamically(java.lang.Object, java.lang.Object, java.lang.Object[])
  55. */
  56. public boolean matchesDynamically(Object thisObject, Object targetObject,
  57. Object[] args) {
  58. return left.matchesDynamically(thisObject,targetObject,args)
  59. ||
  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. .or(
  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 OrPointcut)) return false;
  77. OrPointcut o = (OrPointcut)other;
  78. return o.left.equals(left) && o.right.equals(right);
  79. }
  80. public int hashCode() {
  81. int result = 31;
  82. result = 37*result + left.hashCode();
  83. result = 37*result + right.hashCode();
  84. return result;
  85. }
  86. /**
  87. * @see org.aspectj.weaver.patterns.Pointcut#resolveBindings(IScope, Bindings)
  88. */
  89. public void resolveBindings(IScope scope, Bindings bindings) {
  90. Bindings old = bindings == null ? null : bindings.copy();
  91. left.resolveBindings(scope, bindings);
  92. right.resolveBindings(scope, old);
  93. if (bindings != null) bindings.checkEquals(old, scope);
  94. }
  95. public void resolveBindingsFromRTTI() {
  96. left.resolveBindingsFromRTTI();
  97. right.resolveBindingsFromRTTI();
  98. }
  99. public void write(DataOutputStream s) throws IOException {
  100. s.writeByte(Pointcut.OR);
  101. left.write(s);
  102. right.write(s);
  103. writeLocation(s);
  104. }
  105. public static Pointcut read(DataInputStream s, ISourceContext context) throws IOException {
  106. OrPointcut ret = new OrPointcut(Pointcut.read(s, context), Pointcut.read(s, context));
  107. ret.readLocation(context, s);
  108. return ret;
  109. }
  110. protected Test findResidueInternal(Shadow shadow, ExposedState state) {
  111. return Test.makeOr(left.findResidue(shadow, state), right.findResidue(shadow, state));
  112. }
  113. public Pointcut concretize1(ResolvedTypeX inAspect, IntMap bindings) {
  114. Pointcut ret = new OrPointcut(left.concretize(inAspect, bindings),
  115. right.concretize(inAspect, bindings));
  116. ret.copyLocationFrom(this);
  117. return ret;
  118. }
  119. public Pointcut getLeft() {
  120. return left;
  121. }
  122. public Pointcut getRight() {
  123. return right;
  124. }
  125. }