diff options
author | jhugunin <jhugunin> | 2004-01-07 17:00:52 +0000 |
---|---|---|
committer | jhugunin <jhugunin> | 2004-01-07 17:00:52 +0000 |
commit | 97ab1e91dfba52187c14f0f7e5fdf6fafd9966c4 (patch) | |
tree | 1758e455c1531ab3a1507ec22ff33cb64ac3286c /bridge | |
parent | cda2dd4f82306debf0a2c04eb98586fac50cd696 (diff) | |
download | aspectj-97ab1e91dfba52187c14f0f7e5fdf6fafd9966c4.tar.gz aspectj-97ab1e91dfba52187c14f0f7e5fdf6fafd9966c4.zip |
fix for Bugzilla Bug 41952
XLint warning for call PCD's using subtype of defining type
also added extraSourceLocations to IMessage+ for
message with multiple source lines
Diffstat (limited to 'bridge')
-rw-r--r-- | bridge/src/org/aspectj/bridge/IMessage.java | 2 | ||||
-rw-r--r-- | bridge/src/org/aspectj/bridge/Message.java | 71 | ||||
-rw-r--r-- | bridge/src/org/aspectj/bridge/MessageUtil.java | 55 | ||||
-rw-r--r-- | bridge/src/org/aspectj/bridge/SourceLocation.java | 2 |
4 files changed, 78 insertions, 52 deletions
diff --git a/bridge/src/org/aspectj/bridge/IMessage.java b/bridge/src/org/aspectj/bridge/IMessage.java index 7fddcb089..1848e0e31 100644 --- a/bridge/src/org/aspectj/bridge/IMessage.java +++ b/bridge/src/org/aspectj/bridge/IMessage.java @@ -124,4 +124,6 @@ public interface IMessage { * join point's static part. */ public String getDetails(); + + public List getExtraSourceLocations(); } diff --git a/bridge/src/org/aspectj/bridge/Message.java b/bridge/src/org/aspectj/bridge/Message.java index 408a2d4f3..975d0c70d 100644 --- a/bridge/src/org/aspectj/bridge/Message.java +++ b/bridge/src/org/aspectj/bridge/Message.java @@ -18,6 +18,10 @@ import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; /** @@ -30,6 +34,7 @@ public class Message implements IMessage { // XXX toString or renderer? private final Throwable thrown; private final ISourceLocation sourceLocation; private final String details; + private final List/*SourceLocation*/ extraSourceLocations; /** convenience for constructing failure messages */ public static Message fail(String message, Throwable thrown) { @@ -60,20 +65,19 @@ public class Message implements IMessage { // XXX toString or renderer? * and thrown is null. */ public Message(String message, String details, IMessage.Kind kind, - ISourceLocation sourceLocation) { + ISourceLocation sourceLocation, Throwable thrown, ISourceLocation[] extraSourceLocations) { this.details = details; - this.message = message; + this.message = (message==null) ? thrown.getMessage() : message; this.kind = kind; this.sourceLocation = sourceLocation; - this.thrown = null; - if (null == message) { - if (null != thrown) { - message = thrown.getMessage(); - } - if (null == message) { - throw new IllegalArgumentException("null message"); - } + this.thrown = thrown; + + if (extraSourceLocations != null) { + this.extraSourceLocations = Arrays.asList(extraSourceLocations); } + else { + this.extraSourceLocations = Collections.EMPTY_LIST; + } if (null == kind) { throw new IllegalArgumentException("null kind"); } @@ -92,22 +96,23 @@ public class Message implements IMessage { // XXX toString or renderer? */ public Message(String message, IMessage.Kind kind, Throwable thrown, ISourceLocation sourceLocation) { - this.message = message; - this.kind = kind; - this.thrown = thrown; - this.sourceLocation = sourceLocation; - this.details = ""; - if (null == message) { - if (null != thrown) { - message = thrown.getMessage(); - } - if (null == message) { - throw new IllegalArgumentException("null message"); - } - } - if (null == kind) { - throw new IllegalArgumentException("null kind"); - } + this(message, "", kind, sourceLocation, thrown, null ); +// this.message = message; +// this.kind = kind; +// this.thrown = thrown; +// this.sourceLocation = sourceLocation; +// this.details = ""; +// if (null == message) { +// if (null != thrown) { +// message = thrown.getMessage(); +// } +// if (null == message) { +// throw new IllegalArgumentException("null message"); +// } +// } +// if (null == kind) { +// throw new IllegalArgumentException("null kind"); +// } } /** @return the kind of this message */ @@ -165,16 +170,9 @@ public class Message implements IMessage { // XXX toString or renderer? } public String toString() { - return Message.renderToString(this); + return MessageUtil.renderMessage(this,false); } - public static String renderToString(IMessage message) { - ISourceLocation loc = message.getSourceLocation(); - String locString = (null == loc ? "" : " at " + loc); - Throwable thrown = message.getThrown(); - return message.getKind() + locString + ": " + message.getMessage() - + (null == thrown ? "" : render(thrown)); - } public static String render(Throwable thrown) { // XXX cf LangUtil.debugStr if (null == thrown) return "null throwable"; @@ -200,4 +198,9 @@ public class Message implements IMessage { // XXX toString or renderer? public String getDetails() { return details; } + + public List getExtraSourceLocations() { + return extraSourceLocations; + } + } diff --git a/bridge/src/org/aspectj/bridge/MessageUtil.java b/bridge/src/org/aspectj/bridge/MessageUtil.java index 9dbb09e44..7a3fea2d0 100644 --- a/bridge/src/org/aspectj/bridge/MessageUtil.java +++ b/bridge/src/org/aspectj/bridge/MessageUtil.java @@ -759,28 +759,49 @@ public class MessageUtil { if (null == message) { return "((IMessage) null)"; } - StringBuffer result = new StringBuffer(); - - result.append(message.getKind().toString()); - result.append(" "); + + ISourceLocation loc = message.getSourceLocation(); + String locString = (null == loc ? "" : " at " + loc); - String messageString = message.getMessage(); - if (!LangUtil.isEmpty(messageString)) { - result.append(messageString); - result.append(" "); + String result = message.getKind() + locString + " " + message.getMessage(); + + Throwable thrown = message.getThrown(); + if (thrown != null) { + result += " -- " + LangUtil.renderExceptionShort(thrown); + result += "\n" + LangUtil.renderException(thrown, elide); } - - ISourceLocation loc = message.getSourceLocation(); - if ((null != loc) && (loc != ISourceLocation.EMPTY)) { - result.append("at " + renderSourceLocation(loc)); + + if (message.getExtraSourceLocations().isEmpty()) { + return result; } - Throwable thrown = message.getThrown(); - if (null != thrown) { - result.append(" -- " + LangUtil.renderExceptionShort(thrown)); - result.append("\n" + LangUtil.renderException(thrown, elide)); + else { + return addExtraSourceLocations(message, result); } - return result.toString(); } + + public static String addExtraSourceLocations( + IMessage message, + String baseMessage) + { + StringWriter buf = new StringWriter(); + PrintWriter writer = new PrintWriter(buf); + writer.println(baseMessage); + for (Iterator iter = message.getExtraSourceLocations().iterator(); iter.hasNext();) { + ISourceLocation element = (ISourceLocation) iter.next(); + writer.print("\tsee also: " + element.toString()); + if (iter.hasNext()) { + writer.println(); + } + } + try { buf.close(); } + catch (IOException ioe) {} + return buf.getBuffer().toString(); + } + + + + + /** * Render ISourceLocation to String, ignoring empty elements diff --git a/bridge/src/org/aspectj/bridge/SourceLocation.java b/bridge/src/org/aspectj/bridge/SourceLocation.java index 882d8af1b..c44d0b942 100644 --- a/bridge/src/org/aspectj/bridge/SourceLocation.java +++ b/bridge/src/org/aspectj/bridge/SourceLocation.java @@ -135,7 +135,7 @@ public class SourceLocation implements ISourceLocation, java.io.Serializable { sb.append(sourceFile.getPath()); sb.append(":"); } - sb.append("" + startLine + "-" + endLine); + sb.append(startLine); //"" + startLine + "-" + endLine); if (!noColumn) { sb.append(":" + column); } |