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 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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.weaver.CompressingDataOutputStream;
  16. import org.aspectj.weaver.ISourceContext;
  17. import org.aspectj.weaver.UnresolvedType;
  18. import org.aspectj.weaver.VersionedDataInputStream;
  19. import org.aspectj.weaver.World;
  20. public class DeclareErrorOrWarning extends Declare {
  21. private boolean isError;
  22. private Pointcut pointcut;
  23. private String message;
  24. public DeclareErrorOrWarning(boolean isError, Pointcut pointcut, String message) {
  25. this.isError = isError;
  26. this.pointcut = pointcut;
  27. this.message = message;
  28. }
  29. /**
  30. * returns "declare warning: <message>" or "declare error: <message>"
  31. */
  32. public String toString() {
  33. StringBuilder buf = new StringBuilder();
  34. buf.append("declare ");
  35. if (isError) {
  36. buf.append("error: ");
  37. } else {
  38. buf.append("warning: ");
  39. }
  40. buf.append(pointcut);
  41. buf.append(": ");
  42. buf.append("\"");
  43. buf.append(message);
  44. buf.append("\";");
  45. return buf.toString();
  46. }
  47. public boolean equals(Object other) {
  48. if (!(other instanceof DeclareErrorOrWarning)) {
  49. return false;
  50. }
  51. DeclareErrorOrWarning o = (DeclareErrorOrWarning) other;
  52. return (o.isError == isError) && o.pointcut.equals(pointcut) && o.message.equals(message);
  53. }
  54. public int hashCode() {
  55. int result = isError ? 19 : 23;
  56. result = 37 * result + pointcut.hashCode();
  57. result = 37 * result + message.hashCode();
  58. return result;
  59. }
  60. public Object accept(PatternNodeVisitor visitor, Object data) {
  61. return visitor.visit(this, data);
  62. }
  63. public Object traverse(PatternNodeVisitor visitor, Object data) {
  64. Object ret = accept(visitor, data);
  65. if (this.pointcut != null)
  66. this.pointcut.traverse(visitor, ret);
  67. return ret;
  68. }
  69. public void write(CompressingDataOutputStream s) throws IOException {
  70. s.writeByte(Declare.ERROR_OR_WARNING);
  71. s.writeBoolean(isError);
  72. pointcut.write(s);
  73. s.writeUTF(message);
  74. writeLocation(s);
  75. }
  76. public static Declare read(VersionedDataInputStream s, ISourceContext context) throws IOException {
  77. Declare ret = new DeclareErrorOrWarning(s.readBoolean(), Pointcut.read(s, context), s.readUTF());
  78. ret.readLocation(context, s);
  79. return ret;
  80. }
  81. public boolean isError() {
  82. return isError;
  83. }
  84. public String getMessage() {
  85. return message;
  86. }
  87. public Pointcut getPointcut() {
  88. return pointcut;
  89. }
  90. public void resolve(IScope scope) {
  91. pointcut = pointcut.resolve(scope);
  92. }
  93. public Declare parameterizeWith(Map<String,UnresolvedType> typeVariableBindingMap, World w) {
  94. Declare ret = new DeclareErrorOrWarning(isError, pointcut.parameterizeWith(typeVariableBindingMap, w), message);
  95. ret.copyLocationFrom(this);
  96. return ret;
  97. }
  98. public boolean isAdviceLike() {
  99. return true;
  100. }
  101. public String getNameSuffix() {
  102. return "eow";
  103. }
  104. /**
  105. * returns "declare warning" or "declare error"
  106. */
  107. public String getName() {
  108. StringBuilder buf = new StringBuilder();
  109. buf.append("declare ");
  110. if (isError) {
  111. buf.append("error");
  112. } else {
  113. buf.append("warning");
  114. }
  115. return buf.toString();
  116. }
  117. }