All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.codemodder.remediation.DefaultNodePositionMatcher Maven / Gradle / Ivy

There is a newer version: 0.98.6
Show newest version
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