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.

WithinPointcut.java 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. * Xerox/PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.patterns;
  13. import java.io.*;
  14. import org.aspectj.weaver.*;
  15. import org.aspectj.weaver.ast.*;
  16. import org.aspectj.util.*;
  17. public class WithinPointcut extends Pointcut {
  18. TypePattern type;
  19. public WithinPointcut(TypePattern type) {
  20. this.type = type;
  21. }
  22. public FuzzyBoolean match(Shadow shadow) {
  23. TypeX enclosingType = shadow.getEnclosingType();
  24. while (enclosingType != null) {
  25. if (type.matchesStatically(shadow.getIWorld().resolve(enclosingType))) {
  26. return FuzzyBoolean.YES;
  27. }
  28. enclosingType = enclosingType.getDeclaringType();
  29. }
  30. return FuzzyBoolean.NO;
  31. }
  32. public void write(DataOutputStream s) throws IOException {
  33. s.writeByte(Pointcut.WITHIN);
  34. type.write(s);
  35. writeLocation(s);
  36. }
  37. public static Pointcut read(DataInputStream s, ISourceContext context) throws IOException {
  38. TypePattern type = TypePattern.read(s, context);
  39. WithinPointcut ret = new WithinPointcut(type);
  40. ret.readLocation(context, s);
  41. return ret;
  42. }
  43. public void resolveBindings(IScope scope, Bindings bindings) {
  44. type = type.resolveBindings(scope, bindings, false, false);
  45. }
  46. public void postRead(ResolvedTypeX enclosingType) {
  47. type.postRead(enclosingType);
  48. }
  49. public boolean equals(Object other) {
  50. if (!(other instanceof WithinPointcut)) return false;
  51. WithinPointcut o = (WithinPointcut)other;
  52. return o.type.equals(this.type);
  53. }
  54. public int hashCode() {
  55. int result = 43;
  56. result = 37*result + type.hashCode();
  57. return result;
  58. }
  59. public String toString() {
  60. return "within(" + type + ")";
  61. }
  62. public Test findResidue(Shadow shadow, ExposedState state) {
  63. return match(shadow).alwaysTrue() ? Literal.TRUE : Literal.FALSE;
  64. }
  65. public Pointcut concretize1(ResolvedTypeX inAspect, IntMap bindings) {
  66. return this; //??? no pointers out of here so we're okay
  67. }
  68. }