io.codemodder.remediation.WithoutScopePositionMatcher 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;
import com.github.javaparser.ast.nodeTypes.NodeWithTraversableScope;
/** Removes the range of the node's scope before matching it against a position. */
public final class WithoutScopePositionMatcher extends DefaultNodePositionMatcher {
@Override
protected Range getRange(final Node node) {
var originalRange = node.getRange().orElseThrow();
if (node.hasScope()) {
var scope = ((NodeWithTraversableScope) node).traverseScope().get();
var scopeRange = scope.getRange().orElseThrow();
return new Range(
new Position(scopeRange.end.line, scopeRange.end.column + 1), originalRange.end);
}
return originalRange;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy