mirror of
https://github.com/github/codeql.git
synced 2026-04-28 02:05:14 +02:00
Extract companion objects from interfaces
This commit is contained in:
@@ -348,8 +348,8 @@ class_object(
|
||||
unique int instance: @field ref
|
||||
);
|
||||
|
||||
class_companion_object(
|
||||
unique int id: @class ref,
|
||||
type_companion_object(
|
||||
unique int id: @classorinterface ref,
|
||||
unique int instance: @field ref,
|
||||
unique int companion_object: @class ref
|
||||
);
|
||||
|
||||
@@ -695,11 +695,6 @@ class Class extends ClassOrInterface, @class {
|
||||
)
|
||||
}
|
||||
|
||||
/** Get the companion object of this class, if any. */
|
||||
ClassCompanionObject getCompanionObject() {
|
||||
class_companion_object(this, _, result)
|
||||
}
|
||||
|
||||
override string getAPrimaryQlClass() { result = "Class" }
|
||||
}
|
||||
|
||||
@@ -718,12 +713,12 @@ class ClassObject extends Class {
|
||||
/** A Kotlin `companion object`. */
|
||||
class ClassCompanionObject extends Class {
|
||||
ClassCompanionObject() {
|
||||
class_companion_object(_, _, this)
|
||||
type_companion_object(_, _, this)
|
||||
}
|
||||
|
||||
/** Gets the instance variable that implements this `companion object`. */
|
||||
Field getInstance() {
|
||||
class_companion_object(_, result, this)
|
||||
type_companion_object(_, result, this)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -964,6 +959,9 @@ class ClassOrInterface extends RefType, @classorinterface {
|
||||
|
||||
/** Holds if this class or interface is explicitly or implicitly a sealed class (Java 17 feature). */
|
||||
predicate isSealed() { exists(this.getAPermittedSubtype()) }
|
||||
|
||||
/** Get the companion object of this class or interface, if any. */
|
||||
ClassCompanionObject getCompanionObject() { type_companion_object(this, _, result) }
|
||||
}
|
||||
|
||||
private string getAPublicObjectMethodSignature() {
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
| companion_objects.kt:3:5:5:5 | MyClassCompanion | companion_objects.kt:9:5:9:11 | MyClassCompanion |
|
||||
| companion_objects.kt:3:5:5:5 | MyClassCompanion | companion_objects.kt:23:5:23:11 | MyClassCompanion |
|
||||
| companion_objects.kt:10:5:12:5 | MyInterfaceCompanion | companion_objects.kt:25:5:25:15 | MyInterfaceCompanion |
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
| companion_objects.kt:1:1:6:1 | MyClass | companion_objects.kt:3:5:5:5 | MyClassCompanion | companion_objects.kt:3:5:5:5 | MyClassCompanion | final,public,static |
|
||||
| companion_objects.kt:8:1:13:1 | MyInterface | companion_objects.kt:10:5:12:5 | MyInterfaceCompanion | companion_objects.kt:10:5:12:5 | MyInterfaceCompanion | final,public,static |
|
||||
|
||||
@@ -5,8 +5,24 @@ class MyClass {
|
||||
}
|
||||
}
|
||||
|
||||
interface MyInterface {
|
||||
fun funInInterface()
|
||||
companion object MyInterfaceCompanion {
|
||||
fun funInCompanion() {}
|
||||
}
|
||||
}
|
||||
|
||||
class Imp : MyInterface {
|
||||
override fun funInInterface() {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun user() {
|
||||
MyClass.funInCompanion()
|
||||
MyClass().funInClass()
|
||||
MyInterface.funInCompanion()
|
||||
Imp().funInInterface()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import java
|
||||
|
||||
from Class c, ClassCompanionObject cco, Field f
|
||||
from ClassOrInterface c, ClassCompanionObject cco, Field f
|
||||
where c.fromSource()
|
||||
and cco = c.getCompanionObject()
|
||||
and f = cco.getInstance()
|
||||
|
||||
@@ -1,2 +1,5 @@
|
||||
| companion_objects.kt:9:5:9:11 | MyClassCompanion | VarAccess | companion_objects.kt:4:9:4:31 | funInCompanion |
|
||||
| companion_objects.kt:10:5:10:13 | new MyClass(...) | ClassInstanceExpr | companion_objects.kt:2:5:2:23 | funInClass |
|
||||
| companion_objects.kt:17:9:17:35 | StandardKt | TypeAccess | file:///!unknown-binary-location/kotlin/StandardKt.class:0:0:0:0 | TODO |
|
||||
| companion_objects.kt:23:5:23:11 | MyClassCompanion | VarAccess | companion_objects.kt:4:9:4:31 | funInCompanion |
|
||||
| companion_objects.kt:24:5:24:13 | new MyClass(...) | ClassInstanceExpr | companion_objects.kt:2:5:2:23 | funInClass |
|
||||
| companion_objects.kt:25:5:25:15 | MyInterfaceCompanion | VarAccess | companion_objects.kt:11:9:11:31 | funInCompanion |
|
||||
| companion_objects.kt:26:5:26:9 | new Imp(...) | ClassInstanceExpr | companion_objects.kt:16:14:18:5 | funInInterface |
|
||||
|
||||
Reference in New Issue
Block a user