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.

DeclareSoft.java 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.ISourceContext;
  15. public class DeclareSoft extends Declare {
  16. private TypePattern exception;
  17. private Pointcut pointcut;
  18. public DeclareSoft(TypePattern exception, Pointcut pointcut) {
  19. this.exception = exception;
  20. this.pointcut = pointcut;
  21. }
  22. public String toString() {
  23. StringBuffer buf = new StringBuffer();
  24. buf.append("declare soft: ");
  25. buf.append(exception);
  26. buf.append(": ");
  27. buf.append(pointcut);
  28. buf.append(";");
  29. return buf.toString();
  30. }
  31. public boolean equals(Object other) {
  32. if (!(other instanceof DeclareSoft)) return false;
  33. DeclareSoft o = (DeclareSoft)other;
  34. return
  35. o.pointcut.equals(pointcut) &&
  36. o.exception.equals(exception);
  37. }
  38. public int hashCode() {
  39. int result = 19;
  40. result = 37*result + pointcut.hashCode();
  41. result = 37*result + exception.hashCode();
  42. return result;
  43. }
  44. public void write(DataOutputStream s) throws IOException {
  45. s.writeByte(Declare.SOFT);
  46. exception.write(s);
  47. pointcut.write(s);
  48. writeLocation(s);
  49. }
  50. public static Declare read(DataInputStream s, ISourceContext context) throws IOException {
  51. Declare ret = new DeclareSoft(
  52. TypePattern.read(s, context),
  53. Pointcut.read(s, context)
  54. );
  55. ret.readLocation(context, s);
  56. return ret;
  57. }
  58. public Pointcut getPointcut() {
  59. return pointcut;
  60. }
  61. public TypePattern getException() {
  62. return exception;
  63. }
  64. public void resolve(IScope scope) {
  65. exception = exception.resolveBindings(scope, null, false, true);
  66. pointcut = pointcut.resolve(scope);
  67. }
  68. public boolean isAdviceLike() {
  69. return true;
  70. }
  71. }