8
8
9
9
package org.utbot.framework.plugin.api
10
10
11
+ import org.utbot.common.FileUtil
11
12
import org.utbot.common.isDefaultValue
12
13
import org.utbot.common.withToStringThreadLocalReentrancyGuard
13
14
import 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
16
16
import org.utbot.framework.plugin.api.util.booleanClassId
17
17
import org.utbot.framework.plugin.api.util.byteClassId
18
18
import org.utbot.framework.plugin.api.util.charClassId
@@ -24,7 +24,9 @@ import org.utbot.framework.plugin.api.util.id
24
24
import org.utbot.framework.plugin.api.util.intClassId
25
25
import org.utbot.framework.plugin.api.util.isArray
26
26
import org.utbot.framework.plugin.api.util.isPrimitive
27
+ import org.utbot.framework.plugin.api.util.isStatic
27
28
import org.utbot.framework.plugin.api.util.jClass
29
+ import org.utbot.framework.plugin.api.util.jField
28
30
import org.utbot.framework.plugin.api.util.longClassId
29
31
import org.utbot.framework.plugin.api.util.method
30
32
import org.utbot.framework.plugin.api.util.primitiveTypeJvmNameOrNull
@@ -33,14 +35,24 @@ import org.utbot.framework.plugin.api.util.shortClassId
33
35
import org.utbot.framework.plugin.api.util.supertypeOfAnonymousClass
34
36
import org.utbot.framework.plugin.api.util.toReferenceTypeBytecodeSignature
35
37
import 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
37
51
import soot.jimple.JimpleBody
38
52
import soot.jimple.Stmt
39
53
import java.io.File
40
- import java.lang.reflect.Modifier
41
54
import kotlin.contracts.ExperimentalContracts
42
55
import kotlin.contracts.contract
43
- import org.utbot.common.FileUtil
44
56
45
57
const val SYMBOLIC_NULL_ADDR : Int = 0
46
58
@@ -730,6 +742,8 @@ open class ClassId @JvmOverloads constructor(
730
742
// Treat simple class ids as non-nullable
731
743
open val isNullable : Boolean = false
732
744
) {
745
+ open val modifiers: Int
746
+ get() = jClass.modifiers
733
747
734
748
open val canonicalName: String
735
749
get() = jClass.canonicalName ? : error(" ClassId $name does not have canonical name" )
@@ -764,27 +778,6 @@ open class ClassId @JvmOverloads constructor(
764
778
open val isInDefaultPackage: Boolean
765
779
get() = packageName.isEmpty()
766
780
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
-
788
781
open val isAnonymous: Boolean
789
782
get() = jClass.isAnonymousClass
790
783
@@ -883,12 +876,12 @@ class BuiltinClassId(
883
876
// by default, we assume that the class is not a member class
884
877
override val simpleNameWithEnclosings : String = simpleName,
885
878
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 ,
892
885
override val isAnonymous : Boolean = false ,
893
886
override val isLocal : Boolean = false ,
894
887
override val isInner : Boolean = false ,
@@ -912,6 +905,15 @@ class BuiltinClassId(
912
905
elementClassId = elementClassId,
913
906
isNullable = isNullable,
914
907
) {
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
+
915
917
init {
916
918
BUILTIN_CLASSES_BY_NAMES [name] = this
917
919
}
@@ -929,49 +931,21 @@ class BuiltinClassId(
929
931
fun getBuiltinClassByNameOrNull (name : String ): BuiltinClassId ? = BUILTIN_CLASSES_BY_NAMES [name]
930
932
}
931
933
}
932
- enum class FieldIdStrategyValues {
933
- Reflection ,
934
- Soot
935
- }
936
934
937
935
/* *
938
936
* Field id. Contains field name.
939
937
*
940
938
* Created to avoid usage String objects as a key.
941
939
*/
942
940
open 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
969
943
970
944
open val isSynthetic: Boolean
971
- get() = strategy .isSynthetic
945
+ get() = jField .isSynthetic
972
946
973
947
open val type: ClassId
974
- get() = strategy .type
948
+ get() = jField .type.id
975
949
976
950
override fun equals (other : Any? ): Boolean {
977
951
if (this == = other) return true
@@ -994,16 +968,6 @@ open class FieldId(val declaringClass: ClassId, val name: String) {
994
968
override fun toString () = safeJField?.toString() ? : " [unresolved] $declaringClass .$name "
995
969
}
996
970
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
-
1007
971
/* *
1008
972
* The same as [FieldId], except it represents the fields
1009
973
* of classes that may not be present on the classpath.
@@ -1017,11 +981,18 @@ class BuiltinFieldId(
1017
981
name : String ,
1018
982
override val type : ClassId ,
1019
983
// 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 ,
1023
987
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
+ }
1025
996
1026
997
sealed class StatementId {
1027
998
abstract val classId: ClassId
@@ -1113,11 +1084,12 @@ class BuiltinMethodId(
1113
1084
isProtected : Boolean = false ,
1114
1085
isPrivate : Boolean = false
1115
1086
) : 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
+ }
1121
1093
}
1122
1094
1123
1095
class BuiltinConstructorId (
@@ -1128,18 +1100,19 @@ class BuiltinConstructorId(
1128
1100
isProtected : Boolean = false ,
1129
1101
isPrivate : Boolean = false
1130
1102
) : 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
+ }
1135
1108
}
1136
1109
1137
1110
open class TypeParameters (val parameters : List <ClassId > = emptyList())
1138
1111
1139
1112
class WildcardTypeParameter : TypeParameters (emptyList())
1140
1113
1141
1114
interface CodeGenerationSettingItem {
1142
- val id : String
1115
+ val id: String
1143
1116
val displayName: String
1144
1117
val description: String
1145
1118
}
@@ -1152,7 +1125,7 @@ interface CodeGenerationSettingBox {
1152
1125
}
1153
1126
1154
1127
enum class MockStrategyApi (
1155
- override val id : String ,
1128
+ override val id : String ,
1156
1129
override val displayName : String ,
1157
1130
override val description : String
1158
1131
) : CodeGenerationSettingItem {
@@ -1179,7 +1152,7 @@ enum class MockStrategyApi(
1179
1152
}
1180
1153
1181
1154
enum class TreatOverflowAsError (
1182
- override val id : String ,
1155
+ override val id : String ,
1183
1156
override val displayName : String ,
1184
1157
override val description : String ,
1185
1158
) : CodeGenerationSettingItem {
0 commit comments