Skip to content

Construct assemble models for classes with val-properties in constructor #1190 #1240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -254,25 +254,27 @@ class AssembleModelGenerator(private val basePackageName: String) {
instantiatedModels[compositeModel] = this

compositeModel.fields.forEach { (fieldId, fieldModel) ->
//if field value has been filled by constructor or it is default, we suppose that it is already properly initialized
if ((fieldId in constructorInfo.setFields || fieldModel.hasDefaultValue()) && fieldId !in constructorInfo.affectedFields)
return@forEach

if (fieldId.isStatic) {
throw AssembleException("Static field $fieldId can't be set in an object of the class $classId")
}
if (fieldId.isFinal) {
throw AssembleException("Final field $fieldId can't be set in an object of the class $classId")
}

if (!fieldId.type.isAccessibleFrom(basePackageName)) {
throw AssembleException(
"Field $fieldId can't be set in an object of the class $classId because its type is inaccessible"
)
}
//fill field value if it hasn't been filled by constructor, and it is not default
if (fieldId in constructorInfo.affectedFields ||
(fieldId !in constructorInfo.setFields && !fieldModel.hasDefaultValue())
) {
val assembledModel = assembleModel(fieldModel)
val modifierCall = modifierCall(this, fieldId, assembledModel)
callChain.add(modifierCall)

if (fieldId.isFinal) {
throw AssembleException("Final field $fieldId can't be set in an object of the class $classId")
}

val assembledModel = assembleModel(fieldModel)
val modifierCall = modifierCall(this, fieldId, assembledModel)
callChain.add(modifierCall)
}

callChain.toList()
Expand Down