Skip to content

Consider containingClass when matching psi methods and KFuncitons #1398 #1502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.utbot.framework.plugin.api

import org.utbot.framework.plugin.api.util.declaringClazz
import kotlin.reflect.KFunction
import kotlin.reflect.KParameter
import kotlin.reflect.jvm.javaType

// Note that rules for obtaining signature here should correlate with PsiMethod.signature()
fun KFunction<*>.methodDescription() =
MethodDescription(
this.name,
this.declaringClazz.name,
this.parameters.filter { it.kind != KParameter.Kind.INSTANCE }.map { it.type.javaType.typeName }
)

// Similar to MethodId, but significantly simplified -- used only to match methods from psi and their reflections
data class MethodDescription(val name: String, val containingClass: String?, val parameterTypes: List<String?>) {

fun normalized() = this.copy(
containingClass = containingClass?.replace("$", "."), // normalize names of nested classes
parameterTypes = parameterTypes.map {
it?.replace("$", ".")
}
)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.utbot.framework.codegen.domain.RuntimeExceptionTestsBehaviour
import org.utbot.framework.codegen.domain.testFrameworkByName
import org.utbot.framework.codegen.reports.TestsGenerationReport
import org.utbot.framework.plugin.api.*
import org.utbot.framework.plugin.api.Signature
import org.utbot.framework.plugin.api.MethodDescription
import org.utbot.framework.plugin.api.util.UtContext
import org.utbot.framework.plugin.api.util.executableId
import org.utbot.framework.plugin.api.util.id
Expand Down Expand Up @@ -159,19 +159,21 @@ private fun EngineProcessModel.setup(kryoHelper: KryoHelper, watchdog: IdleWatch
}
watchdog.wrapActiveCall(findMethodsInClassMatchingSelected) { params ->
val classId = kryoHelper.readObject<ClassId>(params.classId)
val selectedSignatures = params.signatures.map { Signature(it.name, it.parametersTypes) }
val selectedMethodDescriptions =
params.methodDescriptions.map { MethodDescription(it.name, it.containingClass, it.parametersTypes) }
FindMethodsInClassMatchingSelectedResult(kryoHelper.writeObject(classId.jClass.allNestedClasses.flatMap { clazz ->
clazz.id.allMethods.mapNotNull { it.method.kotlinFunction }.sortedWith(compareBy { selectedSignatures.indexOf(it.signature()) })
.filter { it.signature().normalized() in selectedSignatures }
clazz.id.allMethods.mapNotNull { it.method.kotlinFunction }
.sortedWith(compareBy { selectedMethodDescriptions.indexOf(it.methodDescription()) })
.filter { it.methodDescription().normalized() in selectedMethodDescriptions }
.map { it.executableId }
}))
}
watchdog.wrapActiveCall(findMethodParamNames) { params ->
val classId = kryoHelper.readObject<ClassId>(params.classId)
val bySignature = kryoHelper.readObject<Map<Signature, List<String>>>(params.bySignature)
val byMethodDescription = kryoHelper.readObject<Map<MethodDescription, List<String>>>(params.bySignature)
FindMethodParamNamesResult(kryoHelper.writeObject(
classId.jClass.allNestedClasses.flatMap { clazz -> clazz.id.allMethods.mapNotNull { it.method.kotlinFunction } }
.mapNotNull { method -> bySignature[method.signature()]?.let { params -> method.executableId to params } }
.mapNotNull { method -> byMethodDescription[method.methodDescription()]?.let { params -> method.executableId to params } }
.toMap()
))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class EngineProcessModel private constructor(
serializers.register(RenderParams)
serializers.register(RenderResult)
serializers.register(SetupContextParams)
serializers.register(Signature)
serializers.register(MethodDescription)
serializers.register(FindMethodsInClassMatchingSelectedArguments)
serializers.register(FindMethodsInClassMatchingSelectedResult)
serializers.register(FindMethodParamNamesArguments)
Expand Down Expand Up @@ -71,9 +71,9 @@ class EngineProcessModel private constructor(
bind(lifetime, protocol, "EngineProcessModel")
}
}
const val serializationHash = -621732450296355904L


const val serializationHash = -6219345436129699239L

}
override val serializersOwner: ISerializersOwner get() = EngineProcessModel
Expand Down Expand Up @@ -180,7 +180,7 @@ val IProtocol.engineProcessModel get() = getOrCreateExtension(EngineProcessModel


/**
* #### Generated from [EngineProcessModel.kt:99]
* #### Generated from [EngineProcessModel.kt:100]
*/
data class FindMethodParamNamesArguments (
val classId: ByteArray,
Expand Down Expand Up @@ -243,7 +243,7 @@ data class FindMethodParamNamesArguments (


/**
* #### Generated from [EngineProcessModel.kt:103]
* #### Generated from [EngineProcessModel.kt:104]
*/
data class FindMethodParamNamesResult (
val paramNames: ByteArray
Expand Down Expand Up @@ -300,27 +300,27 @@ data class FindMethodParamNamesResult (


/**
* #### Generated from [EngineProcessModel.kt:92]
* #### Generated from [EngineProcessModel.kt:93]
*/
data class FindMethodsInClassMatchingSelectedArguments (
val classId: ByteArray,
val signatures: List<Signature>
val methodDescriptions: List<MethodDescription>
) : IPrintable {
//companion

companion object : IMarshaller<FindMethodsInClassMatchingSelectedArguments> {
override val _type: KClass<FindMethodsInClassMatchingSelectedArguments> = FindMethodsInClassMatchingSelectedArguments::class

@Suppress("UNCHECKED_CAST")
override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): FindMethodsInClassMatchingSelectedArguments {
override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): FindMethodsInClassMatchingSelectedArguments {
val classId = buffer.readByteArray()
val signatures = buffer.readList { Signature.read(ctx, buffer) }
return FindMethodsInClassMatchingSelectedArguments(classId, signatures)
val methodDescriptions = buffer.readList { MethodDescription.read(ctx, buffer) }
return FindMethodsInClassMatchingSelectedArguments(classId, methodDescriptions)
}

override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: FindMethodsInClassMatchingSelectedArguments) {
buffer.writeByteArray(value.classId)
buffer.writeList(value.signatures) { v -> Signature.write(ctx, buffer, v) }
buffer.writeList(value.methodDescriptions) { v -> MethodDescription.write(ctx, buffer, v) }
}


Expand All @@ -335,25 +335,25 @@ data class FindMethodsInClassMatchingSelectedArguments (
if (other == null || other::class != this::class) return false

other as FindMethodsInClassMatchingSelectedArguments

if (!(classId contentEquals other.classId)) return false
if (signatures != other.signatures) return false
if (methodDescriptions != other.methodDescriptions) return false

return true
}
//hash code trait
override fun hashCode(): Int {
var __r = 0
__r = __r*31 + classId.contentHashCode()
__r = __r*31 + signatures.hashCode()
__r = __r * 31 + classId.contentHashCode()
__r = __r * 31 + methodDescriptions.hashCode()
return __r
}
//pretty print
override fun print(printer: PrettyPrinter) {
printer.println("FindMethodsInClassMatchingSelectedArguments (")
printer.indent {
print("classId = "); classId.print(printer); println()
print("signatures = "); signatures.print(printer); println()
print("methodDescriptions = "); methodDescriptions.print(printer); println()
}
printer.print(")")
}
Expand All @@ -363,7 +363,7 @@ data class FindMethodsInClassMatchingSelectedArguments (


/**
* #### Generated from [EngineProcessModel.kt:96]
* #### Generated from [EngineProcessModel.kt:97]
*/
data class FindMethodsInClassMatchingSelectedResult (
val executableIds: ByteArray
Expand Down Expand Up @@ -606,7 +606,7 @@ data class GenerateResult (


/**
* #### Generated from [EngineProcessModel.kt:111]
* #### Generated from [EngineProcessModel.kt:112]
*/
data class GenerateTestReportArgs (
val eventLogMessage: String?,
Expand Down Expand Up @@ -699,7 +699,7 @@ data class GenerateTestReportArgs (


/**
* #### Generated from [EngineProcessModel.kt:120]
* #### Generated from [EngineProcessModel.kt:121]
*/
data class GenerateTestReportResult (
val notifyMessage: String,
Expand Down Expand Up @@ -830,10 +830,82 @@ data class JdkInfo (
}


/**
* #### Generated from [EngineProcessModel.kt:88]
*/
data class MethodDescription(
val name: String,
val containingClass: String?,
val parametersTypes: List<String?>
) : IPrintable {
//companion

companion object : IMarshaller<MethodDescription> {
override val _type: KClass<MethodDescription> = MethodDescription::class

@Suppress("UNCHECKED_CAST")
override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): MethodDescription {
val name = buffer.readString()
val containingClass = buffer.readNullable { buffer.readString() }
val parametersTypes = buffer.readList { buffer.readNullable { buffer.readString() } }
return MethodDescription(name, containingClass, parametersTypes)
}

override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: MethodDescription) {
buffer.writeString(value.name)
buffer.writeNullable(value.containingClass) { buffer.writeString(it) }
buffer.writeList(value.parametersTypes) { v -> buffer.writeNullable(v) { buffer.writeString(it) } }
}


}

//fields
//methods
//initializer
//secondary constructor
//equals trait
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || other::class != this::class) return false

other as MethodDescription

if (name != other.name) return false
if (containingClass != other.containingClass) return false
if (parametersTypes != other.parametersTypes) return false

return true
}

//hash code trait
override fun hashCode(): Int {
var __r = 0
__r = __r * 31 + name.hashCode()
__r = __r * 31 + if (containingClass != null) containingClass.hashCode() else 0
__r = __r * 31 + parametersTypes.hashCode()
return __r
}

//pretty print
override fun print(printer: PrettyPrinter) {
printer.println("MethodDescription (")
printer.indent {
print("name = "); name.print(printer); println()
print("containingClass = "); containingClass.print(printer); println()
print("parametersTypes = "); parametersTypes.print(printer); println()
}
printer.print(")")
}
//deepClone
//contexts
}


/**
* #### Generated from [EngineProcessModel.kt:64]
*/
data class RenderParams (
data class RenderParams(
val testSetsId: Long,
val classUnderTest: ByteArray,
val paramNames: ByteArray,
Expand Down Expand Up @@ -1091,69 +1163,6 @@ data class SetupContextParams (
}


/**
* #### Generated from [EngineProcessModel.kt:88]
*/
data class Signature (
val name: String,
val parametersTypes: List<String?>
) : IPrintable {
//companion

companion object : IMarshaller<Signature> {
override val _type: KClass<Signature> = Signature::class

@Suppress("UNCHECKED_CAST")
override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): Signature {
val name = buffer.readString()
val parametersTypes = buffer.readList { buffer.readNullable { buffer.readString() } }
return Signature(name, parametersTypes)
}

override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: Signature) {
buffer.writeString(value.name)
buffer.writeList(value.parametersTypes) { v -> buffer.writeNullable(v) { buffer.writeString(it) } }
}


}
//fields
//methods
//initializer
//secondary constructor
//equals trait
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || other::class != this::class) return false

other as Signature

if (name != other.name) return false
if (parametersTypes != other.parametersTypes) return false

return true
}
//hash code trait
override fun hashCode(): Int {
var __r = 0
__r = __r*31 + name.hashCode()
__r = __r*31 + parametersTypes.hashCode()
return __r
}
//pretty print
override fun print(printer: PrettyPrinter) {
printer.println("Signature (")
printer.indent {
print("name = "); name.print(printer); println()
print("parametersTypes = "); parametersTypes.print(printer); println()
}
printer.print(")")
}
//deepClone
//contexts
}


/**
* #### Generated from [EngineProcessModel.kt:36]
*/
Expand Down Expand Up @@ -1230,7 +1239,7 @@ data class TestGeneratorParams (


/**
* #### Generated from [EngineProcessModel.kt:106]
* #### Generated from [EngineProcessModel.kt:107]
*/
data class WriteSarifReportArguments (
val testSetsId: Long,
Expand Down
Loading