mirror of
https://github.com/github/codeql.git
synced 2025-12-20 10:46:30 +01:00
Kotlin: Return more precise types from PopulateFile.java
This commit is contained in:
@@ -5,6 +5,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.github.codeql.Label;
|
||||
import com.github.codeql.DbFile;
|
||||
import com.github.codeql.TrapWriter;
|
||||
import com.github.codeql.KotlinExtractorDbSchemeKt;
|
||||
import com.semmle.util.exception.CatastrophicError;
|
||||
@@ -75,7 +76,7 @@ public class PopulateFile {
|
||||
return getFileLabel(absoluteFile, true);
|
||||
}
|
||||
|
||||
public Label getFileLabel(File absoluteFile, boolean populateTables) {
|
||||
public Label<DbFile> getFileLabel(File absoluteFile, boolean populateTables) {
|
||||
String databasePath = transformer.fileAsDatabaseString(absoluteFile);
|
||||
Label result = tw.getLabelFor("@\"" + escapeKey(databasePath) + ";sourcefile" + "\"");
|
||||
// Ensure the rewritten path is used from now on.
|
||||
@@ -113,7 +114,7 @@ public class PopulateFile {
|
||||
return getFileInJarLabel(jarFile, pathWithinJar, true);
|
||||
}
|
||||
|
||||
public Label getFileInJarLabel(File jarFile, String pathWithinJar, boolean populateTables) {
|
||||
public Label<DbFile> getFileInJarLabel(File jarFile, String pathWithinJar, boolean populateTables) {
|
||||
if (pathWithinJar.contains("\\"))
|
||||
throw new CatastrophicError("Invalid jar path: '" + pathWithinJar + "' should not contain '\\'.");
|
||||
|
||||
@@ -148,4 +149,4 @@ public class PopulateFile {
|
||||
return current;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,13 +163,11 @@ open class FileTrapWriter (
|
||||
): TrapWriter (lm, bw) {
|
||||
val populateFile = PopulateFile(this)
|
||||
val splitFilePath = filePath.split("!/")
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val fileId =
|
||||
(if(splitFilePath.size == 1)
|
||||
if(splitFilePath.size == 1)
|
||||
populateFile.getFileLabel(File(filePath), populateFileTables)
|
||||
else
|
||||
populateFile.getFileInJarLabel(File(splitFilePath.get(0)), splitFilePath.get(1), populateFileTables)
|
||||
) as Label<DbFile>
|
||||
|
||||
fun getLocation(e: IrElement): Label<DbLocation> {
|
||||
return getLocation(e.startOffset, e.endOffset)
|
||||
|
||||
Reference in New Issue
Block a user