Skip to content

Commit 50dc51b

Browse files
Dynamic invoke for string concatenation #386 (#1185)
1 parent ea14197 commit 50dc51b

File tree

29 files changed

+683
-252
lines changed

29 files changed

+683
-252
lines changed

.github/workflows/framework-tests-matrix.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
{
2828
"PART_NAME": "examples-part3",
29-
"TESTS_TO_RUN": "--tests \"org.utbot.examples.primitives.*\" --tests \"org.utbot.examples.recursion.*\" --tests \"org.utbot.examples.statics.substitution.*\" --tests \"org.utbot.examples.stdlib.*\" --tests \"org.utbot.examples.strings.*\" --tests \"org.utbot.examples.structures.*\" --tests \"org.utbot.examples.thirdparty.numbers.*\" --tests \"org.utbot.examples.types.*\" --tests \"org.utbot.examples.unsafe.*\" --tests \"org.utbot.examples.wrappers.*\""
29+
"TESTS_TO_RUN": "--tests \"org.utbot.examples.primitives.*\" --tests \"org.utbot.examples.recursion.*\" --tests \"org.utbot.examples.statics.substitution.*\" --tests \"org.utbot.examples.stdlib.*\" --tests \"org.utbot.examples.strings11.*\" --tests \"org.utbot.examples.strings.*\" --tests \"org.utbot.examples.structures.*\" --tests \"org.utbot.examples.thirdparty.numbers.*\" --tests \"org.utbot.examples.types.*\" --tests \"org.utbot.examples.unsafe.*\" --tests \"org.utbot.examples.wrappers.*\""
3030
},
3131
{
3232
"PART_NAME": "examples-lists",

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ allprojects {
4141
withType<KotlinCompile> {
4242
kotlinOptions {
4343
jvmTarget = "1.8"
44-
freeCompilerArgs = freeCompilerArgs + listOf("-Xallow-result-return-type", "-Xsam-conversions=class")
44+
freeCompilerArgs = freeCompilerArgs + listOf("-Xallow-result-return-type", "-Xsam-conversions=class", "-Xcontext-receivers")
4545
allWarningsAsErrors = false
4646
}
4747
}
4848
compileTestKotlin {
4949
kotlinOptions {
5050
jvmTarget = "1.8"
51-
freeCompilerArgs = freeCompilerArgs + listOf("-Xallow-result-return-type", "-Xsam-conversions=class")
51+
freeCompilerArgs = freeCompilerArgs + listOf("-Xallow-result-return-type", "-Xsam-conversions=class", "-Xcontext-receivers")
5252
allWarningsAsErrors = false
5353
}
5454
}

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

Lines changed: 63 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
package org.utbot.framework.plugin.api
1010

11+
import org.utbot.common.FileUtil
1112
import org.utbot.common.isDefaultValue
1213
import org.utbot.common.withToStringThreadLocalReentrancyGuard
1314
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
1616
import org.utbot.framework.plugin.api.util.booleanClassId
1717
import org.utbot.framework.plugin.api.util.byteClassId
1818
import org.utbot.framework.plugin.api.util.charClassId
@@ -24,7 +24,9 @@ import org.utbot.framework.plugin.api.util.id
2424
import org.utbot.framework.plugin.api.util.intClassId
2525
import org.utbot.framework.plugin.api.util.isArray
2626
import org.utbot.framework.plugin.api.util.isPrimitive
27+
import org.utbot.framework.plugin.api.util.isStatic
2728
import org.utbot.framework.plugin.api.util.jClass
29+
import org.utbot.framework.plugin.api.util.jField
2830
import org.utbot.framework.plugin.api.util.longClassId
2931
import org.utbot.framework.plugin.api.util.method
3032
import org.utbot.framework.plugin.api.util.primitiveTypeJvmNameOrNull
@@ -33,14 +35,24 @@ import org.utbot.framework.plugin.api.util.shortClassId
3335
import org.utbot.framework.plugin.api.util.supertypeOfAnonymousClass
3436
import org.utbot.framework.plugin.api.util.toReferenceTypeBytecodeSignature
3537
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
3751
import soot.jimple.JimpleBody
3852
import soot.jimple.Stmt
3953
import java.io.File
40-
import java.lang.reflect.Modifier
4154
import kotlin.contracts.ExperimentalContracts
4255
import kotlin.contracts.contract
43-
import org.utbot.common.FileUtil
4456

4557
const 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
*/
942940
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
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

1026997
sealed 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

11231095
class 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

11371110
open class TypeParameters(val parameters: List<ClassId> = emptyList())
11381111

11391112
class WildcardTypeParameter : TypeParameters(emptyList())
11401113

11411114
interface 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

11541127
enum 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

11811154
enum class TreatOverflowAsError(
1182-
override val id : String,
1155+
override val id: String,
11831156
override val displayName: String,
11841157
override val description: String,
11851158
) : CodeGenerationSettingItem {

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

Lines changed: 0 additions & 90 deletions
This file was deleted.

0 commit comments

Comments
 (0)