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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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.UnresolvedType;
  22. import org.aspectj.weaver.VersionedDataInputStream;
  23. import org.aspectj.weaver.World;
  24. import org.aspectj.weaver.ast.Test;
  25. public class AndPointcut extends Pointcut {
  26. Pointcut left, right; // exposed for testing
  27. private int couldMatchKinds;
  28. public AndPointcut(Pointcut left, Pointcut right) {
  29. super();
  30. this.left = left;
  31. this.right = right;
  32. this.pointcutKind = AND;
  33. setLocation(left.getSourceContext(), left.getStart(), right.getEnd());
  34. 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.alwaysFalse()) {
  42. return leftMatch;
  43. }
  44. return leftMatch.and(right.fastMatch(type));
  45. }
  46. protected FuzzyBoolean matchInternal(Shadow shadow) {
  47. FuzzyBoolean leftMatch = left.match(shadow);
  48. if (leftMatch.alwaysFalse()) {
  49. return leftMatch;
  50. }
  51. return leftMatch.and(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 AndPointcut)) {
  58. return false;
  59. }
  60. AndPointcut o = (AndPointcut) other;
  61. return o.left.equals(left) && o.right.equals(right);
  62. }
  63. public int hashCode() {
  64. int result = 19;
  65. result = 37 * result + left.hashCode();
  66. result = 37 * result + right.hashCode();
  67. return result;
  68. }
  69. public void resolveBindings(IScope scope, Bindings bindings) {
  70. left.resolveBindings(scope, bindings);
  71. right.resolveBindings(scope, bindings);
  72. }
  73. public void write(CompressingDataOutputStream s) throws IOException {
  74. s.writeByte(Pointcut.AND);
  75. left.write(s);
  76. right.write(s);
  77. writeLocation(s);
  78. }
  79. public static Pointcut read(VersionedDataInputStream s, ISourceContext context) throws IOException {
  80. AndPointcut ret = new AndPointcut(Pointcut.read(s, context), Pointcut.read(s, context));
  81. ret.readLocation(context, s);
  82. return ret;
  83. }
  84. protected Test findResidueInternal(Shadow shadow, ExposedState state) {
  85. return Test.makeAnd(left.findResidue(shadow, state), right.findResidue(shadow, state));
  86. }
  87. public Pointcut concretize1(ResolvedType inAspect, ResolvedType declaringType, IntMap bindings) {
  88. AndPointcut ret = new AndPointcut(left.concretize(inAspect, declaringType, bindings), right.concretize(inAspect,
  89. declaringType, bindings));
  90. ret.copyLocationFrom(this);
  91. ret.m_ignoreUnboundBindingForNames = m_ignoreUnboundBindingForNames;
  92. return ret;
  93. }
  94. @Override
  95. public Pointcut parameterizeWith(Map<String,UnresolvedType> typeVariableMap, World w) {
  96. AndPointcut ret = new AndPointcut(left.parameterizeWith(typeVariableMap, w), right.parameterizeWith(typeVariableMap, w));
  97. ret.copyLocationFrom(this);
  98. ret.m_ignoreUnboundBindingForNames = m_ignoreUnboundBindingForNames;
  99. return ret;
  100. }
  101. public Pointcut getLeft() {
  102. return left;
  103. }
  104. public Pointcut getRight() {
  105. return right;
  106. }
  107. public Object accept(PatternNodeVisitor visitor, Object data) {
  108. return visitor.visit(this, data);
  109. }
  110. public Object traverse(PatternNodeVisitor visitor, Object data) {
  111. Object ret = accept(visitor, data);
  112. left.traverse(visitor, ret);
  113. right.traverse(visitor, ret);
  114. return ret;
  115. }
  116. }