/** * Notify checks that we are about to begin walking a tree. * @param rootAST the root of the tree. * @param contents the contents of the file the AST was generated from. * @param astState state of AST. */ private void notifyBegin(DetailAST rootAST, FileContents contents, AstState astState) { final Set<AbstractCheck> checks; if (astState == AstState.WITH_COMMENTS) { checks = commentChecks; } else { checks = ordinaryChecks; } for (AbstractCheck check : checks) { check.setFileContents(contents); check.clearMessages(); check.beginTree(rootAST); } }
/** * 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 beginTree(DetailAST rootAST) { super.beginTree(rootAST); stringMap.clear(); }
/** * Notify checks that we are about to begin walking a tree. * @param rootAST the root of the tree. * @param contents the contents of the file the AST was generated from. * @param astState state of AST. */ private void notifyBegin(DetailAST rootAST, FileContents contents, AstState astState) { final Set<AbstractCheck> checks; if (astState == AstState.WITH_COMMENTS) { checks = commentChecks; } else { checks = ordinaryChecks; } for (AbstractCheck check : checks) { check.setFileContents(contents); check.clearMessages(); check.beginTree(rootAST); } }
@Override public void beginTree(DetailAST rootAST) { this.check.setFileContents(getFileContents()); this.check.clearMessages(); this.check.beginTree(rootAST); }