Coverage Summary for Class: KClassCreatorKt (com.kotlinorm.utils)

Class Method, % Branch, % Line, % Instruction, %
KClassCreatorKt 75% (3/4) 50% (2/4) 60% (3/5) 65.9% (27/41)
KClassCreatorKt$kClassCreator$1 0% (0/1) 0% (0/1) 0% (0/1)
KClassCreatorKt$kClassCreatorCustom$1 100% (1/1) 100% (1/1) 100% (1/1)
Total 66.7% (4/6) 50% (2/4) 57.1% (4/7) 65.1% (28/43)


 /**
  * Copyright 2022-2025 kronos-orm
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package com.kotlinorm.utils
 
 import com.kotlinorm.interfaces.KPojo
 import kotlin.reflect.KClass
 
 /**
  * kClassCreator
  *
  * Transform the KClass into a KPojo instance
  *
  * **the body of this function will be generated by the compiler plugin**
  * @return KPojo instance
  */
 var kClassCreator: (KClass<out KPojo>) -> KPojo? = { null }
 
 /**
  * kClassCreatorCustom
  *
  * Transform the KClass into a KPojo instance, custom instantiation method
  *
  * @return KPojo instance
  */
 var kClassCreatorCustom: (KClass<out KPojo>) -> KPojo? = { null }
 
 fun registerKPojo(vararg kClass: KClass<out KPojo>) {}
 
 @Suppress("UNCHECKED_CAST")
 fun <T : KPojo> KClass<T>.createInstance(): T {
     return kClassCreatorCustom(this) as T? ?: kClassCreator(this) as T? ?: throw NullPointerException(
         "KClass ${this.simpleName} instantiation failed \n" +
                 "1.Please check if the data class has a no-argument constructor. \n" +
                 "2.if you did not add `Kronos.init{}` to your code, please add it  to the code, " +
                 "this is a necessary step to use the ORM framework \n" +
                 "3.if you have added it, Maybe you're referencing some third-party library and using a KPojo class defined by them," +
                 "please add a custom instantiation method to the `kClassCreatorCustom` like this: \n" +
                 "kClassCreatorCustom = { kClass -> \n" +
                 "\twhen (kClass) {\n" +
                 "\t\tYourKPojo::class -> YourKPojo()\n" +
                 "\t\telse -> null\n\t}\n}"
     )
 }