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.

DeclareTypeErrorOrWarning.java 3.5KB

пре 14 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* *******************************************************************
  2. * Copyright (c) 2010 Contributors
  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. * Andy Clement 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.VersionedDataInputStream;
  18. import org.aspectj.weaver.World;
  19. /**
  20. * For a declare error/warning that specified a type pattern rather than a pointcut.
  21. *
  22. * @author Andy Clement
  23. * @since 1.6.9
  24. */
  25. public class DeclareTypeErrorOrWarning extends Declare {
  26. private boolean isError;
  27. private TypePattern typePattern;
  28. private String message;
  29. public DeclareTypeErrorOrWarning(boolean isError, TypePattern typePattern, String message) {
  30. this.isError = isError;
  31. this.typePattern = typePattern;
  32. this.message = message;
  33. }
  34. /**
  35. * returns "declare warning: <typepattern>: <message>" or "declare error: <typepattern>: <message>"
  36. */
  37. public String toString() {
  38. StringBuffer buf = new StringBuffer();
  39. buf.append("declare ");
  40. if (isError) {
  41. buf.append("error: ");
  42. } else {
  43. buf.append("warning: ");
  44. }
  45. buf.append(typePattern);
  46. buf.append(": ");
  47. buf.append("\"");
  48. buf.append(message);
  49. buf.append("\";");
  50. return buf.toString();
  51. }
  52. public boolean equals(Object other) {
  53. if (!(other instanceof DeclareTypeErrorOrWarning)) {
  54. return false;
  55. }
  56. DeclareTypeErrorOrWarning o = (DeclareTypeErrorOrWarning) other;
  57. return (o.isError == isError) && o.typePattern.equals(typePattern) && o.message.equals(message);
  58. }
  59. public int hashCode() {
  60. int result = isError ? 19 : 23;
  61. result = 37 * result + typePattern.hashCode();
  62. result = 37 * result + message.hashCode();
  63. return result;
  64. }
  65. public Object accept(PatternNodeVisitor visitor, Object data) {
  66. return visitor.visit(this, data);
  67. }
  68. public void write(CompressingDataOutputStream s) throws IOException {
  69. s.writeByte(Declare.TYPE_ERROR_OR_WARNING);
  70. s.writeBoolean(isError);
  71. typePattern.write(s);
  72. s.writeUTF(message);
  73. writeLocation(s);
  74. }
  75. public static Declare read(VersionedDataInputStream s, ISourceContext context) throws IOException {
  76. Declare ret = new DeclareTypeErrorOrWarning(s.readBoolean(), TypePattern.read(s, context), s.readUTF());
  77. ret.readLocation(context, s);
  78. return ret;
  79. }
  80. public boolean isError() {
  81. return isError;
  82. }
  83. public String getMessage() {
  84. return message;
  85. }
  86. public TypePattern getTypePattern() {
  87. return typePattern;
  88. }
  89. public void resolve(IScope scope) {
  90. typePattern.resolve(scope.getWorld());
  91. }
  92. public Declare parameterizeWith(Map typeVariableBindingMap, World w) {
  93. Declare ret = new DeclareTypeErrorOrWarning(isError, typePattern.parameterizeWith(typeVariableBindingMap, w), message);
  94. ret.copyLocationFrom(this);
  95. return ret;
  96. }
  97. public boolean isAdviceLike() {
  98. return false;
  99. }
  100. public String getNameSuffix() {
  101. return "teow";
  102. }
  103. /**
  104. * returns "declare type warning" or "declare type error"
  105. */
  106. public String getName() {
  107. StringBuffer buf = new StringBuffer();
  108. buf.append("declare type ");
  109. if (isError) {
  110. buf.append("error");
  111. } else {
  112. buf.append("warning");
  113. }
  114. return buf.toString();
  115. }
  116. }