From ea00a7613cb85f47b4d0aa9e726f20cbe1d103ad Mon Sep 17 00:00:00 2001 From: dgelessus <dgelessus@users.noreply.github.com> Date: Thu, 24 Aug 2023 15:02:42 +0200 Subject: [PATCH] Remove last uses of IStatus.getCode The severity now determines whether the user is notified - errors and warnings are displayed and everything else isn't. --- de.prob.core/src/de/prob/cli/CliStarter.java | 5 ++-- .../src/de/prob/core/ProblemHandler.java | 16 ++++++------- .../src/de/prob/core/PrologException.java | 3 +-- de.prob.core/src/de/prob/logging/Logger.java | 18 ++++---------- .../disprover/core/DisproverReasoner.java | 24 +++++++++---------- .../prob/ui/eventb/StartAnimationHandler.java | 2 +- .../de/prob/ui/ticket/ProBLogListener.java | 6 +---- 7 files changed, 30 insertions(+), 44 deletions(-) diff --git a/de.prob.core/src/de/prob/cli/CliStarter.java b/de.prob.core/src/de/prob/cli/CliStarter.java index 73aa32ab..089d9847 100644 --- a/de.prob.core/src/de/prob/cli/CliStarter.java +++ b/de.prob.core/src/de/prob/cli/CliStarter.java @@ -259,14 +259,13 @@ public final class CliStarter { if (line == null) { break; } - // Logger.log(IStatus.INFO, IStatus.OK, prefix + line, - // null); + // Logger.log(IStatus.INFO, prefix + line, null); System.err.println(prefix + line); } } catch (IOException e) { if (!"Stream closed".equals(e.getMessage())) { final String message = "OutputLogger died with error"; - Logger.log(IStatus.INFO, Logger.DEBUG, message, e); + Logger.log(IStatus.INFO, message, e); } } finally { if (in != null) { diff --git a/de.prob.core/src/de/prob/core/ProblemHandler.java b/de.prob.core/src/de/prob/core/ProblemHandler.java index 7a269ea4..30a76a8d 100644 --- a/de.prob.core/src/de/prob/core/ProblemHandler.java +++ b/de.prob.core/src/de/prob/core/ProblemHandler.java @@ -16,8 +16,8 @@ import de.prob.logging.Logger; public class ProblemHandler { /** - * Notifies the User about a fatal problem inside a command by adding a - * {@link Logger#FATALERROR} to the log. This method takes a message + * Notifies the User about a fatal problem inside a command by adding an error + * to the log. This method takes a message * describing the problem.<br> * * <b>Note:</b> Calling this method logs the problem and throws a new @@ -37,8 +37,8 @@ public class ProblemHandler { } /** - * Notifies the User about a fatal problem inside a command by adding a - * {@link Logger#FATALERROR} to the log. This method takes a message + * Notifies the User about a fatal problem inside a command by adding an error + * to the log. This method takes a message * describing the problem.<br> * * <b>Note:</b> Calling this method logs the problem and throws a new @@ -74,8 +74,8 @@ public class ProblemHandler { /** * - * Notifies the User about a fatal problem by adding a - * {@link Logger#FATALERROR} to the log. This method takes a message + * Notifies the User about a fatal problem by adding an error + * to the log. This method takes a message * describing the problem and the causing exception. * * Note: Calling this method logs the problem and throws a CliException that @@ -95,8 +95,8 @@ public class ProblemHandler { /** * - * Notifies the User about a fatal problem by adding a - * {@link Logger#FATALERROR} to the log. This method takes a message + * Notifies the User about a fatal problem by adding an error + * to the log. This method takes a message * describing the problem and the causing exception. * * Note: Calling this method logs the problem and throws a CliException that diff --git a/de.prob.core/src/de/prob/core/PrologException.java b/de.prob.core/src/de/prob/core/PrologException.java index 84ae7bdf..8b99996f 100644 --- a/de.prob.core/src/de/prob/core/PrologException.java +++ b/de.prob.core/src/de/prob/core/PrologException.java @@ -26,8 +26,7 @@ public class PrologException extends ProBException { if (!handled) { handled = true; if (onlyWarnings) { - Logger.log(IStatus.WARNING, Logger.NOTIFY_USER, - this.getMessage(), this); + Logger.log(IStatus.WARNING, this.getMessage(), this); } else { Logger.notifyUser(this.getMessage(), this); } diff --git a/de.prob.core/src/de/prob/logging/Logger.java b/de.prob.core/src/de/prob/logging/Logger.java index e8d1d95b..2893acd1 100644 --- a/de.prob.core/src/de/prob/logging/Logger.java +++ b/de.prob.core/src/de/prob/logging/Logger.java @@ -23,12 +23,6 @@ import de.prob.parser.BindingGenerator; * */ public final class Logger { - - public static final int DEBUG = 0; - public static final int INFO = 1; - public static final int WARNING = 2; - public static final int NOTIFY_USER = 4; - /** * Registers a new {@link ILogListener}. The listener's * {@link ILogListener#logging(IStatus, String)} method is called, if @@ -41,8 +35,8 @@ public final class Logger { } /** - * Notifies the User about a fatal problem by adding a - * {@link Logger#FATALERROR} to the log. This method takes a message + * Notifies the User about a fatal problem by adding an error + * to the log. This method takes a message * describing the problem as well as an exception. * <p> * Note: Use this only if you don't want to throw an exception. If you want @@ -58,7 +52,7 @@ public final class Logger { */ public static void notifyUser(final String message, final Throwable throwable) { - log(IStatus.ERROR, NOTIFY_USER, message, throwable); + log(IStatus.ERROR, message, throwable); } public static void notifyUser(final String message) { @@ -121,10 +115,8 @@ public final class Logger { assertProB(assertion, false); } - public static void log(final int severity, final int code, - final String message, final Throwable exception) { - final IStatus status = new Status(severity, Activator.PLUGIN_ID, code, - message, exception); + public static void log(final int severity, final String message, final Throwable exception) { + final IStatus status = new Status(severity, Activator.PLUGIN_ID, message, exception); log(status); } diff --git a/de.prob.eventb.disprover.core/src/de/prob/eventb/disprover/core/DisproverReasoner.java b/de.prob.eventb.disprover.core/src/de/prob/eventb/disprover/core/DisproverReasoner.java index d4074c2b..0e9309ca 100644 --- a/de.prob.eventb.disprover.core/src/de/prob/eventb/disprover/core/DisproverReasoner.java +++ b/de.prob.eventb.disprover.core/src/de/prob/eventb/disprover/core/DisproverReasoner.java @@ -3,7 +3,17 @@ package de.prob.eventb.disprover.core; import java.util.HashSet; import java.util.Set; -import org.eclipse.core.runtime.Status; +import de.be4.classicalb.core.parser.analysis.prolog.ASTProlog; +import de.be4.classicalb.core.parser.node.AEventBContextParseUnit; +import de.prob.core.Animator; +import de.prob.eventb.disprover.core.internal.DisproverCommand; +import de.prob.eventb.disprover.core.internal.ICounterExample; +import de.prob.eventb.disprover.core.translation.DisproverContextCreator; +import de.prob.eventb.translator.internal.TranslationVisitor; +import de.prob.logging.Logger; +import de.prob.prolog.output.PrologTermStringOutput; + +import org.eclipse.core.runtime.IStatus; import org.eventb.core.IEventBProject; import org.eventb.core.IPOSequent; import org.eventb.core.ast.Predicate; @@ -22,16 +32,6 @@ import org.eventb.core.seqprover.SerializeException; import org.rodinp.core.IRodinProject; import org.rodinp.core.RodinDBException; -import de.be4.classicalb.core.parser.analysis.prolog.ASTProlog; -import de.be4.classicalb.core.parser.node.AEventBContextParseUnit; -import de.prob.core.Animator; -import de.prob.eventb.disprover.core.internal.DisproverCommand; -import de.prob.eventb.disprover.core.internal.ICounterExample; -import de.prob.eventb.disprover.core.translation.DisproverContextCreator; -import de.prob.eventb.translator.internal.TranslationVisitor; -import de.prob.logging.Logger; -import de.prob.prolog.output.PrologTermStringOutput; - public class DisproverReasoner implements IReasoner { static final String DISPROVER_CONTEXT = "disprover_context"; @@ -62,7 +62,7 @@ public class DisproverReasoner implements IReasoner { timeoutFactor, pm); return createDisproverResult(ce, sequent, input); } catch (RodinDBException e) { - Logger.log(Logger.WARNING, Status.WARNING, e.getMessage(), e); + Logger.log(IStatus.WARNING, e.getMessage(), e); return ProverFactory.reasonerFailure(this, input, e.getMessage()); } catch (InterruptedException e) { return ProverFactory.reasonerFailure(this, input, e.getMessage()); diff --git a/de.prob.ui/src/de/prob/ui/eventb/StartAnimationHandler.java b/de.prob.ui/src/de/prob/ui/eventb/StartAnimationHandler.java index c041a905..88c9ed07 100644 --- a/de.prob.ui/src/de/prob/ui/eventb/StartAnimationHandler.java +++ b/de.prob.ui/src/de/prob/ui/eventb/StartAnimationHandler.java @@ -95,7 +95,7 @@ public class StartAnimationHandler extends AbstractHandler implements IHandler { } else if (realError) Logger.notifyUser(stringBuffer.toString()); else - Logger.log(IStatus.WARNING, Logger.NOTIFY_USER, stringBuffer.toString(), null); + Logger.log(IStatus.WARNING, stringBuffer.toString(), null); } else { Animator.getAnimator().resetRodinProjectHasErrorsOrWarnings(); } diff --git a/de.prob.ui/src/de/prob/ui/ticket/ProBLogListener.java b/de.prob.ui/src/de/prob/ui/ticket/ProBLogListener.java index 8f739f95..c5b2118b 100644 --- a/de.prob.ui/src/de/prob/ui/ticket/ProBLogListener.java +++ b/de.prob.ui/src/de/prob/ui/ticket/ProBLogListener.java @@ -11,8 +11,6 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.swt.widgets.Display; -import de.prob.logging.Logger; - public final class ProBLogListener implements ILogListener { private static final Display display = Display.getDefault(); @@ -25,9 +23,7 @@ public final class ProBLogListener implements ILogListener { return; } - final int code = status.getCode(); - - if (code == Logger.NOTIFY_USER) { + if (status.getSeverity() == IStatus.ERROR || status.getSeverity() == IStatus.WARNING) { display.asyncExec(new Runnable() { public void run() { String title = (status.getSeverity() == IStatus.ERROR) ? "An Error occured" -- GitLab