/** * Notify checks that visiting a node. * @param ast the node to notify for. * @param astState state of AST. */ private void notifyVisit(DetailAST ast, AstState astState) { final Collection<AbstractCheck> visitors = getListOfChecks(ast, astState); if (visitors != null) { for (AbstractCheck check : visitors) { check.visitToken(ast); } } }
@Test public void testVisitToken() { final AbstractCheck check = new AbstractCheck() { @Override public int[] getDefaultTokens() { return CommonUtil.EMPTY_INT_ARRAY; } @Override public int[] getAcceptableTokens() { return CommonUtil.EMPTY_INT_ARRAY; } @Override public int[] getRequiredTokens() { return CommonUtil.EMPTY_INT_ARRAY; } }; final AbstractCheck checkSpy = spy(check); // Eventually it will become clear abstract method checkSpy.visitToken(null); verify(checkSpy, times(1)).visitToken(null); }
/** * Checks if stateful field is cleared during {@link AbstractCheck#beginTree} in check. * * @param check check object which field is to be verified * @param astToVisit ast to pass into check methods * @param fieldName name of the field to be checked * @param isClear function for checking field state * @return {@code true} if state of the field is cleared * @throws NoSuchFieldException if there is no field with the * {@code fieldName} in the {@code check} * @throws IllegalAccessException if the field is inaccessible */ public static boolean isStatefulFieldClearedDuringBeginTree(AbstractCheck check, DetailAST astToVisit, String fieldName, Predicate<Object> isClear) throws NoSuchFieldException, IllegalAccessException { check.beginTree(astToVisit); check.visitToken(astToVisit); check.beginTree(null); final Field resultField = getClassDeclaredField(check.getClass(), fieldName); return isClear.test(resultField.get(check)); }
@Override public void visitToken(DetailAST ast) { this.check.visitToken(ast); }
/** * Notify checks that visiting a node. * @param ast the node to notify for. * @param astState state of AST. */ private void notifyVisit(DetailAST ast, AstState astState) { final Collection<AbstractCheck> visitors = getListOfChecks(ast, astState); if (visitors != null) { for (AbstractCheck check : visitors) { check.visitToken(ast); } } }