diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/process/RdInstrumenter.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/process/RdInstrumenter.kt index bb5aee3866..e7d033181b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/process/RdInstrumenter.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/process/RdInstrumenter.kt @@ -14,17 +14,17 @@ private val logger = KotlinLogging.logger { } class RdInstrumenter(private val rdInstrumenterAdapter: RdInstrumenterAdapter) : InstrumenterAdapter() { override fun computeSourceFileByClass( - className: String, - packageName: String?, + clazz: Class<*>, directoryToSearchRecursively: Path ): File? { - logger.debug { "starting computeSourceFileByClass with classname - $className" } + val canonicalClassName = clazz.canonicalName + logger.debug { "starting computeSourceFileByClass for class - $canonicalClassName" } val result = logger.logException { - val arguments = ComputeSourceFileByClassArguments(className, packageName) + val arguments = ComputeSourceFileByClassArguments(canonicalClassName) rdInstrumenterAdapter.computeSourceFileByClass.startBlocking(arguments) } - logger.debug { "computeSourceFileByClass result for $className from idea: $result" } + logger.debug { "computeSourceFileByClass result for $canonicalClassName from idea: $result" } return result?.let { File(it) } } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/EngineProcessModel.Generated.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/EngineProcessModel.Generated.kt index 180487cff5..f06c0eaa9c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/EngineProcessModel.Generated.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/EngineProcessModel.Generated.kt @@ -15,7 +15,7 @@ import kotlin.jvm.JvmStatic /** - * #### Generated from [EngineProcessModel.kt:31] + * #### Generated from [EngineProcessModel.kt:30] */ class EngineProcessModel private constructor( private val _setupUtContext: RdCall, @@ -177,7 +177,7 @@ val IProtocol.engineProcessModel get() = getOrCreateExtension(EngineProcessModel /** - * #### Generated from [EngineProcessModel.kt:100] + * #### Generated from [EngineProcessModel.kt:99] */ data class FindMethodParamNamesArguments ( val classId: ByteArray, @@ -240,7 +240,7 @@ data class FindMethodParamNamesArguments ( /** - * #### Generated from [EngineProcessModel.kt:104] + * #### Generated from [EngineProcessModel.kt:103] */ data class FindMethodParamNamesResult ( val paramNames: ByteArray @@ -297,7 +297,7 @@ data class FindMethodParamNamesResult ( /** - * #### Generated from [EngineProcessModel.kt:93] + * #### Generated from [EngineProcessModel.kt:92] */ data class FindMethodsInClassMatchingSelectedArguments ( val classId: ByteArray, @@ -360,7 +360,7 @@ data class FindMethodsInClassMatchingSelectedArguments ( /** - * #### Generated from [EngineProcessModel.kt:97] + * #### Generated from [EngineProcessModel.kt:96] */ data class FindMethodsInClassMatchingSelectedResult ( val executableIds: ByteArray @@ -417,7 +417,7 @@ data class FindMethodsInClassMatchingSelectedResult ( /** - * #### Generated from [EngineProcessModel.kt:43] + * #### Generated from [EngineProcessModel.kt:42] */ data class GenerateParams ( val mockInstalled: Boolean, @@ -540,7 +540,7 @@ data class GenerateParams ( /** - * #### Generated from [EngineProcessModel.kt:61] + * #### Generated from [EngineProcessModel.kt:60] */ data class GenerateResult ( val notEmptyCases: Int, @@ -603,7 +603,7 @@ data class GenerateResult ( /** - * #### Generated from [EngineProcessModel.kt:112] + * #### Generated from [EngineProcessModel.kt:111] */ data class GenerateTestReportArgs ( val eventLogMessage: String?, @@ -696,7 +696,7 @@ data class GenerateTestReportArgs ( /** - * #### Generated from [EngineProcessModel.kt:121] + * #### Generated from [EngineProcessModel.kt:120] */ data class GenerateTestReportResult ( val notifyMessage: String, @@ -765,7 +765,7 @@ data class GenerateTestReportResult ( /** - * #### Generated from [EngineProcessModel.kt:32] + * #### Generated from [EngineProcessModel.kt:31] */ data class JdkInfo ( val path: String, @@ -828,7 +828,7 @@ data class JdkInfo ( /** - * #### Generated from [EngineProcessModel.kt:65] + * #### Generated from [EngineProcessModel.kt:64] */ data class RenderParams ( val testSetsId: Long, @@ -969,7 +969,7 @@ data class RenderParams ( /** - * #### Generated from [EngineProcessModel.kt:82] + * #### Generated from [EngineProcessModel.kt:81] */ data class RenderResult ( val generatedCode: String, @@ -1032,7 +1032,7 @@ data class RenderResult ( /** - * #### Generated from [EngineProcessModel.kt:86] + * #### Generated from [EngineProcessModel.kt:85] */ data class SetupContextParams ( val classpathForUrlsClassloader: List @@ -1089,7 +1089,7 @@ data class SetupContextParams ( /** - * #### Generated from [EngineProcessModel.kt:89] + * #### Generated from [EngineProcessModel.kt:88] */ data class Signature ( val name: String, @@ -1152,7 +1152,7 @@ data class Signature ( /** - * #### Generated from [EngineProcessModel.kt:37] + * #### Generated from [EngineProcessModel.kt:36] */ data class TestGeneratorParams ( val buildDir: Array, @@ -1227,7 +1227,7 @@ data class TestGeneratorParams ( /** - * #### Generated from [EngineProcessModel.kt:107] + * #### Generated from [EngineProcessModel.kt:106] */ data class WriteSarifReportArguments ( val testSetsId: Long, diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/RdInstrumenterAdapter.Generated.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/RdInstrumenterAdapter.Generated.kt index 8612506a27..4a3fc12edf 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/RdInstrumenterAdapter.Generated.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/RdInstrumenterAdapter.Generated.kt @@ -47,7 +47,7 @@ class RdInstrumenterAdapter private constructor( private val __StringNullableSerializer = FrameworkMarshallers.String.nullable() - const val serializationHash = -671974871925861655L + const val serializationHash = 1502978559314472937L } override val serializersOwner: ISerializersOwner get() = RdInstrumenterAdapter @@ -97,8 +97,7 @@ val IProtocol.rdInstrumenterAdapter get() = getOrCreateExtension(RdInstrumenterA * #### Generated from [EngineProcessModel.kt:8] */ data class ComputeSourceFileByClassArguments ( - val className: String, - val packageName: String? + val canonicalClassName: String ) : IPrintable { //companion @@ -107,14 +106,12 @@ data class ComputeSourceFileByClassArguments ( @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): ComputeSourceFileByClassArguments { - val className = buffer.readString() - val packageName = buffer.readNullable { buffer.readString() } - return ComputeSourceFileByClassArguments(className, packageName) + val canonicalClassName = buffer.readString() + return ComputeSourceFileByClassArguments(canonicalClassName) } override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: ComputeSourceFileByClassArguments) { - buffer.writeString(value.className) - buffer.writeNullable(value.packageName) { buffer.writeString(it) } + buffer.writeString(value.canonicalClassName) } @@ -130,24 +127,21 @@ data class ComputeSourceFileByClassArguments ( other as ComputeSourceFileByClassArguments - if (className != other.className) return false - if (packageName != other.packageName) return false + if (canonicalClassName != other.canonicalClassName) return false return true } //hash code trait override fun hashCode(): Int { var __r = 0 - __r = __r*31 + className.hashCode() - __r = __r*31 + if (packageName != null) packageName.hashCode() else 0 + __r = __r*31 + canonicalClassName.hashCode() return __r } //pretty print override fun print(printer: PrettyPrinter) { printer.println("ComputeSourceFileByClassArguments (") printer.indent { - print("className = "); className.print(printer); println() - print("packageName = "); packageName.print(printer); println() + print("canonicalClassName = "); canonicalClassName.print(printer); println() } printer.print(")") } diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/RdSourceFindingStrategy.Generated.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/RdSourceFindingStrategy.Generated.kt index 86806e0930..773ab28d40 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/RdSourceFindingStrategy.Generated.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/RdSourceFindingStrategy.Generated.kt @@ -15,7 +15,7 @@ import kotlin.jvm.JvmStatic /** - * #### Generated from [EngineProcessModel.kt:17] + * #### Generated from [EngineProcessModel.kt:16] */ class RdSourceFindingStrategy private constructor( private val _testsRelativePath: RdCall, @@ -108,7 +108,7 @@ val IProtocol.rdSourceFindingStrategy get() = getOrCreateExtension(RdSourceFindi /** - * #### Generated from [EngineProcessModel.kt:18] + * #### Generated from [EngineProcessModel.kt:17] */ data class SourceStrategyMethodArgs ( val testSetId: Long, diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/instrumenter/InstrumenterAdapter.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/instrumenter/InstrumenterAdapter.kt index 3ed3d16934..1a8ff6cba3 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/instrumenter/InstrumenterAdapter.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/instrumenter/InstrumenterAdapter.kt @@ -52,12 +52,7 @@ open class InstrumenterAdapter { computeSourceFileByClass(it, directoryToSearchRecursively) } - fun computeSourceFileByClass(clazz: Class<*>, directoryToSearchRecursively: Path = Paths.get("")): File? { - val packageName = clazz.`package`?.name?.replace('.', File.separatorChar) - return computeSourceFileByClass(clazz.name, packageName, directoryToSearchRecursively) - } - - open fun computeSourceFileByClass( + fun computeSourceFileByNameAndPackage( className: String, packageName: String?, directoryToSearchRecursively: Path ): File? { val sourceFileName = computeSourceFileName(className) ?: return null @@ -73,4 +68,9 @@ open class InstrumenterAdapter { } return fileWithoutPackage } + + open fun computeSourceFileByClass(clazz: Class<*>, directoryToSearchRecursively: Path = Paths.get("")): File? { + val packageName = clazz.`package`?.name?.replace('.', File.separatorChar) + return computeSourceFileByNameAndPackage(clazz.name, packageName, directoryToSearchRecursively) + } } diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt index dccff24d37..79807c2afc 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt @@ -294,6 +294,13 @@ object UtTestsDialogProcessor { } private val PsiClass.canonicalName: String + /* + This method calculates exactly name that is used by compiler convention, + i.e. result is the exact name of .class file for provided PsiClass. + This value is used to provide classes to engine process - follow usages for clarification. + Equivalent for Class.getCanonicalName. + P.S. We cannot load project class in IDEA jvm + */ get() { return if (packageName.isEmpty()) { qualifiedName?.replace(".", "$") ?: "" diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/process/EngineProcess.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/process/EngineProcess.kt index 8d1b019878..c27a022bfc 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/process/EngineProcess.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/process/EngineProcess.kt @@ -169,7 +169,8 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process private fun computeSourceFileByClass(params: ComputeSourceFileByClassArguments): String = DumbService.getInstance(project).runReadActionInSmartMode { val scope = GlobalSearchScope.allScope(project) - val psiClass = JavaFileManager.getInstance(project).findClass(params.className, scope) + // JavaFileManager requires canonical name as it is said in import + val psiClass = JavaFileManager.getInstance(project).findClass(params.canonicalClassName, scope) val sourceFile = psiClass?.navigationElement?.containingFile?.virtualFile?.canonicalPath logger.debug { "computeSourceFileByClass result: $sourceFile" } diff --git a/utbot-intellij/src/main/resources/log4j2.xml b/utbot-intellij/src/main/resources/log4j2.xml index e584743d00..58caefe205 100644 --- a/utbot-intellij/src/main/resources/log4j2.xml +++ b/utbot-intellij/src/main/resources/log4j2.xml @@ -1,28 +1 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/utbot-rd/src/main/rdgen/org/utbot/rd/models/EngineProcessModel.kt b/utbot-rd/src/main/rdgen/org/utbot/rd/models/EngineProcessModel.kt index c3a40dd71c..8e2c734ffa 100644 --- a/utbot-rd/src/main/rdgen/org/utbot/rd/models/EngineProcessModel.kt +++ b/utbot-rd/src/main/rdgen/org/utbot/rd/models/EngineProcessModel.kt @@ -6,8 +6,7 @@ object EngineProcessRoot : Root() object RdInstrumenterAdapter: Ext(EngineProcessRoot) { val computeSourceFileByClassArguments = structdef { - field("className", PredefinedType.string) - field("packageName", PredefinedType.string.nullable) + field("canonicalClassName", PredefinedType.string) } init { call("computeSourceFileByClass", computeSourceFileByClassArguments, PredefinedType.string.nullable).async diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt index a9777a78a9..ab5ef3b37b 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt @@ -362,7 +362,7 @@ private fun invokeDescriptions(testSet: UtMethodTestSet, searchDirectory: Path): //TODO(SAT-1170) .filterNot { "\$lambda" in it.declaringClass.name } .mapNotNull { sootMethod -> - val methodFile = Instrumenter.adapter.computeSourceFileByClass( + val methodFile = Instrumenter.adapter.computeSourceFileByNameAndPackage( sootMethod.declaringClass.name, sootMethod.declaringClass.javaPackageName.replace(".", File.separator), searchDirectory diff --git a/utbot-ui-commons/src/main/kotlin/org/utbot/intellij/plugin/util/IntelliJApiHelper.kt b/utbot-ui-commons/src/main/kotlin/org/utbot/intellij/plugin/util/IntelliJApiHelper.kt index 9690285e68..683c69d2c1 100644 --- a/utbot-ui-commons/src/main/kotlin/org/utbot/intellij/plugin/util/IntelliJApiHelper.kt +++ b/utbot-ui-commons/src/main/kotlin/org/utbot/intellij/plugin/util/IntelliJApiHelper.kt @@ -18,7 +18,7 @@ import org.jetbrains.kotlin.idea.util.application.invokeLater * This object is required to encapsulate Android API usage and grant safe access to it. */ object IntelliJApiHelper { - private val logger = KotlinLogging.logger {"org.utbot.IntelliJApiHelper"} + private val logger = KotlinLogging.logger {} enum class Target { THREAD_POOL, READ_ACTION, WRITE_ACTION, EDT_LATER } fun run(target: Target, indicator: ProgressIndicator? = null, logMessage : String, runnable: Runnable) {