88
99package org.utbot.framework.plugin.api
1010
11+ import org.utbot.common.FileUtil
1112import org.utbot.common.isDefaultValue
1213import org.utbot.common.withToStringThreadLocalReentrancyGuard
1314import org.utbot.framework.UtSettings
14- import org.utbot.framework.plugin.api.impl.FieldIdReflectionStrategy
15- import org.utbot.framework.plugin.api.impl.FieldIdSootStrategy
15+ import org.utbot.framework.plugin.api.util.ModifierFactory
1616import org.utbot.framework.plugin.api.util.booleanClassId
1717import org.utbot.framework.plugin.api.util.byteClassId
1818import org.utbot.framework.plugin.api.util.charClassId
@@ -24,7 +24,9 @@ import org.utbot.framework.plugin.api.util.id
2424import org.utbot.framework.plugin.api.util.intClassId
2525import org.utbot.framework.plugin.api.util.isArray
2626import org.utbot.framework.plugin.api.util.isPrimitive
27+ import org.utbot.framework.plugin.api.util.isStatic
2728import org.utbot.framework.plugin.api.util.jClass
29+ import org.utbot.framework.plugin.api.util.jField
2830import org.utbot.framework.plugin.api.util.longClassId
2931import org.utbot.framework.plugin.api.util.method
3032import org.utbot.framework.plugin.api.util.primitiveTypeJvmNameOrNull
@@ -33,14 +35,24 @@ import org.utbot.framework.plugin.api.util.shortClassId
3335import org.utbot.framework.plugin.api.util.supertypeOfAnonymousClass
3436import org.utbot.framework.plugin.api.util.toReferenceTypeBytecodeSignature
3537import org.utbot.framework.plugin.api.util.voidClassId
36- import soot.*
38+ import soot.ArrayType
39+ import soot.BooleanType
40+ import soot.ByteType
41+ import soot.CharType
42+ import soot.DoubleType
43+ import soot.FloatType
44+ import soot.IntType
45+ import soot.LongType
46+ import soot.RefType
47+ import soot.ShortType
48+ import soot.SootClass
49+ import soot.Type
50+ import soot.VoidType
3751import soot.jimple.JimpleBody
3852import soot.jimple.Stmt
3953import java.io.File
40- import java.lang.reflect.Modifier
4154import kotlin.contracts.ExperimentalContracts
4255import kotlin.contracts.contract
43- import org.utbot.common.FileUtil
4456
4557const val SYMBOLIC_NULL_ADDR : Int = 0
4658
@@ -730,6 +742,8 @@ open class ClassId @JvmOverloads constructor(
730742 // Treat simple class ids as non-nullable
731743 open val isNullable : Boolean = false
732744) {
745+ open val modifiers: Int
746+ get() = jClass.modifiers
733747
734748 open val canonicalName: String
735749 get() = jClass.canonicalName ? : error(" ClassId $name does not have canonical name" )
@@ -764,27 +778,6 @@ open class ClassId @JvmOverloads constructor(
764778 open val isInDefaultPackage: Boolean
765779 get() = packageName.isEmpty()
766780
767- open val isPublic: Boolean
768- get() = Modifier .isPublic(jClass.modifiers)
769-
770- open val isProtected: Boolean
771- get() = Modifier .isProtected(jClass.modifiers)
772-
773- open val isPrivate: Boolean
774- get() = Modifier .isPrivate(jClass.modifiers)
775-
776- val isPackagePrivate: Boolean
777- get() = ! (isPublic || isProtected || isPrivate)
778-
779- open val isFinal: Boolean
780- get() = Modifier .isFinal(jClass.modifiers)
781-
782- open val isStatic: Boolean
783- get() = Modifier .isStatic(jClass.modifiers)
784-
785- open val isAbstract: Boolean
786- get() = Modifier .isAbstract(jClass.modifiers)
787-
788781 open val isAnonymous: Boolean
789782 get() = jClass.isAnonymousClass
790783
@@ -883,12 +876,12 @@ class BuiltinClassId(
883876 // by default, we assume that the class is not a member class
884877 override val simpleNameWithEnclosings : String = simpleName,
885878 override val isNullable : Boolean = false ,
886- override val isPublic : Boolean = true ,
887- override val isProtected : Boolean = false ,
888- override val isPrivate : Boolean = false ,
889- override val isFinal : Boolean = false ,
890- override val isStatic : Boolean = false ,
891- override val isAbstract : Boolean = false ,
879+ isPublic : Boolean = true ,
880+ isProtected : Boolean = false ,
881+ isPrivate : Boolean = false ,
882+ isFinal : Boolean = false ,
883+ isStatic : Boolean = false ,
884+ isAbstract : Boolean = false ,
892885 override val isAnonymous : Boolean = false ,
893886 override val isLocal : Boolean = false ,
894887 override val isInner : Boolean = false ,
@@ -912,6 +905,15 @@ class BuiltinClassId(
912905 elementClassId = elementClassId,
913906 isNullable = isNullable,
914907) {
908+ override val modifiers: Int = ModifierFactory {
909+ public = isPublic
910+ protected = isProtected
911+ private = isPrivate
912+ final = isFinal
913+ static = isStatic
914+ abstract = isAbstract
915+ }
916+
915917 init {
916918 BUILTIN_CLASSES_BY_NAMES [name] = this
917919 }
@@ -929,49 +931,21 @@ class BuiltinClassId(
929931 fun getBuiltinClassByNameOrNull (name : String ): BuiltinClassId ? = BUILTIN_CLASSES_BY_NAMES [name]
930932 }
931933}
932- enum class FieldIdStrategyValues {
933- Reflection ,
934- Soot
935- }
936934
937935/* *
938936 * Field id. Contains field name.
939937 *
940938 * Created to avoid usage String objects as a key.
941939 */
942940open class FieldId (val declaringClass : ClassId , val name : String ) {
943-
944- object Strategy {
945- var value: FieldIdStrategyValues = FieldIdStrategyValues .Soot
946- }
947-
948- private val strategy
949- get() = if (Strategy .value == FieldIdStrategyValues .Soot )
950- FieldIdSootStrategy (declaringClass, this ) else FieldIdReflectionStrategy (this )
951-
952- open val isPublic: Boolean
953- get() = strategy.isPublic
954-
955- open val isProtected: Boolean
956- get() = strategy.isProtected
957-
958- open val isPrivate: Boolean
959- get() = strategy.isPrivate
960-
961- open val isPackagePrivate: Boolean
962- get() = strategy.isPackagePrivate
963-
964- open val isFinal: Boolean
965- get() = strategy.isFinal
966-
967- open val isStatic: Boolean
968- get() = strategy.isStatic
941+ open val modifiers: Int
942+ get() = jField.modifiers
969943
970944 open val isSynthetic: Boolean
971- get() = strategy .isSynthetic
945+ get() = jField .isSynthetic
972946
973947 open val type: ClassId
974- get() = strategy .type
948+ get() = jField .type.id
975949
976950 override fun equals (other : Any? ): Boolean {
977951 if (this == = other) return true
@@ -994,16 +968,6 @@ open class FieldId(val declaringClass: ClassId, val name: String) {
994968 override fun toString () = safeJField?.toString() ? : " [unresolved] $declaringClass .$name "
995969}
996970
997- inline fun <T > withReflection (block : () -> T ): T {
998- val prevStrategy = FieldId .Strategy .value
999- try {
1000- FieldId .Strategy .value = FieldIdStrategyValues .Reflection
1001- return block()
1002- } finally {
1003- FieldId .Strategy .value = prevStrategy
1004- }
1005- }
1006-
1007971/* *
1008972 * The same as [FieldId], except it represents the fields
1009973 * of classes that may not be present on the classpath.
@@ -1017,11 +981,18 @@ class BuiltinFieldId(
1017981 name : String ,
1018982 override val type : ClassId ,
1019983 // by default we assume that the builtin field is public and non-final
1020- override val isPublic : Boolean = true ,
1021- override val isPrivate : Boolean = false ,
1022- override val isFinal : Boolean = false ,
984+ isPublic : Boolean = true ,
985+ isPrivate : Boolean = false ,
986+ isFinal : Boolean = false ,
1023987 override val isSynthetic : Boolean = false ,
1024- ) : FieldId(declaringClass, name)
988+ ) : FieldId(declaringClass, name) {
989+ override val modifiers = ModifierFactory {
990+ public = isPublic
991+ private = isPrivate
992+ final = isFinal
993+ }
994+
995+ }
1025996
1026997sealed class StatementId {
1027998 abstract val classId: ClassId
@@ -1113,11 +1084,12 @@ class BuiltinMethodId(
11131084 isProtected : Boolean = false ,
11141085 isPrivate : Boolean = false
11151086) : MethodId(classId, name, returnType, parameters) {
1116- override val modifiers: Int =
1117- (if (isStatic) Modifier .STATIC else 0 ) or
1118- (if (isPublic) Modifier .PUBLIC else 0 ) or
1119- (if (isProtected) Modifier .PROTECTED else 0 ) or
1120- (if (isPrivate) Modifier .PRIVATE else 0 )
1087+ override val modifiers: Int = ModifierFactory {
1088+ static = isStatic
1089+ public = isPublic
1090+ private = isPrivate
1091+ protected = isProtected
1092+ }
11211093}
11221094
11231095class BuiltinConstructorId (
@@ -1128,18 +1100,19 @@ class BuiltinConstructorId(
11281100 isProtected : Boolean = false ,
11291101 isPrivate : Boolean = false
11301102) : ConstructorId(classId, parameters) {
1131- override val modifiers: Int =
1132- (if (isPublic) Modifier .PUBLIC else 0 ) or
1133- (if (isProtected) Modifier .PROTECTED else 0 ) or
1134- (if (isPrivate) Modifier .PRIVATE else 0 )
1103+ override val modifiers: Int = ModifierFactory {
1104+ public = isPublic
1105+ private = isPrivate
1106+ protected = isProtected
1107+ }
11351108}
11361109
11371110open class TypeParameters (val parameters : List <ClassId > = emptyList())
11381111
11391112class WildcardTypeParameter : TypeParameters (emptyList())
11401113
11411114interface CodeGenerationSettingItem {
1142- val id : String
1115+ val id: String
11431116 val displayName: String
11441117 val description: String
11451118}
@@ -1152,7 +1125,7 @@ interface CodeGenerationSettingBox {
11521125}
11531126
11541127enum class MockStrategyApi (
1155- override val id : String ,
1128+ override val id : String ,
11561129 override val displayName : String ,
11571130 override val description : String
11581131) : CodeGenerationSettingItem {
@@ -1179,7 +1152,7 @@ enum class MockStrategyApi(
11791152}
11801153
11811154enum class TreatOverflowAsError (
1182- override val id : String ,
1155+ override val id : String ,
11831156 override val displayName : String ,
11841157 override val description : String ,
11851158) : CodeGenerationSettingItem {
0 commit comments