Skip to content

Commit 6ca2a97

Browse files
authored
Merge pull request github#104 from github/igfoo/abstract
Kotlin: Extract the abstractness of classes.
2 parents 479bf8d + 00c28d6 commit 6ca2a97

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

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.*
@@ -494,7 +494,8 @@ open class KotlinUsesExtractor(
494494
tw.writeIsParameterized(id)
495495
val unbound = useClassSource(c)
496496
tw.writeErasure(id, unbound)
497-
extractClassCommon(c, id)
497+
extractClassModifiers(c, id)
498+
extractClassSupertypes(c, id)
498499

499500
return id
500501
}
@@ -571,7 +572,7 @@ open class KotlinUsesExtractor(
571572
dimensions,
572573
componentTypeLabel)
573574

574-
extractClassCommon(arrayType.classifier.owner as IrClass, it)
575+
extractClassSupertypes(arrayType.classifier.owner as IrClass, it)
575576

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

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

1126-
extractClassCommon(c, id)
1141+
extractClassModifiers(c, id)
1142+
extractClassSupertypes(c, id)
11271143

11281144
return id
11291145
}
@@ -2012,14 +2028,6 @@ open class KotlinFileExtractor(
20122028
}
20132029
}
20142030

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

0 commit comments

Comments
 (0)