From 60b3a70a85f5b0c1dd504fbe4410d52664f63eed Mon Sep 17 00:00:00 2001 From: wisberg Date: Wed, 31 Mar 2004 00:39:21 +0000 Subject: [PATCH] recursive message checks of run status with children --- .../org/aspectj/testing/run/IRunStatus.java | 20 ++++++++++ .../org/aspectj/testing/run/RunStatus.java | 38 +++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/testing/src/org/aspectj/testing/run/IRunStatus.java b/testing/src/org/aspectj/testing/run/IRunStatus.java index 6651c42f1..1757fedbc 100644 --- a/testing/src/org/aspectj/testing/run/IRunStatus.java +++ b/testing/src/org/aspectj/testing/run/IRunStatus.java @@ -105,6 +105,26 @@ public interface IRunStatus extends IMessageHolder { */ void completeAbruptly(); //------------------- process messages + /** + * Detect whether a message of a given kind has been handled. + * @param kind the IMessage.Kind of the message to detect + * @param orGreater if true, then also accept any message of a greater kind + * @param includeChildren if true, then also search in any child IRunStatus + * @return true if any such message is detected + */ + boolean hasAnyMessage(IMessage.Kind kind, boolean orGreater, boolean includeChildren); + + /** + * Get all messages or those of a specific kind, optionally in children as well + * Pass null to get all kinds. + * @param kind the IMessage.Kind expected, or null for all messages + * @param orGreater if true, also get any greater than the target kind + * as determined by IMessage.Kind.COMPARATOR + * @param includeChildren if true, then also search in any child IRunStatus + * @return IMessage[] of messages of the right kind, or IMessage.NONE + */ + IMessage[] getMessages(IMessage.Kind kind, boolean orGreater, boolean includeChildren); + /** * Call this any time to signal any messages. * (In particular, the IRun caller may use this to register messages diff --git a/testing/src/org/aspectj/testing/run/RunStatus.java b/testing/src/org/aspectj/testing/run/RunStatus.java index be971f6b9..1f2af56ab 100644 --- a/testing/src/org/aspectj/testing/run/RunStatus.java +++ b/testing/src/org/aspectj/testing/run/RunStatus.java @@ -15,13 +15,16 @@ package org.aspectj.testing.run; import java.util.ArrayList; +import java.util.Arrays; import java.util.Iterator; import java.util.List; import org.aspectj.bridge.IMessage; import org.aspectj.bridge.IMessageHolder; import org.aspectj.bridge.MessageHandler; +import org.aspectj.bridge.IMessage.Kind; import org.aspectj.testing.util.BridgeUtil; +import org.aspectj.util.LangUtil; /** * Default implementation of {@link IRunStatus}. @@ -227,6 +230,41 @@ public class RunStatus implements IRunStatus { public boolean runResult() { return validator.runPassed(this); } + + public boolean hasAnyMessage(IMessage.Kind kind, boolean orGreater, boolean includeChildren) { + if (messageHolder.hasAnyMessage(kind, orGreater)) { + return true; + } + if (includeChildren) { + IRunStatus[] kids = getChildren(); + for (int i = 0; i < kids.length; i++) { + if (kids[i].hasAnyMessage(kind, orGreater, true)) { + return true; + } + } + } + return false; + } + + public IMessage[] getMessages(IMessage.Kind kind, boolean orGreater, boolean includeChildren) { + IMessage[] result = getMessages(kind, orGreater); + if (!includeChildren) { + return result; + } + ArrayList sink = new ArrayList(); + if (!LangUtil.isEmpty(result)) { + sink.addAll(Arrays.asList(result)); + } + + IRunStatus[] kids = getChildren(); + for (int i = 0; i < kids.length; i++) { + result = kids[i].getMessages(kind, orGreater, includeChildren); + if (!LangUtil.isEmpty(result)) { + sink.addAll(Arrays.asList(result)); + } + } + return (IMessage[]) sink.toArray(new IMessage[0]); + } //------------------- process messages /** -- 2.39.5