Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Additional work
  • Loading branch information
EgorkaKulikov committed Jul 20, 2022
commit 08928ee98c794c4d52a40a83955c123056f24397
Original file line number Diff line number Diff line change
Expand Up @@ -685,10 +685,6 @@ open class ClassId(
open val isSynthetic: Boolean
get() = jClass.isSynthetic

// open val isNullable: Boolean
// // Treat simple class ids as non-nullable
// get() = false

/**
* Collects all declared methods (including private and protected) from class and all its superclasses to sequence
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,21 @@ val idToPrimitive: Map<ClassId, Class<*>> = mapOf(
*/
fun isPrimitiveWrapperOrString(type: ClassId): Boolean = (type in primitiveWrappers) || (type == stringClassId)

/**
* Returns a wrapper of a given type if it is primitive or a type itself otherwise.
*/
fun wrapIfPrimitive(type: ClassId): ClassId = when (type) {
booleanClassId -> booleanWrapperClassId
byteClassId -> byteWrapperClassId
charClassId -> charWrapperClassId
shortClassId -> shortWrapperClassId
intClassId -> intWrapperClassId
longClassId -> longWrapperClassId
floatClassId -> floatWrapperClassId
doubleClassId -> doubleWrapperClassId
else -> type
}

/**
* Note: currently uses class$innerClass form to load classes with classloader.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.utbot.framework.assemble

import org.utbot.framework.plugin.api.UtAssembleModel
import org.utbot.framework.plugin.api.UtExecutableCallModel
import org.utbot.framework.plugin.api.UtPrimitiveModel
import org.utbot.framework.plugin.api.util.booleanClassId
import org.utbot.framework.plugin.api.util.charClassId
import org.utbot.framework.plugin.api.util.doubleClassId
import org.utbot.framework.plugin.api.util.executableId
import org.utbot.framework.plugin.api.util.floatClassId
import org.utbot.framework.plugin.api.util.intClassId
import org.utbot.framework.plugin.api.util.longClassId
import org.utbot.framework.plugin.api.util.shortClassId
import org.utbot.framework.plugin.api.util.wrapIfPrimitive

/**
* Creates [UtAssembleModel] of the wrapper for a given [UtPrimitiveModel].
*/
fun assemble(model: UtPrimitiveModel): UtAssembleModel {
val modelType = model.classId
val assembledModelType = wrapIfPrimitive(modelType)

val constructorCall = when (modelType) {
shortClassId -> java.lang.Short::class.java.getConstructor(Short::class.java)
Comment thread
EgorkaKulikov marked this conversation as resolved.
intClassId -> java.lang.Integer::class.java.getConstructor(Int::class.java)
longClassId -> java.lang.Long::class.java.getConstructor(Long::class.java)
charClassId -> java.lang.Character::class.java.getConstructor(Char::class.java)
booleanClassId -> java.lang.Boolean::class.java.getConstructor(Boolean::class.java)
floatClassId -> java.lang.Float::class.java.getConstructor(Float::class.java)
doubleClassId -> java.lang.Double::class.java.getConstructor(Double::class.java)
else -> error("Model type $modelType is void or non-primitive")
}

val constructorCallModel = UtExecutableCallModel(
instance = null,
executable = constructorCall.executableId,
params = listOf(model),
returnValue = null,
)

return UtAssembleModel(
id = null,
classId = assembledModelType,
modelName = modelType.canonicalName,
instantiationChain = listOf(constructorCallModel),
modificationsChain = emptyList(),
)
}
Loading