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