Skip to content

Commit f25dcc9

Browse files
Remove name generation logic from CgVariableConstructor (#1797)
1 parent c4c26f3 commit f25dcc9

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/services/framework/MockFrameworkManager.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ import org.utbot.framework.codegen.domain.models.CgSwitchCase
3737
import org.utbot.framework.codegen.domain.models.CgSwitchCaseLabel
3838
import org.utbot.framework.codegen.domain.models.CgValue
3939
import org.utbot.framework.codegen.domain.models.CgVariable
40+
import org.utbot.framework.codegen.services.CgNameGenerator
4041
import org.utbot.framework.codegen.services.access.CgCallableAccessManager
4142
import org.utbot.framework.codegen.services.access.CgCallableAccessManagerImpl
43+
import org.utbot.framework.codegen.tree.CgComponents.getNameGeneratorBy
4244
import org.utbot.framework.codegen.tree.CgComponents.getVariableConstructorBy
4345
import org.utbot.framework.codegen.tree.CgStatementConstructor
4446
import org.utbot.framework.codegen.tree.CgStatementConstructorImpl
@@ -72,6 +74,7 @@ abstract class CgVariableConstructorComponent(val context: CgContext) :
7274
CgCallableAccessManager by CgCallableAccessManagerImpl(context),
7375
CgStatementConstructor by CgStatementConstructorImpl(context) {
7476

77+
val nameGenerator: CgNameGenerator = getNameGeneratorBy(context)
7578
val variableConstructor: CgVariableConstructor by lazy { getVariableConstructorBy(context) }
7679

7780
fun mockitoArgumentMatchersFor(executable: ExecutableId): Array<CgMethodCall> =
@@ -220,7 +223,7 @@ private class MockitoStaticMocker(context: CgContext, private val mocker: Object
220223

221224
val mockClassCounter = CgDeclaration(
222225
atomicIntegerClassId,
223-
variableConstructor.constructVarName(MOCK_CLASS_COUNTER_NAME),
226+
nameGenerator.variableName(MOCK_CLASS_COUNTER_NAME),
224227
CgConstructorCall(ConstructorId(atomicIntegerClassId, emptyList()), emptyList())
225228
)
226229
+mockClassCounter
@@ -241,7 +244,7 @@ private class MockitoStaticMocker(context: CgContext, private val mocker: Object
241244
)
242245
val mockedConstructionDeclaration = CgDeclaration(
243246
MockitoStaticMocking.mockedConstructionClassId,
244-
variableConstructor.constructVarName(MOCKED_CONSTRUCTION_NAME),
247+
nameGenerator.variableName(MOCKED_CONSTRUCTION_NAME),
245248
mockConstructionInitializer
246249
)
247250
resources += mockedConstructionDeclaration
@@ -300,7 +303,7 @@ private class MockitoStaticMocker(context: CgContext, private val mocker: Object
300303
mockedStaticForMethods.getOrPut(classId) {
301304
val modelClass = getClassOf(classId)
302305
val classMockStaticCall = mockStatic(modelClass)
303-
val mockedStaticVariableName = variableConstructor.constructVarName(MOCKED_STATIC_NAME)
306+
val mockedStaticVariableName = nameGenerator.variableName(MOCKED_STATIC_NAME)
304307
CgDeclaration(
305308
MockitoStaticMocking.mockedStaticClassId,
306309
mockedStaticVariableName,
@@ -319,11 +322,11 @@ private class MockitoStaticMocker(context: CgContext, private val mocker: Object
319322
): CgMethodCall {
320323
val mockParameter = variableConstructor.declareParameter(
321324
classId,
322-
variableConstructor.constructVarName(classId.simpleName, isMock = true)
325+
nameGenerator.variableName(classId.simpleName, isMock = true)
323326
)
324327
val contextParameter = variableConstructor.declareParameter(
325328
mockedConstructionContextClassId,
326-
variableConstructor.constructVarName("context")
329+
nameGenerator.variableName("context")
327330
)
328331

329332
val caseLabels = mutableListOf<CgSwitchCaseLabel>()

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/tree/CgMethodConstructor.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
640640
val actualObject: CgVariable = when (codegenLanguage) {
641641
CodegenLanguage.KOTLIN -> newVar(
642642
baseType = objectClassId,
643-
baseName = variableConstructor.constructVarName("actualObject"),
643+
baseName = nameGenerator.variableName("actualObject"),
644644
init = { CgTypeCast(objectClassId, actual) }
645645
)
646646
else -> actual
@@ -793,7 +793,7 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
793793
): CgDeclaration {
794794
val cgGetLengthDeclaration = CgDeclaration(
795795
intClassId,
796-
variableConstructor.constructVarName("${expected.name}Size"),
796+
nameGenerator.variableName("${expected.name}Size"),
797797
expected.length(this@CgMethodConstructor)
798798
)
799799
currentBlock += cgGetLengthDeclaration
@@ -847,13 +847,13 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
847847
statements = block {
848848
val expectedNestedElement = newVar(
849849
baseType = expected.type.elementClassId!!,
850-
baseName = variableConstructor.constructVarName("${expected.name}NestedElement"),
850+
baseName = nameGenerator.variableName("${expected.name}NestedElement"),
851851
init = { CgArrayElementAccess(expected, i) }
852852
)
853853

854854
val actualNestedElement = newVar(
855855
baseType = actual.type.elementClassId!!,
856-
baseName = variableConstructor.constructVarName("${actual.name}NestedElement"),
856+
baseName = nameGenerator.variableName("${actual.name}NestedElement"),
857857
init = { CgArrayElementAccess(actual, i) }
858858
)
859859

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/tree/CgSimpleTestClassConstructor.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import org.utbot.framework.codegen.domain.models.CgTripleSlashMultilineComment
2222
import org.utbot.framework.codegen.domain.models.CgUtilEntity
2323
import org.utbot.framework.codegen.domain.models.CgUtilMethod
2424
import org.utbot.framework.codegen.domain.models.SimpleTestClassModel
25-
import org.utbot.framework.codegen.domain.models.TestClassModel
2625
import org.utbot.framework.codegen.renderer.importUtilMethodDependencies
2726
import org.utbot.framework.codegen.reports.TestsGenerationReport
2827
import org.utbot.framework.codegen.tree.CgComponents.clearContextRelatedStorage

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ import org.utbot.framework.plugin.api.util.wrapperByPrimitive
6868
/**
6969
* Constructs CgValue or CgVariable given a UtModel
7070
*/
71-
@Suppress("unused")
7271
open class CgVariableConstructor(val context: CgContext) :
7372
CgContextOwner by context,
7473
CgCallableAccessManager by getCallableAccessManagerBy(context),
@@ -204,7 +203,7 @@ open class CgVariableConstructor(val context: CgContext) :
204203
return obj
205204
}
206205

207-
fun constructAssemble(model: UtAssembleModel, baseName: String?): CgValue {
206+
private fun constructAssemble(model: UtAssembleModel, baseName: String?): CgValue {
208207
val instantiationCall = model.instantiationCall
209208
processInstantiationStatement(model, instantiationCall, baseName)
210209

@@ -391,11 +390,13 @@ open class CgVariableConstructor(val context: CgContext) :
391390
return array
392391
}
393392

394-
// TODO: cannot be used now but will be useful in case of storing stores in generated code
395393
/**
396394
* Splits sorted by indices pairs of index and value from stores to continuous by index chunks
397395
* [indexedValuesFromStores] have to be sorted by key
396+
*
397+
* Сan not be used now but will be useful in case of storing stores in generated code
398398
*/
399+
@Suppress("unused")
399400
private fun splitSettingFromStoresToForLoops(
400401
array: CgVariable,
401402
indexedValuesFromStores: List<MutableMap.MutableEntry<Int, UtModel>>
@@ -499,7 +500,6 @@ open class CgVariableConstructor(val context: CgContext) :
499500
/**
500501
* Create loop initializer expression
501502
*/
502-
@Suppress("SameParameterValue")
503503
internal fun loopInitialization(
504504
variableType: ClassId,
505505
baseVariableName: String,
@@ -537,9 +537,6 @@ open class CgVariableConstructor(val context: CgContext) :
537537
}
538538
}
539539

540-
internal fun constructVarName(baseName: String, isMock: Boolean = false): String =
541-
nameGenerator.variableName(baseName, isMock)
542-
543540
private fun String.toVarName(): String = nameGenerator.variableName(this)
544541

545542
}

0 commit comments

Comments
 (0)