List<ANTLRMessage> getMessagesOfType(List<ANTLRMessage> msgs, Class c) { List<ANTLRMessage> filtered = new ArrayList<ANTLRMessage>(); for (ANTLRMessage m : msgs) { if (m.getClass() == c) filtered.add(m); } return filtered; }
protected void checkGrammarSemanticsWarning( ErrorQueue equeue, GrammarSemanticsMessage expectedMessage) throws Exception { ANTLRMessage foundMsg = null; for (int i = 0; i < equeue.warnings.size(); i++) { ANTLRMessage m = equeue.warnings.get(i); if (m.getErrorType() == expectedMessage.getErrorType()) { foundMsg = m; } } assertNotNull("no error; " + expectedMessage.getErrorType() + " expected", foundMsg); assertTrue( "error is not a GrammarSemanticsMessage", foundMsg instanceof GrammarSemanticsMessage); assertEquals(Arrays.toString(expectedMessage.getArgs()), Arrays.toString(foundMsg.getArgs())); if (equeue.size() != 1) { System.err.println(equeue); } }
protected void checkError(ErrorQueue equeue, ANTLRMessage expectedMessage) throws Exception { // System.out.println("errors="+equeue); ANTLRMessage foundMsg = null; for (int i = 0; i < equeue.errors.size(); i++) { ANTLRMessage m = equeue.errors.get(i); if (m.getErrorType() == expectedMessage.getErrorType()) { foundMsg = m; } } assertTrue( "no error; " + expectedMessage.getErrorType() + " expected", !equeue.errors.isEmpty()); assertTrue("too many errors; " + equeue.errors, equeue.errors.size() <= 1); assertNotNull("couldn't find expected error: " + expectedMessage.getErrorType(), foundMsg); /* assertTrue("error is not a GrammarSemanticsMessage", foundMsg instanceof GrammarSemanticsMessage); */ assertArrayEquals(expectedMessage.getArgs(), foundMsg.getArgs()); }