From 684c9c1c3dd084b43645f537774bea0b4a9c1222 Mon Sep 17 00:00:00 2001 From: mkersten Date: Thu, 7 Aug 2003 10:51:36 +0000 Subject: [PATCH] 40534: Declare warning/error output - more detail required. - Added getDetails() to messages. This String corresponding to thisJoinPointStatic part can be used by tools that need to display additional info. --- bridge/src/org/aspectj/bridge/IMessage.java | 7 ++++ bridge/src/org/aspectj/bridge/Message.java | 37 +++++++++++++++++++ .../org/aspectj/testing/xml/SoftMessage.java | 10 ++++- weaver/src/org/aspectj/weaver/Checker.java | 24 ++++++------ 4 files changed, 66 insertions(+), 12 deletions(-) diff --git a/bridge/src/org/aspectj/bridge/IMessage.java b/bridge/src/org/aspectj/bridge/IMessage.java index fe2a2124d..7fddcb089 100644 --- a/bridge/src/org/aspectj/bridge/IMessage.java +++ b/bridge/src/org/aspectj/bridge/IMessage.java @@ -117,4 +117,11 @@ public interface IMessage { return name; } } + + /** + * @return Detailed information about the message. For example, for declare + * error/warning messages this returns information about the corresponding + * join point's static part. + */ + public String getDetails(); } diff --git a/bridge/src/org/aspectj/bridge/Message.java b/bridge/src/org/aspectj/bridge/Message.java index ada78629a..408a2d4f3 100644 --- a/bridge/src/org/aspectj/bridge/Message.java +++ b/bridge/src/org/aspectj/bridge/Message.java @@ -29,6 +29,7 @@ public class Message implements IMessage { // XXX toString or renderer? private final IMessage.Kind kind; private final Throwable thrown; private final ISourceLocation sourceLocation; + private final String details; /** convenience for constructing failure messages */ public static Message fail(String message, Throwable thrown) { @@ -45,6 +46,38 @@ public class Message implements IMessage { // XXX toString or renderer? this(message, (isError ? IMessage.ERROR : IMessage.WARNING), null, location); } + + /** + * Create a message, handling null values for message and kind + * if thrown is not null. + * @param message the String used as the underlying message + * @param kind the IMessage.Kind of message - not null + * @param thrown the Throwable, if any, associated with this message + * @param sourceLocation the ISourceLocation, if any, associated with this message + * @param details descriptive information about the message + * @throws IllegalArgumentException if message is null and + * thrown is null or has a null message, or if kind is null + * and thrown is null. + */ + public Message(String message, String details, IMessage.Kind kind, + ISourceLocation sourceLocation) { + this.details = details; + this.message = 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"); + } + } + if (null == kind) { + throw new IllegalArgumentException("null kind"); + } + } /** * Create a message, handling null values for message and kind @@ -63,6 +96,7 @@ public class Message implements IMessage { // XXX toString or renderer? this.kind = kind; this.thrown = thrown; this.sourceLocation = sourceLocation; + this.details = ""; if (null == message) { if (null != thrown) { message = thrown.getMessage(); @@ -163,4 +197,7 @@ public class Message implements IMessage { // XXX toString or renderer? return buf.getBuffer().toString(); } + public String getDetails() { + return details; + } } diff --git a/testing/src/org/aspectj/testing/xml/SoftMessage.java b/testing/src/org/aspectj/testing/xml/SoftMessage.java index c5eb95489..e798f8f05 100644 --- a/testing/src/org/aspectj/testing/xml/SoftMessage.java +++ b/testing/src/org/aspectj/testing/xml/SoftMessage.java @@ -37,7 +37,7 @@ public class SoftMessage implements IMessage { // XXX mutable dup of Message private IMessage.Kind kind; private Throwable thrown; private ISourceLocation sourceLocation; - + private String details; //private ISourceLocation pseudoSourceLocation; // set directly // collapse enclosed source location for shorter, property-based xml @@ -279,4 +279,12 @@ public class SoftMessage implements IMessage { // XXX mutable dup of Message } return result.toString(); } + + public String getDetails() { + return details; + } + + public void setDetails(String string) { + details = string; + } } diff --git a/weaver/src/org/aspectj/weaver/Checker.java b/weaver/src/org/aspectj/weaver/Checker.java index 69285c37f..4e4517077 100644 --- a/weaver/src/org/aspectj/weaver/Checker.java +++ b/weaver/src/org/aspectj/weaver/Checker.java @@ -13,13 +13,13 @@ package org.aspectj.weaver; -import java.util.Collection; -import java.util.Collections; +import java.util.*; -import org.aspectj.bridge.IMessage; -import org.aspectj.bridge.Message; -import org.aspectj.weaver.patterns.DeclareErrorOrWarning; -import org.aspectj.weaver.patterns.PerClause; +import org.aspectj.bridge.*; +import org.aspectj.lang.Signature; +import org.aspectj.lang.JoinPoint.StaticPart; +import org.aspectj.lang.reflect.SourceLocation; +import org.aspectj.weaver.patterns.*; public class Checker extends ShadowMunger { @@ -48,11 +48,13 @@ public class Checker extends ShadowMunger { public boolean match(Shadow shadow, World world) { if (super.match(shadow, world)) { - world.getMessageHandler().handleMessage( - new Message(msg, - isError ? IMessage.ERROR : IMessage.WARNING, - null, - shadow.getSourceLocation())); + IMessage message = new Message( + msg, + shadow.toString(), + isError ? IMessage.ERROR : IMessage.WARNING, + shadow.getSourceLocation()); + world.getMessageHandler().handleMessage(message); + } return false; } -- 2.39.5