Skip to content

Commit bf9b61a

Browse files
committed
feat(model): Introduce a TextLocation.hasLineRange property
Note that although strictly speaking `!hasLineRange` equals startLine == UNKNOWN_LINE || endLine == UNKNOWN_LINE instead of startLine == UNKNOWN_LINE && endLine == UNKNOWN_LINE the `TextLocation` constructors ensures that not only either `startLine` or `endLine` can be `UNKNOWN_LINE`, but always both of them. Also, `isFullFileLocation()` was not completely removed (yet) to not break existing templates. Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent 2b7bfe9 commit bf9b61a

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

model/src/main/kotlin/TextLocation.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package org.ossreviewtoolkit.model
2121

22+
import com.fasterxml.jackson.annotation.JsonIgnore
23+
2224
import java.io.File
2325

2426
import kotlin.math.abs
@@ -65,6 +67,12 @@ data class TextLocation(
6567
*/
6668
constructor(path: String, line: Int) : this(path, line, line)
6769

70+
/**
71+
* Indicate whether this TextLocation has known start and end lines.
72+
*/
73+
@JsonIgnore
74+
val hasLineRange = startLine != UNKNOWN_LINE && endLine != UNKNOWN_LINE
75+
6876
/**
6977
* Return a negative integer, zero, or a positive integer as this TextLocation comes before, is the same, or comes
7078
* after the [other] TextLocation.

plugins/reporters/freemarker/src/main/kotlin/FreemarkerTemplateProcessor.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,7 @@ class FreemarkerTemplateProcessor(
343343
* Return a flag if the given [sourceLocation] refers to the full source file.
344344
*/
345345
@Suppress("unused") // This function is used in the templates.
346-
fun isFullFileLocation(sourceLocation: TextLocation) =
347-
sourceLocation.startLine == TextLocation.UNKNOWN_LINE && sourceLocation.endLine == TextLocation.UNKNOWN_LINE
346+
fun isFullFileLocation(sourceLocation: TextLocation) = !sourceLocation.hasLineRange
348347

349348
/**
350349
* Collect all the licenses present in a collection of [SnippetFinding]s.

plugins/scanners/fossid/src/main/kotlin/FossIdScanResults.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@ private fun urlToPackageType(url: String): PurlType =
455455
}
456456

457457
internal fun TextLocation.prettyPrint(): String =
458-
if (startLine == TextLocation.UNKNOWN_LINE && endLine == TextLocation.UNKNOWN_LINE) {
459-
"$path#FULL"
460-
} else {
458+
if (hasLineRange) {
461459
"$path#$startLine-$endLine"
460+
} else {
461+
"$path#FULL"
462462
}

0 commit comments

Comments
 (0)