Search in sources :

Example 1 with Warning

use of io.github.wysohn.triggerreactor.core.script.warning.Warning in project TriggerReactor by wysohn.

the class AbstractTriggerManager method reportWarnings.

protected static void reportWarnings(List<Warning> warnings, Trigger trigger) {
    if (warnings == null || warnings.isEmpty()) {
        return;
    }
    Level L = Level.WARNING;
    Logger log = TriggerReactorCore.getInstance().getLogger();
    int numWarnings = warnings.size();
    String ww;
    if (numWarnings > 1) {
        ww = "warnings were";
    } else {
        ww = "warning was";
    }
    log.log(L, "===== " + warnings.size() + " " + ww + " found while loading trigger " + trigger.getInfo() + " =====");
    for (Warning w : warnings) {
        for (String line : w.getMessageLines()) {
            log.log(L, line);
        }
        log.log(Level.WARNING, "");
    }
    log.log(Level.WARNING, "");
}
Also used : Warning(io.github.wysohn.triggerreactor.core.script.warning.Warning) Level(java.util.logging.Level) Logger(java.util.logging.Logger)

Example 2 with Warning

use of io.github.wysohn.triggerreactor.core.script.warning.Warning in project TriggerReactor by wysohn.

the class Trigger method init.

/**
 * @throws IOException                low level exception from Lexer
 * @throws LexerException             throws if lexical analysis failed
 * @throws ParserException            throws if parsing failed
 * @throws TriggerInitFailedException
 */
public void init() throws TriggerInitFailedException {
    try {
        if (script == null) {
            throw new NullPointerException("init() was invoked, yet 'script' was null. Make sure to override " + "init() method to in order to construct a customized Trigger.");
        }
        Charset charset = StandardCharsets.UTF_8;
        Lexer lexer = new Lexer(script, charset);
        Parser parser = new Parser(lexer);
        root = parser.parse(true);
        List<Warning> warnings = parser.getWarnings();
        AbstractTriggerManager.reportWarnings(warnings, this);
        executorMap = TriggerReactorCore.getInstance().getExecutorManager().getBackedMap();
        placeholderMap = TriggerReactorCore.getInstance().getPlaceholderManager().getBackedMap();
        gvarMap = TriggerReactorCore.getInstance().getVariableManager().getGlobalVariableAdapter();
    } catch (Exception ex) {
        throw new TriggerInitFailedException("Failed to initialize Trigger [" + this.getClass().getSimpleName() + " -- " + info + "]!", ex);
    }
}
Also used : Lexer(io.github.wysohn.triggerreactor.core.script.lexer.Lexer) Warning(io.github.wysohn.triggerreactor.core.script.warning.Warning) Charset(java.nio.charset.Charset) TriggerInitFailedException(io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager.TriggerInitFailedException) ParserException(io.github.wysohn.triggerreactor.core.script.parser.ParserException) TriggerInitFailedException(io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager.TriggerInitFailedException) InterpreterException(io.github.wysohn.triggerreactor.core.script.interpreter.InterpreterException) IOException(java.io.IOException) LexerException(io.github.wysohn.triggerreactor.core.script.lexer.LexerException) Parser(io.github.wysohn.triggerreactor.core.script.parser.Parser)

Example 3 with Warning

use of io.github.wysohn.triggerreactor.core.script.warning.Warning in project TriggerReactor by wysohn.

the class Parser method parse.

public Node parse(boolean showWarnings) throws IOException, LexerException, ParserException {
    this.showWarnings = showWarnings;
    lexer.setWarnings(showWarnings);
    Node root = new Node(new Token(Type.ROOT, "<ROOT>", -1, -1));
    Node statement = null;
    while ((statement = parseStatement()) != null) root.getChildren().add(statement);
    List<Warning> lexWarnings = lexer.getWarnings();
    if (lexWarnings != null) {
        this.warnings.addAll(lexWarnings);
    }
    return root;
}
Also used : Warning(io.github.wysohn.triggerreactor.core.script.warning.Warning) DeprecationWarning(io.github.wysohn.triggerreactor.core.script.warning.DeprecationWarning) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Token(io.github.wysohn.triggerreactor.core.script.Token)

Aggregations

Warning (io.github.wysohn.triggerreactor.core.script.warning.Warning)3 TriggerInitFailedException (io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager.TriggerInitFailedException)1 Token (io.github.wysohn.triggerreactor.core.script.Token)1 InterpreterException (io.github.wysohn.triggerreactor.core.script.interpreter.InterpreterException)1 Lexer (io.github.wysohn.triggerreactor.core.script.lexer.Lexer)1 LexerException (io.github.wysohn.triggerreactor.core.script.lexer.LexerException)1 Parser (io.github.wysohn.triggerreactor.core.script.parser.Parser)1 ParserException (io.github.wysohn.triggerreactor.core.script.parser.ParserException)1 DeprecationWarning (io.github.wysohn.triggerreactor.core.script.warning.DeprecationWarning)1 IOException (java.io.IOException)1 Charset (java.nio.charset.Charset)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1