Extend EvaluationFeedback with specific methods for creating details feedback; introduce details parameter.

This commit is contained in:
Fedor Isakov 2019-08-30 13:52:33 +02:00
parent 84d07ef5f4
commit 4080ab519a
4 changed files with 68 additions and 19 deletions

View File

@ -63,6 +63,11 @@ class CompositeFeedback private constructor(private val elements: List<Feedback>
return composeMessages(elements)
}
override fun getDetails(): Any? {
// FIXME compose the details
return null
}
fun elements(): List<Feedback> {
return elements
}

View File

@ -27,19 +27,22 @@ import jetbrains.mps.logic.reactor.evaluation.EvaluationFeedback
open class DetailedFeedback : Feedback {
private val message: String
private val severity: EvaluationFeedback.Severity
private val severity: Severity
private val details: Any?
constructor(message: String) {
this.message = message
this.severity = EvaluationFeedback.Severity.INFO
this.severity = Severity.INFO
this.details = null
}
constructor(message: String, severity: EvaluationFeedback.Severity) {
constructor(message: String, severity: Severity, details: Any? = null) {
this.message = message
this.severity = severity
this.details = details
}
override fun getSeverity(): EvaluationFeedback.Severity {
override fun getSeverity(): Severity {
return severity
}
@ -47,6 +50,10 @@ open class DetailedFeedback : Feedback {
return message
}
override fun getDetails(): Any? {
return details
}
override fun toString(): String {
return getSeverity().toString() + " " + message
}

View File

@ -76,8 +76,12 @@ class EvaluationFailure : Feedback {
return message
}
override fun getDetails(): Any? {
return null
}
override fun getSeverity(): EvaluationFeedback.Severity {
return EvaluationFeedback.Severity.ERROR
return EvaluationFeedback.Severity.FAILURE
}
override fun failureCause(): Throwable? {

View File

@ -17,7 +17,6 @@
package jetbrains.mps.logic.reactor.evaluation;
import jetbrains.mps.logic.reactor.core.DetailedFeedback;
import jetbrains.mps.logic.reactor.program.Rule;
/**
* Abstract feedback to be provided by the code being evaluated.
@ -26,36 +25,72 @@ import jetbrains.mps.logic.reactor.program.Rule;
*/
abstract public class EvaluationFeedback {
@Deprecated
public static EvaluationFeedback details(String message) {
return new DetailedFeedback(message, Severity.INFO);
return new DetailedFeedback(message, Severity.INFO, null);
}
@Deprecated
public static EvaluationFeedback details(String message, Severity severity) {
return new DetailedFeedback(message, severity);
return new DetailedFeedback(message, severity, null);
}
public static EvaluationFeedback debug(String message, Object details) {
return new DetailedFeedback(message, Severity.DEBUG, details);
}
public static EvaluationFeedback debug(String message) {
return new DetailedFeedback(message, Severity.DEBUG, null);
}
public static EvaluationFeedback info(String message, Object details) {
return new DetailedFeedback(message, Severity.INFO, details);
}
public static EvaluationFeedback info(String message) {
return new DetailedFeedback(message, Severity.INFO, null);
}
public static EvaluationFeedback warn(String message, Object details) {
return new DetailedFeedback(message, Severity.WARN, details);
}
public static EvaluationFeedback warn(String message) {
return new DetailedFeedback(message, Severity.WARN, null);
}
public static EvaluationFeedback error(String message, Object details) {
return new DetailedFeedback(message, Severity.ERROR, details);
}
public static EvaluationFeedback error(String message) {
return new DetailedFeedback(message, Severity.ERROR, null);
}
abstract public Severity getSeverity();
abstract public String getMessage();
abstract public Object getDetails();
public boolean isFailure() {
return Severity.ERROR.compareTo(getSeverity()) <= 0;
return Severity.FAILURE.compareTo(getSeverity()) <= 0;
}
public Throwable failureCause() { throw new UnsupportedOperationException(); }
public static enum Severity {
public enum Severity {
DEBUG(0, "[debug]"),
INFO(1, "[info]"),
WARN(2, "[warning]"),
ERROR(3, "[error]"),
FATAL(4, "[fatal]")
DEBUG("[debug]"),
INFO("[info]"),
WARN("[warning]"),
ERROR("[error]"),
FAILURE("[failure]"),
FATAL("[fatal]")
;
private Severity(int level, String title) {
this.level = level;
Severity(String title) {
this.title = title;
}
@ -64,8 +99,6 @@ abstract public class EvaluationFeedback {
return title;
}
private final int level;
private final String title;
}
}