Example usage for org.antlr.v4.runtime ParserRuleContext addErrorNode

List of usage examples for org.antlr.v4.runtime ParserRuleContext addErrorNode

Introduction

In this page you can find the example usage for org.antlr.v4.runtime ParserRuleContext addErrorNode.

Prototype

@Deprecated
public ErrorNode addErrorNode(Token badToken) 

Source Link

Document

Add a child to this node based upon badToken.

Usage

From source file:illarion.easynpc.parser.Utils.java

License:Open Source License

@Nonnull
private static <T extends Enum<T>> T getEnumValue(@Nullable ParserRuleContext node, @Nonnull Class<T> enumClass,
        @Nonnull T defaultValue) {/*from  ww  w .  j a va2 s  .c om*/
    if (node == null) {
        LOGGER.warn("Expected node for enumerator {} not found.", enumClass.getSimpleName());
        return defaultValue;
    }
    String string = removeQuotes(node.getText());
    try {
        return Enum.valueOf(enumClass, string);
    } catch (IllegalArgumentException e) {
        node.addErrorNode(node.getStart());
        LOGGER.warn("Failed to resolve {} to enumerator {}", string, enumClass.getSimpleName());
        return defaultValue;
    }
}