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.

DeclareErrorOrWarning.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.patterns;
  13. import java.io.DataOutputStream;
  14. import java.io.IOException;
  15. import org.aspectj.weaver.ISourceContext;
  16. import org.aspectj.weaver.VersionedDataInputStream;
  17. public class DeclareErrorOrWarning extends Declare {
  18. private boolean isError;
  19. private Pointcut pointcut;
  20. private String message;
  21. public DeclareErrorOrWarning(boolean isError, Pointcut pointcut, String message) {
  22. this.isError = isError;
  23. this.pointcut = pointcut;
  24. this.message = message;
  25. }
  26. public String toString() {
  27. StringBuffer buf = new StringBuffer();
  28. buf.append("declare ");
  29. if (isError) buf.append("error: ");
  30. else buf.append("warning: ");
  31. buf.append(pointcut);
  32. buf.append(": ");
  33. buf.append("\"");
  34. buf.append(message);
  35. buf.append("\";");
  36. return buf.toString();
  37. }
  38. public boolean equals(Object other) {
  39. if (!(other instanceof DeclareErrorOrWarning)) return false;
  40. DeclareErrorOrWarning o = (DeclareErrorOrWarning)other;
  41. return (o.isError == isError) &&
  42. o.pointcut.equals(pointcut) &&
  43. o.message.equals(message);
  44. }
  45. public int hashCode() {
  46. int result = isError ? 19 : 23;
  47. result = 37*result + pointcut.hashCode();
  48. result = 37*result + message.hashCode();
  49. return result;
  50. }
  51. public void write(DataOutputStream s) throws IOException {
  52. s.writeByte(Declare.ERROR_OR_WARNING);
  53. s.writeBoolean(isError);
  54. pointcut.write(s);
  55. s.writeUTF(message);
  56. writeLocation(s);
  57. }
  58. public static Declare read(VersionedDataInputStream s, ISourceContext context) throws IOException {
  59. Declare ret = new DeclareErrorOrWarning(
  60. s.readBoolean(),
  61. Pointcut.read(s, context),
  62. s.readUTF()
  63. );
  64. ret.readLocation(context, s);
  65. return ret;
  66. }
  67. public boolean isError() {
  68. return isError;
  69. }
  70. public String getMessage() {
  71. return message;
  72. }
  73. public Pointcut getPointcut() {
  74. return pointcut;
  75. }
  76. public void resolve(IScope scope) {
  77. pointcut = pointcut.resolve(scope);
  78. }
  79. public boolean isAdviceLike() {
  80. return true;
  81. }
  82. }