Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 088e7ad

Browse files
committed
Kotlin: Handle zero-width locations for generated elements
1 parent 76fd386 commit 088e7ad

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

java/kotlin-extractor/src/main/kotlin/TrapWriter.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,19 @@ class FileTrapWriter (
7878
return getLocation(e.startOffset, e.endOffset)
7979
}
8080
fun getLocation(startOffset: Int, endOffset: Int): Label<DbLocation> {
81+
// If the compiler doesn't have a location, then start and end are both -1
8182
val unknownLoc = startOffset == -1 && endOffset == -1
83+
// If this is the location for a compiler-generated element, then it will
84+
// be a zero-width location. QL doesn't support these, so we translate it
85+
// into a one-width location.
86+
val zeroWidthLoc = !unknownLoc && startOffset == endOffset
8287
val startLine = if(unknownLoc) 0 else fileEntry.getLineNumber(startOffset) + 1
8388
val startColumn = if(unknownLoc) 0 else fileEntry.getColumnNumber(startOffset) + 1
8489
val endLine = if(unknownLoc) 0 else fileEntry.getLineNumber(endOffset) + 1
8590
val endColumn = if(unknownLoc) 0 else fileEntry.getColumnNumber(endOffset)
91+
val endColumn2 = if(zeroWidthLoc) endColumn + 1 else endColumn
8692
val locFileId: Label<DbFile> = if (unknownLoc) unknownFileId else fileId
87-
return getLocation(locFileId, startLine, startColumn, endLine, endColumn)
93+
return getLocation(locFileId, startLine, startColumn, endLine, endColumn2)
8894
}
8995
fun getLocationString(e: IrElement): String {
9096
val path = irFile.path

java/ql/test/kotlin/library-tests/classes/ctorCalls.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ superCall
77
| classes.kt:12:23:12:34 | super(...) |
88
| classes.kt:17:18:17:28 | super(...) |
99
| classes.kt:28:19:28:29 | super(...) |
10-
| classes.kt:35:27:35:26 | super(...) |
10+
| classes.kt:35:27:35:27 | super(...) |

java/ql/test/kotlin/library-tests/variables/variableAccesses.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ varAcc
44
| variables.kt:16:11:16:18 | o |
55
instAcc
66
| variables.kt:21:11:21:15 | this |
7-
| variables.kt:24:9:24:8 | this |
8-
| variables.kt:25:9:25:8 | this |
7+
| variables.kt:24:9:24:9 | this |
8+
| variables.kt:25:9:25:9 | this |
99
| variables.kt:26:9:26:12 | this |
1010
| variables.kt:27:9:27:12 | this |
1111
| variables.kt:28:9:28:12 | this |

0 commit comments

Comments
 (0)