io.codemodder.remediation.FixCandidateSearcher Maven / Gradle / Ivy
package io.codemodder.remediation;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.Node;
import io.codemodder.codetf.DetectorRule;
import java.util.*;
import java.util.function.Function;
import java.util.function.Predicate;
/** Searches for potential fix locations in the source code. */
public interface FixCandidateSearcher {
/**
* Searches the AST for nodes associated with the given issues.
*
* @param cu
* @param path
* @param rule
* @param issuesForFile
* @param getKey A function that extracts the key for T.
* @param getStartLine A function that extracts start line information from T. Always required.
* @param getEndLine A function that extracts end line information from T. May not be available
* @param getColumn A function that extracts column information from T. May not be available
* @return
*/
FixCandidateSearchResults search(
CompilationUnit cu,
String path,
DetectorRule rule,
List issuesForFile,
Function getKey,
Function getStartLine,
Function> getEndLine,
Function> getColumn);
/** Builder for {@link FixCandidateSearcher}. */
final class Builder {
private final List> matchers;
public Builder() {
this.matchers = new ArrayList<>();
}
public Builder withMatcher(final Predicate matcher) {
this.matchers.add(Objects.requireNonNull(matcher));
return this;
}
public FixCandidateSearcher build() {
return new DefaultFixCandidateSearcher<>(List.copyOf(matchers));
}
}
}