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

Skip to content

Commit 1990b68

Browse files
committed
Kotlin: Return more precise types from PopulateFile.java
1 parent 83ac77d commit 1990b68

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

java/kotlin-extractor/src/main/java/com/semmle/extractor/java/PopulateFile.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.Map;
66

77
import com.github.codeql.Label;
8+
import com.github.codeql.DbFile;
89
import com.github.codeql.TrapWriter;
910
import com.github.codeql.KotlinExtractorDbSchemeKt;
1011
import com.semmle.util.exception.CatastrophicError;
@@ -75,7 +76,7 @@ public Label populateFile(File absoluteFile) {
7576
return getFileLabel(absoluteFile, true);
7677
}
7778

78-
public Label getFileLabel(File absoluteFile, boolean populateTables) {
79+
public Label<DbFile> getFileLabel(File absoluteFile, boolean populateTables) {
7980
String databasePath = transformer.fileAsDatabaseString(absoluteFile);
8081
Label result = tw.getLabelFor("@\"" + escapeKey(databasePath) + ";sourcefile" + "\"");
8182
// Ensure the rewritten path is used from now on.
@@ -113,7 +114,7 @@ public Label relativeFileId(File jarFile, String pathWithinJar) {
113114
return getFileInJarLabel(jarFile, pathWithinJar, true);
114115
}
115116

116-
public Label getFileInJarLabel(File jarFile, String pathWithinJar, boolean populateTables) {
117+
public Label<DbFile> getFileInJarLabel(File jarFile, String pathWithinJar, boolean populateTables) {
117118
if (pathWithinJar.contains("\\"))
118119
throw new CatastrophicError("Invalid jar path: '" + pathWithinJar + "' should not contain '\\'.");
119120

@@ -148,4 +149,4 @@ public Label getFileInJarLabel(File jarFile, String pathWithinJar, boolean popul
148149
return current;
149150
}
150151

151-
}
152+
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,11 @@ open class FileTrapWriter (
163163
): TrapWriter (lm, bw) {
164164
val populateFile = PopulateFile(this)
165165
val splitFilePath = filePath.split("!/")
166-
@Suppress("UNCHECKED_CAST")
167166
val fileId =
168-
(if(splitFilePath.size == 1)
167+
if(splitFilePath.size == 1)
169168
populateFile.getFileLabel(File(filePath), populateFileTables)
170169
else
171170
populateFile.getFileInJarLabel(File(splitFilePath.get(0)), splitFilePath.get(1), populateFileTables)
172-
) as Label<DbFile>
173171

174172
fun getLocation(e: IrElement): Label<DbLocation> {
175173
return getLocation(e.startOffset, e.endOffset)

0 commit comments

Comments
 (0)