-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
149 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/edu/kit/kastel/sdq/artemis4j/grading/LineColumn.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* Licensed under EPL-2.0 2025. */ | ||
package edu.kit.kastel.sdq.artemis4j.grading; | ||
|
||
import java.util.Comparator; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* A line-column pair representing the start or end of a {@link Location}. | ||
* | ||
* @param line the 0-indexed line in the source file on which the {@link Location} starts or ends (inclusive) | ||
* @param column the 0-indexed column in the source file on which the {@link Location} starts or ends (inclusive). If empty, the entire line is spanned. | ||
*/ | ||
public record LineColumn(int line, Optional<Integer> column) implements Comparable<LineColumn> { | ||
/** | ||
* Constructs a {@link LineColumn} spanning the entire line. | ||
* | ||
* @param line the line in the source file | ||
* @return a {@link LineColumn} spanning the entire line | ||
*/ | ||
public static LineColumn entireLine(int line) { | ||
return new LineColumn(line, Optional.empty()); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object object) { | ||
if (!(object instanceof LineColumn that)) { | ||
return false; | ||
} | ||
|
||
return this.line() == that.line() && this.column() == that.column(); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(this.line, this.column); | ||
} | ||
|
||
@Override | ||
public int compareTo(@NotNull LineColumn other) { | ||
return Comparator.comparingInt(LineColumn::line) | ||
.thenComparing(LineColumn::column, Comparator.comparingInt(value -> value.orElse(Integer.MAX_VALUE))) | ||
.compare(this, other); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
if (this.column.isEmpty()) { | ||
return "L%d".formatted(this.line + 1); | ||
} | ||
|
||
return "L%d:%d".formatted(this.line + 1, this.column.get() + 1); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/edu/kit/kastel/sdq/artemis4j/grading/Location.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* Licensed under EPL-2.0 2025. */ | ||
package edu.kit.kastel.sdq.artemis4j.grading; | ||
|
||
public record Location(String filePath, LineColumn start, LineColumn end) { | ||
public Location { | ||
if (start.compareTo(end) > 0) { | ||
throw new IllegalArgumentException("start %s must be before end %s".formatted(start, end)); | ||
} | ||
|
||
// In the past there were problems with paths that contained backslashes. This ensures that this will never | ||
// happen again. | ||
filePath = filePath.replace("\\", "/"); | ||
} | ||
|
||
public Location(String filePath, int startLine, int endLine) { | ||
this(filePath, LineColumn.entireLine(startLine), LineColumn.entireLine(endLine)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.