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.

Message.java 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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.List;
  17. /**
  18. * Implement messages. This implementation is immutable if ISourceLocation is immutable.
  19. */
  20. public class Message implements IMessage {
  21. private final String message;
  22. private final IMessage.Kind kind;
  23. private final Throwable thrown;
  24. private final ISourceLocation sourceLocation;
  25. private final String details;
  26. private final List<ISourceLocation> extraSourceLocations;
  27. private final boolean declared; // Is it a DEOW ?
  28. private final int id;
  29. private final int sourceStart, sourceEnd;
  30. /**
  31. * Create a (compiler) error or warning message
  32. *
  33. * @param message the String used as the underlying message
  34. * @param location the ISourceLocation, if any, associated with this message
  35. * @param isError if true, use IMessage.ERROR; else use IMessage.WARNING
  36. */
  37. public Message(String message, ISourceLocation location, boolean isError) {
  38. this(message, (isError ? IMessage.ERROR : IMessage.WARNING), null, location);
  39. }
  40. public Message(String message, ISourceLocation location, boolean isError, ISourceLocation[] extraSourceLocations) {
  41. this(message, "", (isError ? IMessage.ERROR : IMessage.WARNING), location, null,
  42. (extraSourceLocations.length > 0 ? extraSourceLocations : null));
  43. }
  44. /**
  45. * Create a message, handling null values for message and kind if thrown is not null.
  46. *
  47. * @param message the String used as the underlying message
  48. * @param kind the IMessage.Kind of message - not null
  49. * @param thrown the Throwable, if any, associated with this message
  50. * @param sourceLocation the ISourceLocation, if any, associated with this message
  51. * @param details descriptive information about the message
  52. * @throws IllegalArgumentException if message is null and thrown is null or has a null message, or if kind is null and thrown
  53. * is null.
  54. */
  55. public Message(String message, String details, IMessage.Kind kind, ISourceLocation sourceLocation, Throwable thrown,
  56. ISourceLocation[] extraSourceLocations) {
  57. this(message, details, kind, sourceLocation, thrown, extraSourceLocations, false, 0, -1, -1);
  58. }
  59. public Message(String message, String details, IMessage.Kind kind, ISourceLocation sLoc, Throwable thrown,
  60. ISourceLocation[] otherLocs, boolean declared, int id, int sourcestart, int sourceend) {
  61. this.details = details;
  62. this.id = id;
  63. this.sourceStart = sourcestart;
  64. this.sourceEnd = sourceend;
  65. this.message = ((message != null) ? message : ((thrown == null) ? null : thrown.getMessage()));
  66. this.kind = kind;
  67. this.sourceLocation = sLoc;
  68. this.thrown = thrown;
  69. if (otherLocs != null) {
  70. this.extraSourceLocations = Collections.unmodifiableList(Arrays.asList(otherLocs));
  71. } else {
  72. this.extraSourceLocations = Collections.emptyList();
  73. }
  74. if (null == this.kind) {
  75. throw new IllegalArgumentException("null kind");
  76. }
  77. if (null == this.message) {
  78. throw new IllegalArgumentException("null message");
  79. }
  80. this.declared = declared;
  81. }
  82. /**
  83. * Create a message, handling null values for message and kind if thrown is not null.
  84. *
  85. * @param message the String used as the underlying message
  86. * @param kind the IMessage.Kind of message - not null
  87. * @param thrown the Throwable, if any, associated with this message
  88. * @param sourceLocation the ISourceLocation, if any, associated with this message
  89. * @throws IllegalArgumentException if message is null and thrown is null or has a null message, or if kind is null and thrown
  90. * is null.
  91. */
  92. public Message(String message, IMessage.Kind kind, Throwable thrown, ISourceLocation sourceLocation) {
  93. this(message, "", kind, sourceLocation, thrown, null);
  94. }
  95. /** @return the kind of this message */
  96. public IMessage.Kind getKind() {
  97. return kind;
  98. }
  99. /** @return true if kind == IMessage.ERROR */
  100. public boolean isError() {
  101. return kind == IMessage.ERROR;
  102. }
  103. /** @return true if kind == IMessage.WARNING */
  104. public boolean isWarning() {
  105. return kind == IMessage.WARNING;
  106. }
  107. /** @return true if kind == IMessage.DEBUG */
  108. public boolean isDebug() {
  109. return kind == IMessage.DEBUG;
  110. }
  111. public boolean isTaskTag() {
  112. return kind == IMessage.TASKTAG;
  113. }
  114. /**
  115. * @return true if kind == IMessage.INFO
  116. */
  117. public boolean isInfo() {
  118. return kind == IMessage.INFO;
  119. }
  120. /** @return true if kind == IMessage.ABORT */
  121. public boolean isAbort() {
  122. return kind == IMessage.ABORT;
  123. }
  124. /** Caller can verify if this message came about because of a DEOW */
  125. public boolean getDeclared() {
  126. return declared;
  127. }
  128. /**
  129. * @return true if kind == IMessage.FAIL
  130. */
  131. public boolean isFailed() {
  132. return kind == IMessage.FAIL;
  133. }
  134. /** @return non-null String with simple message */
  135. final public String getMessage() {
  136. return message;
  137. }
  138. /** @return Throwable associated with this message, or null if none */
  139. final public Throwable getThrown() {
  140. return thrown;
  141. }
  142. /** @return ISourceLocation associated with this message, or null if none */
  143. final public ISourceLocation getSourceLocation() {
  144. return sourceLocation;
  145. }
  146. public String toString() {
  147. return MessageUtil.renderMessage(this, false);
  148. }
  149. public String getDetails() {
  150. return details;
  151. }
  152. public List<ISourceLocation> getExtraSourceLocations() {
  153. return extraSourceLocations;
  154. }
  155. public int getID() {
  156. return id;
  157. }
  158. public int getSourceStart() {
  159. return sourceStart;
  160. }
  161. public int getSourceEnd() {
  162. return sourceEnd;
  163. }
  164. }