Kotlin: Return more precise types from PopulateFile.java

This commit is contained in:
Ian Lynagh
2021-11-22 17:48:44 +00:00
parent 83ac77dccc
commit 1990b68c21
2 changed files with 5 additions and 6 deletions

View File

@@ -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;
}
}
}

View File

@@ -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)