io.codemodder.remediation.FixCandidateSearcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of codemodder-base Show documentation
Show all versions of codemodder-base Show documentation
Base framework for writing codemods in Java
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. Issues are sorted into
* FixCandidates, UnfixedFindings and unmatched.
*
* @param cu
* @param path
* @param rule
* @param issuesForFile A list of issues.
* @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 A FixSearchResults object that sorts the issues into FixCandidates, unfixed and
* unmatched.
*/
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;
private NodePositionMatcher nodePositionMatcher;
public Builder() {
this.matchers = new ArrayList<>();
this.nodePositionMatcher = new DefaultNodePositionMatcher();
}
public Builder withMatcher(final Predicate matcher) {
this.matchers.add(Objects.requireNonNull(matcher));
return this;
}
public Builder withNodePositionMatcher(final NodePositionMatcher nodePositionMatcher) {
this.nodePositionMatcher = nodePositionMatcher;
return this;
}
public FixCandidateSearcher build() {
return new DefaultFixCandidateSearcher<>(List.copyOf(matchers), nodePositionMatcher);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy