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.

IMessage.java 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* *******************************************************************
  2. * Copyright (c) 1999-2001 Xerox Corporation,
  3. * 2002 Palo Alto Research Center, Incorporated (PARC).
  4. * All rights reserved.
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Public License v1.0
  7. * which accompanies this distribution and is available at
  8. * http://www.eclipse.org/legal/epl-v10.html
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * ******************************************************************/
  13. package org.aspectj.bridge;
  14. import java.util.Arrays;
  15. import java.util.Collections;
  16. import java.util.Comparator;
  17. import java.util.List;
  18. /**
  19. * Wrap message with any associated throwable or source location.
  20. */
  21. public interface IMessage {
  22. /** no messages */
  23. IMessage[] RA_IMessage = new IMessage[0];
  24. // int values must sync with KINDS order below
  25. Kind WEAVEINFO = new Kind("weaveinfo", 5);
  26. Kind INFO = new Kind("info", 10);
  27. Kind DEBUG = new Kind("debug", 20);
  28. Kind TASKTAG = new Kind("task", 25); // represents a 'TODO' from eclipse - producted by the compiler and
  29. // consumed by AJDT
  30. Kind WARNING = new Kind("warning", 30);
  31. Kind ERROR = new Kind("error", 40);
  32. Kind FAIL = new Kind("fail", 50);
  33. Kind ABORT = new Kind("abort", 60);
  34. // XXX prefer another Kind to act as selector for "any",
  35. // but can't prohibit creating messages with it.
  36. // public static final Kind ANY = new Kind("any-selector", 0);
  37. /**
  38. * list of Kind in precedence order. 0 is less than IMessage.Kind#COMPARATOR.compareTo(KINDS.get(i), KINDS.get(i + 1))
  39. */
  40. List<Kind> KINDS = Collections.unmodifiableList(Arrays.asList(new Kind[] { WEAVEINFO, INFO, DEBUG, TASKTAG,
  41. WARNING, ERROR, FAIL, ABORT }));
  42. /** @return non-null String with simple message */
  43. String getMessage();
  44. /** @return the kind of this message */
  45. Kind getKind();
  46. /** @return true if this is an error */
  47. boolean isError();
  48. /** @return true if this is a warning */
  49. boolean isWarning();
  50. /** @return true if this is an internal debug message */
  51. boolean isDebug();
  52. /** @return true if this is information for the user */
  53. boolean isInfo();
  54. /** @return true if the process is aborting */
  55. boolean isAbort(); // XXX ambiguous
  56. /** @return true if this is a task tag message */
  57. boolean isTaskTag();
  58. /** @return true if something failed */
  59. boolean isFailed();
  60. /** Caller can verify if this message came about because of a DEOW */
  61. boolean getDeclared();
  62. /** Return the ID of the message where applicable, see IProblem for list of valid IDs */
  63. int getID();
  64. /** Return the start position of the problem (inclusive), or -1 if unknown. */
  65. int getSourceStart();
  66. /** Return the end position of the problem (inclusive), or -1 if unknown. */
  67. int getSourceEnd();
  68. /** @return Throwable associated with this message, or null if none */
  69. Throwable getThrown();
  70. /** @return source location associated with this message, or null if none */
  71. ISourceLocation getSourceLocation();
  72. final class Kind implements Comparable<IMessage.Kind> {
  73. public static final Comparator<IMessage.Kind> COMPARATOR = new Comparator<IMessage.Kind>() {
  74. public int compare(IMessage.Kind one, IMessage.Kind two) {
  75. if (null == one) {
  76. return (null == two ? 0 : -1);
  77. } else if (null == two) {
  78. return 1;
  79. } else if (one == two) {
  80. return 0;
  81. } else {
  82. return (one.precedence - two.precedence);
  83. }
  84. }
  85. };
  86. /**
  87. * @param kind the Kind floor
  88. * @return false if kind is null or this has less precedence than kind, true otherwise.
  89. */
  90. public boolean isSameOrLessThan(Kind kind) {
  91. return (0 >= COMPARATOR.compare(this, kind));
  92. }
  93. public int compareTo(IMessage.Kind other) {
  94. return COMPARATOR.compare(this, other);
  95. }
  96. private final int precedence;
  97. private final String name;
  98. private Kind(String name, int precedence) {
  99. this.name = name;
  100. this.precedence = precedence;
  101. }
  102. public String toString() {
  103. return name;
  104. }
  105. }
  106. /**
  107. * @return Detailed information about the message. For example, for declare error/warning messages this returns information
  108. * about the corresponding join point's static part.
  109. */
  110. String getDetails();
  111. /**
  112. * @return List of <code>ISourceLocation</code> instances that indicate additional source locations relevent to this message as
  113. * specified by the message creator. The list should not include the primary source location associated with the message
  114. * which can be obtained from <code>getSourceLocation()<code>.
  115. * <p>
  116. * An example of using extra locations would be in a warning message that
  117. * flags all shadow locations that will go unmatched due to a pointcut definition
  118. * being based on a subtype of a defining type.
  119. * @see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=41952">AspectJ bug 41952</a>
  120. */
  121. /**
  122. * Return a List of <code>ISourceLocation</code> instances that indicate additional source locations relevent to this message as
  123. * specified by the message creator. The list should not include the primary source location associated with the message
  124. * which can be obtained from <code>getSourceLocation()<code>.
  125. * <p>
  126. * An example of using extra locations would be in a warning message that
  127. * flags all shadow locations that will go unmatched due to a pointcut definition
  128. * being based on a subtype of a defining type.
  129. * </p>
  130. *
  131. * @return a list of additional source locations
  132. * @see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=41952">AspectJ bug 41952</a>
  133. */
  134. List<ISourceLocation> getExtraSourceLocations();
  135. }