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

Skip to content

Commit 87e8425

Browse files
committed
Kotlin: Extract the abstractness of classes.
1 parent 45658e5 commit 87e8425

1 file changed

Lines changed: 21 additions & 13 deletions

File tree

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import com.github.codeql.comments.CommentExtractor
44
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
55
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
66
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
7-
import org.jetbrains.kotlin.descriptors.ClassKind
7+
import org.jetbrains.kotlin.descriptors.*
88
import org.jetbrains.kotlin.ir.IrElement
99
import org.jetbrains.kotlin.ir.IrStatement
1010
import org.jetbrains.kotlin.ir.declarations.*
@@ -493,7 +493,8 @@ open class KotlinUsesExtractor(
493493
tw.writeIsParameterized(id)
494494
val unbound = useClassSource(c)
495495
tw.writeErasure(id, unbound)
496-
extractClassCommon(c, id)
496+
extractClassModifiers(c, id)
497+
extractClassSupertypes(c, id)
497498

498499
return id
499500
}
@@ -570,7 +571,7 @@ open class KotlinUsesExtractor(
570571
dimensions,
571572
componentTypeLabel)
572573

573-
extractClassCommon(arrayType.classifier.owner as IrClass, it)
574+
extractClassSupertypes(arrayType.classifier.owner as IrClass, it)
574575

575576
// array.length
576577
val length = tw.getLabelFor<DbField>("@\"field;{$it};length\"")
@@ -861,7 +862,21 @@ class X {
861862
return tw.getLabelFor(l)
862863
}
863864

864-
fun extractClassCommon(c: IrClass, id: Label<out DbReftype>) {
865+
fun extractModifier(m: String): Label<DbModifier> {
866+
val modifierLabel = "@\"modifier;$m\""
867+
val id: Label<DbModifier> = tw.getLabelFor(modifierLabel, {
868+
tw.writeModifiers(it, m)
869+
})
870+
return id
871+
}
872+
873+
fun extractClassModifiers(c: IrClass, id: Label<out DbClassorinterface>) {
874+
if (c.modality == Modality.ABSTRACT) {
875+
tw.writeHasModifier(id, extractModifier("abstract"))
876+
}
877+
}
878+
879+
fun extractClassSupertypes(c: IrClass, id: Label<out DbReftype>) {
865880
for(t in c.superTypes) {
866881
when(t) {
867882
is IrSimpleType -> {
@@ -1122,7 +1137,8 @@ open class KotlinFileExtractor(
11221137
tw.writeClass_object(id as Label<DbClass>, instance.id)
11231138
}
11241139

1125-
extractClassCommon(c, id)
1140+
extractClassModifiers(c, id)
1141+
extractClassSupertypes(c, id)
11261142

11271143
return id
11281144
}
@@ -2011,14 +2027,6 @@ open class KotlinFileExtractor(
20112027
}
20122028
}
20132029

2014-
fun extractModifier(m: String): Label<DbModifier> {
2015-
val modifierLabel = "@\"modifier;$m\""
2016-
val id: Label<DbModifier> = tw.getLabelFor(modifierLabel, {
2017-
tw.writeModifiers(it, m)
2018-
})
2019-
return id
2020-
}
2021-
20222030
fun extractTypeAccess(t: IrType, callable: Label<out DbCallable>, parent: Label<out DbExprparent>, idx: Int, elementForLocation: IrElement) {
20232031
// TODO: elementForLocation allows us to give some sort of
20242032
// location, but a proper location for the type access will

0 commit comments

Comments
 (0)