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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  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. StringBuffer buf = new StringBuffer();
  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 void write(CompressingDataOutputStream s) throws IOException {
  64. s.writeByte(Declare.ERROR_OR_WARNING);
  65. s.writeBoolean(isError);
  66. pointcut.write(s);
  67. s.writeUTF(message);
  68. writeLocation(s);
  69. }
  70. public static Declare read(VersionedDataInputStream s, ISourceContext context) throws IOException {
  71. Declare ret = new DeclareErrorOrWarning(s.readBoolean(), Pointcut.read(s, context), s.readUTF());
  72. ret.readLocation(context, s);
  73. return ret;
  74. }
  75. public boolean isError() {
  76. return isError;
  77. }
  78. public String getMessage() {
  79. return message;
  80. }
  81. public Pointcut getPointcut() {
  82. return pointcut;
  83. }
  84. public void resolve(IScope scope) {
  85. pointcut = pointcut.resolve(scope);
  86. }
  87. public Declare parameterizeWith(Map<String,UnresolvedType> typeVariableBindingMap, World w) {
  88. Declare ret = new DeclareErrorOrWarning(isError, pointcut.parameterizeWith(typeVariableBindingMap, w), message);
  89. ret.copyLocationFrom(this);
  90. return ret;
  91. }
  92. public boolean isAdviceLike() {
  93. return true;
  94. }
  95. public String getNameSuffix() {
  96. return "eow";
  97. }
  98. /**
  99. * returns "declare warning" or "declare error"
  100. */
  101. public String getName() {
  102. StringBuffer buf = new StringBuffer();
  103. buf.append("declare ");
  104. if (isError) {
  105. buf.append("error");
  106. } else {
  107. buf.append("warning");
  108. }
  109. return buf.toString();
  110. }
  111. }