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.

OrPointcut.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.patterns;
  13. import java.io.IOException;
  14. import java.util.Map;
  15. import org.aspectj.util.FuzzyBoolean;
  16. import org.aspectj.weaver.CompressingDataOutputStream;
  17. import org.aspectj.weaver.ISourceContext;
  18. import org.aspectj.weaver.IntMap;
  19. import org.aspectj.weaver.ResolvedType;
  20. import org.aspectj.weaver.Shadow;
  21. import org.aspectj.weaver.VersionedDataInputStream;
  22. import org.aspectj.weaver.World;
  23. import org.aspectj.weaver.ast.Test;
  24. public class OrPointcut extends Pointcut {
  25. Pointcut left, right;
  26. private int couldMatchKinds;
  27. public OrPointcut(Pointcut left, Pointcut right) {
  28. super();
  29. this.left = left;
  30. this.right = right;
  31. setLocation(left.getSourceContext(), left.getStart(), right.getEnd());
  32. this.pointcutKind = OR;
  33. this.couldMatchKinds = left.couldMatchKinds() | right.couldMatchKinds();
  34. }
  35. public int couldMatchKinds() {
  36. return couldMatchKinds;
  37. }
  38. public FuzzyBoolean fastMatch(FastMatchInfo type) {
  39. return left.fastMatch(type).or(right.fastMatch(type));
  40. }
  41. protected FuzzyBoolean matchInternal(Shadow shadow) {
  42. FuzzyBoolean leftMatch = left.match(shadow);
  43. if (leftMatch.alwaysTrue()) {
  44. return leftMatch;
  45. }
  46. return leftMatch.or(right.match(shadow));
  47. }
  48. public String toString() {
  49. return "(" + left.toString() + " || " + right.toString() + ")";
  50. }
  51. public boolean equals(Object other) {
  52. if (!(other instanceof OrPointcut)) {
  53. return false;
  54. }
  55. OrPointcut o = (OrPointcut) other;
  56. return o.left.equals(left) && o.right.equals(right);
  57. }
  58. public int hashCode() {
  59. int result = 31;
  60. result = 37 * result + left.hashCode();
  61. result = 37 * result + right.hashCode();
  62. return result;
  63. }
  64. /**
  65. * @see org.aspectj.weaver.patterns.Pointcut#resolveBindings(IScope, Bindings)
  66. */
  67. public void resolveBindings(IScope scope, Bindings bindings) {
  68. Bindings old = bindings == null ? null : bindings.copy();
  69. left.resolveBindings(scope, bindings);
  70. right.resolveBindings(scope, old);
  71. if (bindings != null) {
  72. bindings.checkEquals(old, scope);
  73. }
  74. }
  75. public void write(CompressingDataOutputStream s) throws IOException {
  76. s.writeByte(Pointcut.OR);
  77. left.write(s);
  78. right.write(s);
  79. writeLocation(s);
  80. }
  81. public static Pointcut read(VersionedDataInputStream s, ISourceContext context) throws IOException {
  82. OrPointcut ret = new OrPointcut(Pointcut.read(s, context), Pointcut.read(s, context));
  83. ret.readLocation(context, s);
  84. return ret;
  85. }
  86. protected Test findResidueInternal(Shadow shadow, ExposedState state) {
  87. return Test.makeOr(left.findResidue(shadow, state), right.findResidue(shadow, state));
  88. }
  89. public Pointcut concretize1(ResolvedType inAspect, ResolvedType declaringType, IntMap bindings) {
  90. Pointcut ret = new OrPointcut(left.concretize(inAspect, declaringType, bindings), right.concretize(inAspect, declaringType,
  91. bindings));
  92. ret.copyLocationFrom(this);
  93. return ret;
  94. }
  95. public Pointcut parameterizeWith(Map typeVariableMap, World w) {
  96. Pointcut ret = new OrPointcut(left.parameterizeWith(typeVariableMap, w), right.parameterizeWith(typeVariableMap, w));
  97. ret.copyLocationFrom(this);
  98. return ret;
  99. }
  100. public Pointcut getLeft() {
  101. return left;
  102. }
  103. public Pointcut getRight() {
  104. return right;
  105. }
  106. public Object accept(PatternNodeVisitor visitor, Object data) {
  107. return visitor.visit(this, data);
  108. }
  109. public Object traverse(PatternNodeVisitor visitor, Object data) {
  110. Object ret = accept(visitor, data);
  111. left.traverse(visitor, ret);
  112. right.traverse(visitor, ret);
  113. return ret;
  114. }
  115. }