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 4.1KB

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