Skip to content

Commit fa0bd03

Browse files
tamasvajksmowton
authored andcommitted
Fix extension property labels
1 parent 25fce5f commit fa0bd03

4 files changed

Lines changed: 36 additions & 25 deletions

File tree

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -795,14 +795,14 @@ open class KotlinFileExtractor(
795795
return id
796796
}
797797

798-
fun extractProperty(p: IrProperty, parentId: Label<out DbReftype>, extractBackingField: Boolean, typeSubstitution: TypeSubstitution?, classTypeArgs: List<IrTypeArgument>?) {
798+
fun extractProperty(p: IrProperty, parentId: Label<out DbReftype>, extractBackingField: Boolean, typeSubstitution: TypeSubstitution?, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?) {
799799
with("property", p) {
800800
if (isFake(p)) return
801801

802802
DeclarationStackAdjuster(p).use {
803803

804-
val id = useProperty(p, parentId)
805-
val locId = getLocation(p, classTypeArgs)
804+
val id = useProperty(p, parentId, classTypeArgsIncludingOuterClasses)
805+
val locId = getLocation(p, classTypeArgsIncludingOuterClasses)
806806
tw.writeKtProperties(id, p.name.asString())
807807
tw.writeHasLocation(id, locId)
808808

@@ -811,7 +811,7 @@ open class KotlinFileExtractor(
811811
val setter = p.setter
812812

813813
if (getter != null) {
814-
val getterId = extractFunction(getter, parentId, extractBackingField, typeSubstitution, classTypeArgs)?.cast<DbMethod>()
814+
val getterId = extractFunction(getter, parentId, extractBackingField, typeSubstitution, classTypeArgsIncludingOuterClasses)?.cast<DbMethod>()
815815
if (getterId != null) {
816816
tw.writeKtPropertyGetters(id, getterId)
817817
}
@@ -825,7 +825,7 @@ open class KotlinFileExtractor(
825825
if (!p.isVar) {
826826
logger.errorElement("!isVar property with a setter", p)
827827
}
828-
val setterId = extractFunction(setter, parentId, extractBackingField, typeSubstitution, classTypeArgs)?.cast<DbMethod>()
828+
val setterId = extractFunction(setter, parentId, extractBackingField, typeSubstitution, classTypeArgsIncludingOuterClasses)?.cast<DbMethod>()
829829
if (setterId != null) {
830830
tw.writeKtPropertySetters(id, setterId)
831831
}

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

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,12 @@ import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
77
import org.jetbrains.kotlin.backend.common.ir.allOverridden
88
import org.jetbrains.kotlin.backend.common.lower.parentsWithSelf
99
import org.jetbrains.kotlin.builtins.StandardNames
10-
import org.jetbrains.kotlin.descriptors.ClassKind
11-
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
10+
import org.jetbrains.kotlin.descriptors.*
1211
import org.jetbrains.kotlin.ir.declarations.*
13-
import org.jetbrains.kotlin.ir.expressions.IrConst
14-
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
15-
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
16-
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
12+
import org.jetbrains.kotlin.ir.expressions.*
13+
import org.jetbrains.kotlin.ir.symbols.*
1714
import org.jetbrains.kotlin.ir.types.*
18-
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
19-
import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection
15+
import org.jetbrains.kotlin.ir.types.impl.*
2016
import org.jetbrains.kotlin.ir.util.*
2117
import org.jetbrains.kotlin.load.java.JvmAbi
2218
import org.jetbrains.kotlin.name.FqName
@@ -808,7 +804,9 @@ open class KotlinUsesExtractor(
808804
// The type parameters of the function. This does not include type parameters of enclosing classes.
809805
functionTypeParameters: List<IrTypeParameter>,
810806
// The type arguments of enclosing classes of the function.
811-
classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?
807+
classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?,
808+
// The prefix used in the label. "callable", unless a property label is created, then it's "property".
809+
prefix: String = "callable"
812810
): String {
813811
val parentId = maybeParentId ?: useDeclarationParent(parent, false, classTypeArgsIncludingOuterClasses, true)
814812
val allParams = if (extensionReceiverParameter == null) {
@@ -844,7 +842,7 @@ open class KotlinUsesExtractor(
844842
// method (and presumably that disambiguation is never needed when the method belongs to a parameterized
845843
// instance of a generic class), but as of now I don't know when the raw method would be referred to.
846844
val typeArgSuffix = if (functionTypeParameters.isNotEmpty() && classTypeArgsIncludingOuterClasses.isNullOrEmpty()) "<${functionTypeParameters.size}>" else "";
847-
return "@\"callable;{$parentId}.$name($paramTypeIds){$returnTypeId}${typeArgSuffix}\""
845+
return "@\"$prefix;{$parentId}.$name($paramTypeIds){$returnTypeId}${typeArgSuffix}\""
848846
}
849847

850848
protected fun IrFunction.isLocalFunction(): Boolean {
@@ -1174,24 +1172,29 @@ open class KotlinUsesExtractor(
11741172
if (parentId == null) {
11751173
return null
11761174
} else {
1177-
return getPropertyLabel(p, parentId)
1175+
return getPropertyLabel(p, parentId, null)
11781176
}
11791177
}
11801178

1181-
fun getPropertyLabel(p: IrProperty, parentId: Label<out DbElement>) =
1182-
"@\"property;{$parentId};${p.name.asString()}\""
1179+
private fun getPropertyLabel(p: IrProperty, parentId: Label<out DbElement>, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?): String {
1180+
val getter = p.getter
1181+
val setter = p.setter
11831182

1184-
fun useProperty(p: IrProperty): Label<out DbKt_property>? {
1185-
val label = getPropertyLabel(p)
1186-
if (label == null) {
1187-
return null
1183+
val func = getter ?: setter
1184+
val ext = func?.extensionReceiverParameter
1185+
1186+
return if (ext == null) {
1187+
"@\"property;{$parentId};${p.name.asString()}\""
11881188
} else {
1189-
return tw.getLabelFor<DbKt_property>(label).also { extractPropertyLaterIfExternalFileMember(p) }
1189+
val returnType = getter?.returnType ?: setter?.valueParameters?.singleOrNull()?.type ?: pluginContext.irBuiltIns.unitType
1190+
val typeParams = getFunctionTypeParameters(func)
1191+
1192+
getFunctionLabel(p.parent, parentId, p.name.asString(), listOf(), returnType, ext, typeParams, classTypeArgsIncludingOuterClasses, "property")
11901193
}
11911194
}
11921195

1193-
fun useProperty(p: IrProperty, parentId: Label<out DbElement>): Label<out DbKt_property> =
1194-
tw.getLabelFor<DbKt_property>(getPropertyLabel(p, parentId)).also { extractPropertyLaterIfExternalFileMember(p) }
1196+
fun useProperty(p: IrProperty, parentId: Label<out DbElement>, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?): Label<out DbKt_property> =
1197+
tw.getLabelFor<DbKt_property>(getPropertyLabel(p, parentId, classTypeArgsIncludingOuterClasses)).also { extractPropertyLaterIfExternalFileMember(p) }
11951198

11961199
fun getEnumEntryLabel(ee: IrEnumEntry): String {
11971200
val parentId = useDeclarationParent(ee.parent, false)

java/ql/test/kotlin/library-tests/properties/properties.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,5 @@ fieldDeclarations
4646
| properties.kt:38:5:38:34 | internalProp | properties.kt:38:14:38:34 | getInternalProp | file://:0:0:0:0 | <none> | properties.kt:38:5:38:34 | internalProp | internal |
4747
| properties.kt:67:1:67:23 | constVal | properties.kt:67:7:67:23 | getConstVal | file://:0:0:0:0 | <none> | properties.kt:67:1:67:23 | constVal | public |
4848
| properties.kt:70:5:70:16 | prop | properties.kt:70:5:70:16 | getProp | file://:0:0:0:0 | <none> | properties.kt:70:5:70:16 | prop | public |
49+
| properties.kt:78:1:79:13 | x | properties.kt:79:5:79:13 | getX | file://:0:0:0:0 | <none> | file://:0:0:0:0 | <none> | public |
50+
| properties.kt:80:1:81:13 | x | properties.kt:81:5:81:13 | getX | file://:0:0:0:0 | <none> | file://:0:0:0:0 | <none> | public |

java/ql/test/kotlin/library-tests/properties/properties.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,9 @@ class C<T> {
7373
println(c.prop)
7474
}
7575
}
76+
77+
78+
val Int.x : Int
79+
get() = 5
80+
val Double.x : Int
81+
get() = 5

0 commit comments

Comments
 (0)