Skip to content

Commit 6d85999

Browse files
committed
extend LineReader API
1 parent 82a5781 commit 6d85999

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

src/main/java/org/codetracker/util/Util.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.github.gumtreediff.tree.Tree;
55
import gr.uom.java.xmi.UMLAnnotation;
66
import gr.uom.java.xmi.UMLModel;
7+
import org.codetracker.BlockTrackerGumTreeImpl.CodeElementRange;
78
import org.codetracker.element.Method;
89
import org.eclipse.jgit.api.Git;
910
import org.eclipse.jgit.api.errors.GitAPIException;
@@ -178,10 +179,31 @@ public static LineReader getLineReader(String fileContent) throws IOException {
178179
}
179180

180181
public static int startLine(Tree tree, LineReader lr){
181-
return lr.positionFor(tree.getPos())[0];
182+
return startLine(tree.getPos(), lr);
183+
}
184+
185+
public static int startLine(int startPosition, LineReader lr){
186+
return lr.positionFor(startPosition)[0];
182187
}
183188

184189
public static int endLine(Tree tree, LineReader lr){
185-
return lr.positionFor(tree.getEndPos())[0];
190+
return endLine(tree.getEndPos(), lr);
191+
}
192+
193+
public static int endLine(int endPosition, LineReader lr){
194+
return lr.positionFor(endPosition)[0];
195+
}
196+
197+
public static boolean actionOverlapsElement(CodeElementRange actionRange, CodeElementRange codeElementRange) {
198+
return actionOverlapsElement(actionRange, codeElementRange, false);
199+
}
200+
201+
public static boolean actionOverlapsElement(CodeElementRange actionRange, CodeElementRange codeElementRange, boolean line) {
202+
if (line){
203+
return actionRange.startLine <= codeElementRange.endLine
204+
&& actionRange.endLine >= codeElementRange.startLine;
205+
}
206+
return actionRange.startPosition <= codeElementRange.endPosition
207+
&& actionRange.endPosition >= codeElementRange.startPosition;
186208
}
187209
}

0 commit comments

Comments
 (0)