io.codemodder.remediation.DefaultNodePositionMatcher 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.Position;
import com.github.javaparser.Range;
import com.github.javaparser.ast.Node;
class DefaultNodePositionMatcher implements NodePositionMatcher {
@Override
public boolean match(final Node node, final int line) {
return getRange(node).begin.line == line;
}
@Override
public boolean match(final Node node, int startLine, int endLine) {
return inInterval(getRange(node).begin.line, startLine, endLine);
}
@Override
public boolean match(final Node node, int startLine, int endLine, int startColumn) {
return match(node, startLine, endLine)
&& getRange(node).begin.compareTo(new Position(startLine, startColumn)) >= 0;
}
@Override
public boolean match(
final Node node, int startLine, int endLine, int startColumn, int endColumn) {
return getRange(node)
.strictlyContains(
new Range(new Position(startLine, startColumn), new Position(endLine, endColumn)));
}
private boolean inInterval(int number, int upper, int lower) {
return number >= upper && number <= lower;
}
protected Range getRange(final Node node) {
return node.getRange().orElseThrow();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy