
com.atlassian.clover.instr.aspectj.text.LinesToTextRange Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of clover-aspectj-compiler Show documentation
Show all versions of clover-aspectj-compiler Show documentation
A wrapper for AspectJ compiler which allows code instrumentation using OpenClover.
The newest version!
package com.atlassian.clover.instr.aspectj.text;
import com.atlassian.clover.instr.aspectj.text.TextRange;
import java.util.ArrayList;
public class LinesToTextRange {
private final ArrayList linesEndIndex;
public LinesToTextRange(String input) {
linesEndIndex = new ArrayList();
String[] lines = input.split("[\n\r]");
int endIndex = 0;
for (int i = 0; i < lines.length; i++) {
endIndex += lines[i].length() + (i < lines.length - 1 ? 1 : 0);
linesEndIndex.add(endIndex);
}
}
/**
* @param lineNumber counted from 0
* @return TextRange
*/
public TextRange getTextRangeForLine(int lineNumber) {
if (lineNumber >= 0 && lineNumber < linesEndIndex.size()) {
int min = lineNumber == 0 ? 0 : linesEndIndex.get(lineNumber - 1) + 1;
int max = linesEndIndex.get(lineNumber);
return new TextRange(min, max);
} else {
return new TextRange(0, 0);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy