Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

NotPointcut.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 NotPointcut extends Pointcut {
  26. private Pointcut body;
  27. public NotPointcut(Pointcut negated) {
  28. super();
  29. this.body = negated;
  30. this.pointcutKind = NOT;
  31. setLocation(negated.getSourceContext(), negated.getStart(), negated.getEnd()); // should that be at least start-1?
  32. }
  33. public NotPointcut(Pointcut pointcut, int startPos) {
  34. this(pointcut);
  35. setLocation(pointcut.getSourceContext(), startPos, pointcut.getEnd());
  36. }
  37. @Override
  38. public int couldMatchKinds() {
  39. return Shadow.ALL_SHADOW_KINDS_BITS;
  40. }
  41. public Pointcut getNegatedPointcut() {
  42. return body;
  43. }
  44. @Override
  45. public FuzzyBoolean fastMatch(FastMatchInfo type) {
  46. return body.fastMatch(type).not();
  47. }
  48. @Override
  49. protected FuzzyBoolean matchInternal(Shadow shadow) {
  50. return body.match(shadow).not();
  51. }
  52. @Override
  53. public String toString() {
  54. return "!" + body.toString();
  55. }
  56. @Override
  57. public boolean equals(Object other) {
  58. if (!(other instanceof NotPointcut)) {
  59. return false;
  60. }
  61. NotPointcut o = (NotPointcut) other;
  62. return o.body.equals(body);
  63. }
  64. @Override
  65. public int hashCode() {
  66. return 37 * 23 + body.hashCode();
  67. }
  68. @Override
  69. public void resolveBindings(IScope scope, Bindings bindings) {
  70. // Bindings old = bindings.copy();
  71. // Bindings newBindings = new Bindings(bindings.size());
  72. body.resolveBindings(scope, null);
  73. // newBindings.checkEmpty(scope, "negation does not allow binding");
  74. // bindings.checkEquals(old, scope);
  75. }
  76. @Override
  77. public void write(CompressingDataOutputStream s) throws IOException {
  78. s.writeByte(Pointcut.NOT);
  79. body.write(s);
  80. writeLocation(s);
  81. }
  82. public static Pointcut read(VersionedDataInputStream s, ISourceContext context) throws IOException {
  83. NotPointcut ret = new NotPointcut(Pointcut.read(s, context));
  84. ret.readLocation(context, s);
  85. return ret;
  86. }
  87. @Override
  88. protected Test findResidueInternal(Shadow shadow, ExposedState state) {
  89. return Test.makeNot(body.findResidue(shadow, state));
  90. }
  91. @Override
  92. public Pointcut concretize1(ResolvedType inAspect, ResolvedType declaringType, IntMap bindings) {
  93. Pointcut ret = new NotPointcut(body.concretize(inAspect, declaringType, bindings));
  94. ret.copyLocationFrom(this);
  95. return ret;
  96. }
  97. @Override
  98. public Pointcut parameterizeWith(Map<String,UnresolvedType> typeVariableMap, World w) {
  99. Pointcut ret = new NotPointcut(body.parameterizeWith(typeVariableMap, w));
  100. ret.copyLocationFrom(this);
  101. return ret;
  102. }
  103. @Override
  104. public Object accept(PatternNodeVisitor visitor, Object data) {
  105. return visitor.visit(this, data);
  106. }
  107. @Override
  108. public Object traverse(PatternNodeVisitor visitor, Object data) {
  109. Object ret = accept(visitor, data);
  110. this.body.traverse(visitor, ret);
  111. return ret;
  112. }
  113. }