fun fromScopeMethod()

in models/src/main/kotlin/motif/models/ScopeMethod.kt [29:62]


    fun fromScopeMethod(scope: Scope, method: IrMethod): ScopeMethod {
      if (method.isVoid()) {
        throw VoidScopeMethod(scope, method)
      }

      val returnClass: IrClass? = method.returnType.resolveClass()

      if (returnClass == null && !method.returnType.isPrimitive) {
        // resolve class does not return IrClass if it is primitive,
        // hence we need to throw only if not primitive and not resolved.
        throw CannotResolveType(scope, method.returnType)
      }

      if (returnClass != null && returnClass.hasAnnotation(motif.Scope::class)) {
        method.parameters
            .find { it.isNullable() }
            ?.let { nullableParameter ->
              throw NullableDynamicDependency(scope, method, nullableParameter)
            }
        val childMethod = ChildMethod(method, scope, returnClass)
        val duplicatedParameterTypes =
            childMethod.parameters - childMethod.parameters.distinctBy { it.type }
        if (duplicatedParameterTypes.isNotEmpty()) {
          throw DuplicatedChildParameterSource(scope, childMethod, duplicatedParameterTypes)
        }
        return childMethod
      }

      if (method.hasParameters()) {
        throw AccessMethodParameters(scope, method)
      }

      return AccessMethod(method, scope)
    }