Skip to content

Commit c325091

Browse files
committed
Refactoring
1 parent 051966b commit c325091

File tree

13 files changed

+70
-46
lines changed

13 files changed

+70
-46
lines changed

utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,10 +1436,10 @@ class SpringApplicationContext(
14361436
private val springInjectedClasses: Set<ClassId>
14371437
get() {
14381438
if (!areInjectedClassesInitialized) {
1439-
// TODO: use more info from SpringBeanDefinitionData than beanTypeFqn offers here
1440-
for (beanFqn in beanDefinitions.map { it.beanTypeFqn }) {
1439+
// TODO: use more info from SpringBeanDefinitionData than beanTypeName offers here
1440+
for (beanTypeName in beanDefinitions.map { it.beanTypeName }) {
14411441
try {
1442-
val beanClass = utContext.classLoader.loadClass(beanFqn)
1442+
val beanClass = utContext.classLoader.loadClass(beanTypeName)
14431443
if (!beanClass.isAbstract && !beanClass.isInterface &&
14441444
!beanClass.isLocalClass && (!beanClass.isMemberClass || beanClass.isStatic)) {
14451445
springInjectedClassesStorage += beanClass.id
@@ -1449,7 +1449,7 @@ class SpringApplicationContext(
14491449
// it is possible to have problems with classes loading.
14501450
when (e) {
14511451
is ClassNotFoundException, is NoClassDefFoundError, is IllegalAccessError ->
1452-
logger.warn { "Failed to load bean class for $beanFqn (${e.message})" }
1452+
logger.warn { "Failed to load bean class for $beanTypeName (${e.message})" }
14531453

14541454
else -> throw e
14551455
}
@@ -1530,10 +1530,12 @@ enum class SpringTestsType(
15301530
* Describes information about beans obtained from Spring analysis process.
15311531
*
15321532
* Contains the name of the bean, its type (class or interface) and optional additional data.
1533+
*
1534+
* @param beanTypeName a name in a form obtained by [java.lang.Class.getName] method.
15331535
*/
15341536
data class BeanDefinitionData(
15351537
val beanName: String,
1536-
val beanTypeFqn: String,
1538+
val beanTypeName: String,
15371539
val additionalData: BeanAdditionalData?,
15381540
)
15391541

@@ -1542,11 +1544,13 @@ data class BeanDefinitionData(
15421544
*
15431545
* Sometimes the actual type of the bean can not be obtained from bean definition.
15441546
* Then we try to recover it by method and class defining bean (e.g. using Psi elements).
1547+
*
1548+
* @param configClassName a name in a form obtained by [java.lang.Class.getName] method.
15451549
*/
15461550
data class BeanAdditionalData(
15471551
val factoryMethodName: String,
15481552
val parameterTypes: List<String>,
1549-
val configClassFqn: String,
1553+
val configClassName: String,
15501554
)
15511555

15521556
val RefType.isAbstractType

utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ class UtBotSymbolicEngine(
412412
defaultIdGenerator,
413413
beanNameProvider = { classId ->
414414
(applicationContext as SpringApplicationContext).beanDefinitions
415-
.filter { it.beanTypeFqn == classId.name }
415+
.filter { it.beanTypeName == classId.name }
416416
.map { it.beanName }
417417
},
418418
relevantRepositories = relevantRepositories

utbot-framework/src/main/kotlin/org/utbot/framework/process/EngineProcessMain.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ private fun EngineProcessModel.setup(kryoHelper: KryoHelper, watchdog: IdleWatch
160160
RenderResult(it.generatedCode, it.utilClassKind?.javaClass?.simpleName)
161161
}
162162
}
163-
watchdog.measureTimeForActiveCall(obtainClassId, "Obtain class id in UtContext") { canonicalName ->
164-
kryoHelper.writeObject(UtContext.currentContext()!!.classLoader.loadClass(canonicalName).id)
163+
watchdog.measureTimeForActiveCall(obtainClassId, "Obtain class id in UtContext") { binaryName ->
164+
kryoHelper.writeObject(UtContext.currentContext()!!.classLoader.loadClass(binaryName).id)
165165
}
166166
watchdog.measureTimeForActiveCall(findMethodsInClassMatchingSelected, "Find methods in Class") { params ->
167167
val classId = kryoHelper.readObject<ClassId>(params.classId)

utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/EngineProcessModel.Generated.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class EngineProcessModel private constructor(
7575
}
7676

7777

78-
const val serializationHash = 4955072258757490759L
78+
const val serializationHash = -7418312653824196007L
7979

8080
}
8181
override val serializersOwner: ISerializersOwner get() = EngineProcessModel
@@ -187,7 +187,7 @@ val IProtocol.engineProcessModel get() = getOrCreateExtension(EngineProcessModel
187187
data class BeanAdditionalData (
188188
val factoryMethodName: String,
189189
val parameterTypes: List<String>,
190-
val configClassFqn: String
190+
val configClassName: String
191191
) : IPrintable {
192192
//companion
193193

@@ -198,14 +198,14 @@ data class BeanAdditionalData (
198198
override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): BeanAdditionalData {
199199
val factoryMethodName = buffer.readString()
200200
val parameterTypes = buffer.readList { buffer.readString() }
201-
val configClassFqn = buffer.readString()
202-
return BeanAdditionalData(factoryMethodName, parameterTypes, configClassFqn)
201+
val configClassName = buffer.readString()
202+
return BeanAdditionalData(factoryMethodName, parameterTypes, configClassName)
203203
}
204204

205205
override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: BeanAdditionalData) {
206206
buffer.writeString(value.factoryMethodName)
207207
buffer.writeList(value.parameterTypes) { v -> buffer.writeString(v) }
208-
buffer.writeString(value.configClassFqn)
208+
buffer.writeString(value.configClassName)
209209
}
210210

211211

@@ -223,7 +223,7 @@ data class BeanAdditionalData (
223223

224224
if (factoryMethodName != other.factoryMethodName) return false
225225
if (parameterTypes != other.parameterTypes) return false
226-
if (configClassFqn != other.configClassFqn) return false
226+
if (configClassName != other.configClassName) return false
227227

228228
return true
229229
}
@@ -232,7 +232,7 @@ data class BeanAdditionalData (
232232
var __r = 0
233233
__r = __r*31 + factoryMethodName.hashCode()
234234
__r = __r*31 + parameterTypes.hashCode()
235-
__r = __r*31 + configClassFqn.hashCode()
235+
__r = __r*31 + configClassName.hashCode()
236236
return __r
237237
}
238238
//pretty print
@@ -241,7 +241,7 @@ data class BeanAdditionalData (
241241
printer.indent {
242242
print("factoryMethodName = "); factoryMethodName.print(printer); println()
243243
print("parameterTypes = "); parameterTypes.print(printer); println()
244-
print("configClassFqn = "); configClassFqn.print(printer); println()
244+
print("configClassName = "); configClassName.print(printer); println()
245245
}
246246
printer.print(")")
247247
}

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/SpringUtExecutionInstrumentation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class SpringUtExecutionInstrumentation(
8787

8888
private fun getRelevantBeanNames(clazz: Class<*>): Set<String> = relatedBeansCache.getOrPut(clazz) {
8989
beanDefinitions
90-
.filter { it.beanTypeFqn == clazz.name }
90+
.filter { it.beanTypeName == clazz.name }
9191
.flatMap { springContext.getDependenciesForBean(it.beanName, userSourcesClassLoader) }
9292
.toSet()
9393
.also { logger.info { "Detected relevant beans for class ${clazz.name}: $it" } }

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/rd/generated/InstrumentedProcessModel.Generated.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class InstrumentedProcessModel private constructor(
113113
val getSpringBean: RdCall<GetSpringBeanParams, GetSpringBeanResult> get() = _getSpringBean
114114

115115
/**
116-
* Get Spring repositories by bean names (requires Spring instrumentation)
116+
* Gets a list of [SpringRepositoryId]s that class specified by the [ClassId] (possibly indirectly) depends on (requires Spring instrumentation)
117117
*/
118118
val getRelevantSpringRepositories: RdCall<GetSpringRepositoriesParams, GetSpringRepositoriesResult> get() = _getRelevantSpringRepositories
119119
//methods

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,11 @@ object UtTestsDialogProcessor {
178178
DoNotReplace -> null
179179
is ReplaceIfPossible ->
180180
approach.config.takeUnless { it.endsWith(".xml") }?.let {
181-
// Converting binary name to canonical name
182-
val canonicalName = it.replace("$", ".")
183-
PsiClassHelper.findClass(canonicalName, project) ?: error("Cannot find configuration class $it.")
181+
// Converting binary name to fqn name
182+
val fqnName = it.replace("$", ".")
183+
PsiClassHelper
184+
.findClass(fqnName, project)
185+
?: error("Cannot find configuration class $it with $fqnName name.")
184186
}
185187
}
186188

@@ -478,13 +480,15 @@ object UtTestsDialogProcessor {
478480
val beanType = runReadAction {
479481
val additionalData = bean.additionalData ?: return@runReadAction null
480482

481-
// Converting binary name to canonical name
482-
val canonicalName = additionalData.configClassFqn.replace("$", ".")
483+
// Converting binary name to fqn name
484+
val fqnName = additionalData.configClassName.replace("$", ".")
483485
val configPsiClass =
484-
PsiClassHelper.findClass(canonicalName, project) ?: return@runReadAction null
485-
.also {
486-
logger.warn("Cannot find configuration class ${additionalData.configClassFqn}.")
487-
}
486+
PsiClassHelper
487+
.findClass(fqnName, project)
488+
?: return@runReadAction null
489+
.also {
490+
logger.warn("Cannot find configuration class ${additionalData.configClassName} with $fqnName name.")
491+
}
488492

489493
val beanPsiMethod =
490494
configPsiClass
@@ -504,7 +508,7 @@ object UtTestsDialogProcessor {
504508
.also {
505509
logger.warn(
506510
"Several similar methods named ${bean.beanName} " +
507-
"were found in ${additionalData.configClassFqn} configuration class."
511+
"were found in ${additionalData.configClassName} configuration class."
508512
)
509513
}
510514

@@ -513,12 +517,12 @@ object UtTestsDialogProcessor {
513517
.findReturnStatements(beanPsiMethod)
514518
.mapNotNullTo(mutableSetOf()) { stmt -> stmt.returnValue?.type?.canonicalText }
515519

516-
beanTypes.singleOrNull() ?: bean.beanTypeFqn
520+
beanTypes.singleOrNull() ?: bean.beanTypeName
517521
} ?: return@map bean
518522

519523
BeanDefinitionData(
520524
beanName = bean.beanName,
521-
beanTypeFqn = beanType,
525+
beanTypeName = beanType,
522526
additionalData = bean.additionalData
523527
)
524528
}

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/process/EngineProcess.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,15 @@ class EngineProcess private constructor(val project: Project, private val classN
158158
.map { data ->
159159
BeanDefinitionData(
160160
beanName = data.beanName,
161-
beanTypeFqn = data.beanTypeFqn,
161+
beanTypeName = data.beanTypeFqn,
162162
additionalData = data.additionalData
163-
?.let { BeanAdditionalData(it.factoryMethodName, it.parameterTypes, it.configClassFqn) }
163+
?.let {
164+
BeanAdditionalData(
165+
it.factoryMethodName,
166+
it.parameterTypes,
167+
it.configClassName
168+
)
169+
}
164170
)
165171
}
166172
}

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/util/SpringConfigurationsHelper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class SpringConfigurationsHelper(val configType: SpringConfigurationType) {
4242
.values
4343
.singleOrNull { it.shortenedName == shortenedName }
4444
?.fullName
45-
?: error("Full name of configuration file cannot be restored by shortened name $shortenedName")
45+
?: error("Full name of configuration file cannot be restored with shortened name $shortenedName")
4646

4747
fun shortenSpringConfigNames(fullNames: Set<String>): Map<String, String> {
4848
fullNames.forEach { nameToInfo[it] = NameInfo(it) }

utbot-rd/src/main/rdgen/org/utbot/rd/models/EngineProcessModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ object EngineProcessModel : Ext(EngineProcessRoot) {
134134
val beanAdditionalData = structdef {
135135
field("factoryMethodName", PredefinedType.string)
136136
field("parameterTypes", immutableList(PredefinedType.string))
137-
field("configClassFqn", PredefinedType.string)
137+
field("configClassName", PredefinedType.string)
138138
}
139139
val beanDefinitionData = structdef {
140140
field("beanName", PredefinedType.string)

0 commit comments

Comments
 (0)