Skip to content
Merged
Show file tree
Hide file tree
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
@@ -1,7 +1,5 @@
package com.onesignal.common.services

import com.onesignal.debug.internal.logging.Logging

/**
* A service provider gives access to the implementations of a service.
*/
Expand Down Expand Up @@ -66,7 +64,6 @@ class ServiceProvider(
override fun <T> getService(c: Class<T>): T {
val service = getServiceOrNull(c)
if (service == null) {
Logging.warn("Service not found: $c")
throw Exception("Service $c could not be instantiated")
}

Expand All @@ -75,7 +72,6 @@ class ServiceProvider(

override fun <T> getServiceOrNull(c: Class<T>): T? {
synchronized(serviceMap) {
Logging.debug("${indent}Retrieving service $c")
return serviceMap[c]?.last()?.resolve(this) as T?
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import java.lang.reflect.WildcardType
abstract class ServiceRegistration<T> {
val services: MutableSet<Class<*>> = mutableSetOf()

inline fun <reified TService : Any> provides(): ServiceRegistration<T> {
return provides(TService::class.java)
}
inline fun <reified TService : Any> provides(): ServiceRegistration<T> = provides(TService::class.java)

/**
* Indicate this registration wants to provide the provided class as
Expand Down Expand Up @@ -53,14 +51,12 @@ class ServiceRegistrationReflection<T>(

override fun resolve(provider: IServiceProvider): Any? {
if (obj != null) {
Logging.debug("${ServiceProvider.indent}Already instantiated: $obj")
return obj
}

// use reflection to try to instantiate the thing
for (constructor in clazz.constructors) {
if (doesHaveAllParameters(constructor, provider)) {
Logging.debug("${ServiceProvider.indent}Found constructor: $constructor")
var paramList: MutableList<Any?> = mutableListOf()

for (param in constructor.genericParameterTypes) {
Expand Down Expand Up @@ -106,25 +102,25 @@ class ServiceRegistrationReflection<T>(
val clazz = argType.upperBounds.first()
if (clazz is Class<*>) {
if (!provider.hasService(clazz)) {
Logging.debug("Constructor $constructor could not find service: $clazz")
Logging.error("Constructor $constructor could not find service: $clazz")
return false
}
}
} else if (argType is Class<*>) {
if (!provider.hasService(argType)) {
Logging.debug("Constructor $constructor could not find service: $argType")
Logging.error("Constructor $constructor could not find service: $argType")
return false
}
} else {
return false
}
} else if (param is Class<*>) {
if (!provider.hasService(param)) {
Logging.debug("Constructor $constructor could not find service: $param")
Logging.error("Constructor $constructor could not find service: $param")
return false
}
} else {
Logging.debug("Constructor $constructor could not identify param type: $param")
Logging.error("Constructor $constructor could not identify param type: $param")
return false
}
}
Expand Down
Loading