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

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