Make standard library locations consistent between Java and Kotlin

This commit is contained in:
Chris Smowton
2021-11-25 16:13:51 +00:00
committed by Ian Lynagh
parent 547b60d68f
commit 64e1367e59
5 changed files with 25 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
package com.github.codeql
import com.intellij.openapi.vfs.StandardFileSystems
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
@@ -45,9 +46,15 @@ fun getIrClassVirtualFile(irClass: IrClass): VirtualFile? {
return null
}
fun getRawIrClassBinaryPath(irClass: IrClass): String? {
return getIrClassVirtualFile(irClass)?.getPath()
}
fun getRawIrClassBinaryPath(irClass: IrClass) =
getIrClassVirtualFile(irClass)?.let {
val path = it.path
if(it.fileSystem.protocol == StandardFileSystems.JRT_PROTOCOL)
// For JRT files, which we assume to be the JDK, hide the containing JAR path to match the Java extractor's behaviour.
"/${path.split("!/", limit = 2)[1]}"
else
path
}
fun getIrClassBinaryPath(irClass: IrClass): String {
return getRawIrClassBinaryPath(irClass)

View File

@@ -0,0 +1,3 @@
package main;
public class Q {}

View File

@@ -0,0 +1,3 @@
package main
class W {}

View File

@@ -0,0 +1,2 @@
| Q.java:0:0:0:0 | Q |
| W.kt:0:0:0:0 | W |

View File

@@ -0,0 +1,7 @@
import java
from File f
where f.getExtension() in ["java", "kt"]
select f
// This test is mainly a consistency test; just checking that both the Java and Kotlin source were extracted here