Skip to content

Commit 37ea66e

Browse files
committed
Fix review comments
1 parent 94ee81a commit 37ea66e

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ val floatWrapperClassId = java.lang.Float::class.id
144144
val doubleWrapperClassId = java.lang.Double::class.id
145145

146146
val classClassId = java.lang.Class::class.id
147+
val fieldClassId = java.lang.reflect.Field::class.id
148+
val methodClassId = java.lang.reflect.Method::class.id
149+
val constructorClassId = java.lang.reflect.Constructor::class.id
147150

148151
// We consider void wrapper as primitive wrapper
149152
// because voidClassId is considered primitive here

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgVariableConstructor.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import org.utbot.framework.plugin.api.UtNullModel
4545
import org.utbot.framework.plugin.api.UtPrimitiveModel
4646
import org.utbot.framework.plugin.api.UtReferenceModel
4747
import org.utbot.framework.plugin.api.UtVoidModel
48+
import org.utbot.framework.plugin.api.util.classClassId
4849
import org.utbot.framework.plugin.api.util.defaultValueModel
4950
import org.utbot.framework.plugin.api.util.jField
5051
import org.utbot.framework.plugin.api.util.findFieldByIdOrNull
@@ -351,7 +352,7 @@ internal class CgVariableConstructor(val context: CgContext) :
351352
val init = if (classId.isAccessibleFrom(testClassPackageName)) {
352353
CgGetJavaClass(classId)
353354
} else {
354-
Class::class.id[forName](classId.name)
355+
classClassId[forName](classId.name)
355356
}
356357

357358
return newVar(Class::class.id, baseName) { init }

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/util/CgStatementConstructor.kt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ import org.utbot.framework.plugin.api.ClassId
5050
import org.utbot.framework.plugin.api.ExecutableId
5151
import org.utbot.framework.plugin.api.UtModel
5252
import org.utbot.framework.plugin.api.util.executable
53-
import org.utbot.framework.plugin.api.util.id
5453
import org.utbot.framework.plugin.api.util.isArray
5554
import org.utbot.framework.plugin.api.util.isNotSubtypeOf
5655
import org.utbot.framework.plugin.api.util.isSubtypeOf
@@ -67,7 +66,10 @@ import org.utbot.framework.plugin.api.ConstructorId
6766
import org.utbot.framework.plugin.api.FieldId
6867
import org.utbot.framework.plugin.api.MethodId
6968
import org.utbot.framework.plugin.api.util.classClassId
69+
import org.utbot.framework.plugin.api.util.constructorClassId
70+
import org.utbot.framework.plugin.api.util.fieldClassId
7071
import org.utbot.framework.plugin.api.util.isPrimitive
72+
import org.utbot.framework.plugin.api.util.methodClassId
7173
import java.lang.reflect.Constructor
7274
import java.lang.reflect.Method
7375
import kotlin.reflect.KFunction
@@ -306,15 +308,15 @@ internal class CgStatementConstructorImpl(context: CgContext) :
306308
}
307309

308310
override fun createFieldVariable(fieldId: FieldId): CgVariable {
309-
val declaringClass = newVar(Class::class.id) { Class::class.id[forName](fieldId.declaringClass.name) }
311+
val declaringClass = newVar(classClassId) { classClassId[forName](fieldId.declaringClass.name) }
310312
val name = fieldId.name + "Field"
311-
return newVar(java.lang.reflect.Field::class.id, name) {
313+
return newVar(fieldClassId, name) {
312314
declaringClass[getDeclaredField](fieldId.name)
313315
}
314316
}
315317

316318
override fun createExecutableVariable(executableId: ExecutableId, arguments: List<CgExpression>): CgVariable {
317-
val declaringClass = newVar(Class::class.id) { Class::class.id[forName](executableId.classId.name) }
319+
val declaringClass = newVar(classClassId) { classClassId[forName](executableId.classId.name) }
318320
val argTypes = (arguments zip executableId.parameters).map { (argument, parameterType) ->
319321
val baseName = when (argument) {
320322
is CgVariable -> "${argument.name}Type"
@@ -324,21 +326,21 @@ internal class CgStatementConstructorImpl(context: CgContext) :
324326
if (parameterType.isPrimitive) {
325327
CgGetJavaClass(parameterType)
326328
} else {
327-
Class::class.id[forName](parameterType.name)
329+
classClassId[forName](parameterType.name)
328330
}
329331
}
330332
}
331333

332334
return when (executableId) {
333335
is MethodId -> {
334336
val name = executableId.name + "Method"
335-
newVar(java.lang.reflect.Method::class.id, name) {
337+
newVar(methodClassId, name) {
336338
declaringClass[getDeclaredMethod](executableId.name, *argTypes.toTypedArray())
337339
}
338340
}
339341
is ConstructorId -> {
340342
val name = executableId.classId.prettifiedName.decapitalize() + "Constructor"
341-
newVar(java.lang.reflect.Constructor::class.id, name) {
343+
newVar(constructorClassId, name) {
342344
declaringClass[getDeclaredConstructor](*argTypes.toTypedArray())
343345
}
344346
}
@@ -467,9 +469,9 @@ internal class CgStatementConstructorImpl(context: CgContext) :
467469
// utils
468470

469471
private fun classRefOrNull(type: ClassId, expr: CgExpression): ClassId? {
470-
if (type == Class::class.id && expr is CgGetClass) return expr.classId
472+
if (type == classClassId && expr is CgGetClass) return expr.classId
471473

472-
if (type == Class::class.id && expr is CgExecutableCall && expr.executableId == forName) {
474+
if (type == classClassId && expr is CgExecutableCall && expr.executableId == forName) {
473475
val name = (expr.arguments.getOrNull(0) as? CgLiteral)?.value as? String
474476

475477
if (name != null) {
@@ -487,7 +489,7 @@ internal class CgStatementConstructorImpl(context: CgContext) :
487489
ExpressionWithType(enumClass, access)
488490
} else {
489491
val enumClassVariable = newVar(classCgClassId) {
490-
Class::class.id[forName](enumClass.name)
492+
classClassId[forName](enumClass.name)
491493
}
492494

493495
ExpressionWithType(objectClassId, utilsClassId[getEnumConstantByName](enumClassVariable, constant))

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/util/FieldIdUtil.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.utbot.framework.codegen.model.util
22

33
import org.utbot.framework.plugin.api.FieldId
4-
import org.utbot.framework.plugin.api.util.id
54

65
/**
76
* For now we will count field accessible if it is not private and its class is also accessible,
@@ -10,7 +9,7 @@ import org.utbot.framework.plugin.api.util.id
109
*
1110
* @param packageName name of the package we check accessibility from
1211
*/
13-
fun FieldId.isAccessibleFrom(packageName: String): Boolean {
12+
infix fun FieldId.isAccessibleFrom(packageName: String): Boolean {
1413
val isClassAccessible = declaringClass.isAccessibleFrom(packageName)
1514
val isAccessibleByVisibility = isPublic || (declaringClass.packageName == packageName && (isPackagePrivate || isProtected))
1615
val isAccessibleFromPackageByModifiers = isAccessibleByVisibility && !isSynthetic

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/visitor/UtilMethods.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import org.utbot.framework.plugin.api.ClassId
99
import org.utbot.framework.plugin.api.CodegenLanguage
1010
import org.utbot.framework.plugin.api.MethodId
1111
import org.utbot.framework.plugin.api.MockFramework
12+
import org.utbot.framework.plugin.api.util.fieldClassId
1213
import org.utbot.framework.plugin.api.util.id
13-
import java.lang.reflect.Field
1414
import java.lang.reflect.Modifier
1515
import java.util.Arrays
1616
import java.util.Objects
@@ -815,7 +815,6 @@ private fun TestClassUtilMethodProvider.regularImportsByUtilMethod(
815815
id: MethodId,
816816
codegenLanguage: CodegenLanguage
817817
): List<ClassId> {
818-
val fieldClassId = Field::class.id
819818
return when (id) {
820819
getUnsafeInstanceMethodId -> listOf(fieldClassId)
821820
createInstanceMethodId -> listOf(java.lang.reflect.InvocationTargetException::class.id)

0 commit comments

Comments
 (0)