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.

HandlerPointcut.java 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.apache.bcel.classfile.JavaClass;
  15. import org.aspectj.weaver.*;
  16. import org.aspectj.weaver.ast.*;
  17. import org.aspectj.bridge.MessageUtil;
  18. import org.aspectj.util.FuzzyBoolean;
  19. /**
  20. * This is a kind of KindedPointcut. This belongs either in
  21. * a hierarchy with it or in a new place to share code
  22. * with other potential future statement-level pointcuts like
  23. * synchronized and throws
  24. */
  25. public class HandlerPointcut extends Pointcut {
  26. TypePattern exceptionType;
  27. public HandlerPointcut(TypePattern exceptionType) {
  28. this.exceptionType = exceptionType;
  29. }
  30. public FuzzyBoolean match(Shadow shadow) {
  31. if (shadow.getKind() != Shadow.ExceptionHandler) return FuzzyBoolean.NO;
  32. // we know we have exactly one parameter since we're checking an exception handler
  33. return exceptionType.matches(
  34. shadow.getSignature().getParameterTypes()[0].resolve(shadow.getIWorld()),
  35. TypePattern.STATIC);
  36. }
  37. public boolean equals(Object other) {
  38. if (!(other instanceof HandlerPointcut)) return false;
  39. HandlerPointcut o = (HandlerPointcut)other;
  40. return o.exceptionType.equals(this.exceptionType); }
  41. public int hashCode() {
  42. int result = 17;
  43. result = 37*result + exceptionType.hashCode();
  44. return result;
  45. }
  46. public String toString() {
  47. StringBuffer buf = new StringBuffer();
  48. buf.append("handler(");
  49. buf.append(exceptionType.toString());
  50. buf.append(")");
  51. return buf.toString();
  52. }
  53. public void write(DataOutputStream s) throws IOException {
  54. s.writeByte(Pointcut.HANDLER);
  55. exceptionType.write(s);
  56. writeLocation(s);
  57. }
  58. public static Pointcut read(DataInputStream s, ISourceContext context) throws IOException {
  59. HandlerPointcut ret = new HandlerPointcut(TypePattern.read(s, context));
  60. ret.readLocation(context, s);
  61. return ret;
  62. }
  63. // XXX note: there is no namebinding in any kinded pointcut.
  64. // still might want to do something for better error messages
  65. // We want to do something here to make sure we don't sidestep the parameter
  66. // list in capturing type identifiers.
  67. public void resolveBindings(IScope scope, Bindings bindings) {
  68. exceptionType = exceptionType.resolveBindings(scope, bindings, false, false);
  69. //XXX add error if exact binding and not an exception
  70. }
  71. public Test findResidue(Shadow shadow, ExposedState state) {
  72. return match(shadow).alwaysTrue() ? Literal.TRUE : Literal.FALSE;
  73. }
  74. public Pointcut concretize1(ResolvedTypeX inAspect, IntMap bindings) {
  75. return new HandlerPointcut(exceptionType);
  76. }
  77. }