1package com.github.javaparser.ast.validator;
2
3import com.github.javaparser.ParseResult;
4import com.github.javaparser.ast.Node;
5
6import java.util.function.BiConsumer;
7
8/**
9 * A validator that validates a known node type.
10 */
11public interface TypedValidator<N extends Node> extends BiConsumer<N, ProblemReporter> {
12    /**
13     * @param node the node that wants to be validated
14     * @param problemReporter when found, validation errors can be reported here
15     */
16    void accept(N node, ProblemReporter problemReporter);
17
18    @SuppressWarnings("unchecked")
19    default ParseResult.PostProcessor postProcessor() {
20        return (result, configuration) ->
21                result.getResult().ifPresent(node ->
22                        accept((N) node, new ProblemReporter(problem -> result.getProblems().add(problem))));
23    }
24}
25