@Test void noViableAltExceptionTest() { Parser recognizer = mock(Parser.class); TokenStream stream = mock(TokenStream.class); Token token = mock(Token.class); NoViableAltException error = new NoViableAltException(recognizer, stream, token, token, null, null); CobolErrorStrategy strategy = new CobolErrorStrategy(); when(recognizer.getInputStream()).thenReturn(stream); when(stream.getText(token, token)).thenReturn("text"); when(recognizer.getRuleInvocationStack()).thenReturn(Collections.singletonList("rule")); strategy.reportError(recognizer, error); verify(recognizer).notifyErrorListeners(token, "No viable alternative at input text", error); }
@Override public void reportError(Parser recognizer, RecognitionException e) { if (inErrorRecoveryMode(recognizer)) { return; } beginErrorCondition(recognizer); if (e instanceof NoViableAltException) { reportNoViableAlternative(recognizer, (NoViableAltException) e); } else if (e instanceof InputMismatchException) { reportInputMismatch(recognizer, (InputMismatchException) e); } else if (e instanceof FailedPredicateException) { reportFailedPredicate(recognizer, (FailedPredicateException) e); } else { LOG.error("unknown recognition error type: " + e.getClass().getName()); recognizer.notifyErrorListeners(e.getOffendingToken(), e.getMessage(), e); } }
CobolErrorStrategy extends DefaultErrorStrategy { @Override public void reportError(Parser recognizer, RecognitionException e) { if (inErrorRecoveryMode(recognizer)) { return; } beginErrorCondition(recognizer); if (e instanceof NoViableAltException) { reportNoViableAlternative(recognizer, (NoViableAltException) e); } else if (e instanceof InputMismatchException) { reportInputMismatch(recognizer, (InputMismatchException) e); } else if (e instanceof FailedPredicateException) { reportFailedPredicate(recognizer, (FailedPredicateException) e); } else { LOG.error("unknown recognition error type: " + e.getClass().getName()); recognizer.notifyErrorListeners(e.getOffendingToken(), e.getMessage(), e); } } }
CobolErrorStrategy extends DefaultErrorStrategy { @Override public void reportError(Parser recognizer, RecognitionException e) { if (inErrorRecoveryMode(recognizer)) { return; } beginErrorCondition(recognizer); if (e instanceof NoViableAltException) { reportNoViableAlternative(recognizer, (NoViableAltException) e); } else if (e instanceof InputMismatchException) { reportInputMismatch(recognizer, (InputMismatchException) e); } else if (e instanceof FailedPredicateException) { reportFailedPredicate(recognizer, (FailedPredicateException) e); } else { LOG.error("unknown recognition error type: " + e.getClass().getName()); recognizer.notifyErrorListeners(e.getOffendingToken(), e.getMessage(), e); } }  }
CobolErrorStrategy extends DefaultErrorStrategy { @Override public void reportError(Parser recognizer, RecognitionException e) { if (inErrorRecoveryMode(recognizer)) { return; } beginErrorCondition(recognizer); if (e instanceof NoViableAltException) { reportNoViableAlternative(recognizer, (NoViableAltException) e); } else if (e instanceof InputMismatchException) { reportInputMismatch(recognizer, (InputMismatchException) e); } else if (e instanceof FailedPredicateException) { reportFailedPredicate(recognizer, (FailedPredicateException) e); } else { LOG.error("unknown recognition error type: " + e.getClass().getName()); recognizer.notifyErrorListeners(e.getOffendingToken(), e.getMessage(), e); } }  @Override void reportError(Parser recognizer, RecognitionException e); }
CobolErrorStrategy extends DefaultErrorStrategy { @Override public void reportError(Parser recognizer, RecognitionException e) { if (inErrorRecoveryMode(recognizer)) { return; } beginErrorCondition(recognizer); if (e instanceof NoViableAltException) { reportNoViableAlternative(recognizer, (NoViableAltException) e); } else if (e instanceof InputMismatchException) { reportInputMismatch(recognizer, (InputMismatchException) e); } else if (e instanceof FailedPredicateException) { reportFailedPredicate(recognizer, (FailedPredicateException) e); } else { LOG.error("unknown recognition error type: " + e.getClass().getName()); recognizer.notifyErrorListeners(e.getOffendingToken(), e.getMessage(), e); } }  @Override void reportError(Parser recognizer, RecognitionException e);  }