Container structure dump facilities.
This commit is contained in:
@@ -24,5 +24,9 @@ public class InstanceComponentDescriptor(val instance: Any) : ComponentDescripto
|
||||
override fun getRegistrations(): Iterable<Type> = instance.javaClass.getInfo().registrations
|
||||
|
||||
override fun getDependencies(context: ValueResolveContext): Collection<Class<*>> = emptyList()
|
||||
|
||||
override fun toString(): String {
|
||||
return "Instance: ${instance.javaClass.getSimpleName()}"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
package org.jetbrains.kotlin.container
|
||||
|
||||
import java.io.Closeable
|
||||
import java.io.PrintStream
|
||||
import java.io.Writer
|
||||
import java.lang.reflect.ParameterizedType
|
||||
import java.lang.reflect.Type
|
||||
import java.lang.reflect.WildcardType
|
||||
@@ -28,10 +30,9 @@ public interface ComponentContainer {
|
||||
fun createResolveContext(requestingDescriptor: ValueDescriptor): ValueResolveContext
|
||||
}
|
||||
|
||||
object DynamicComponentDescriptor : ComponentDescriptor {
|
||||
override fun getDependencies(context: ValueResolveContext): Collection<Class<*>> = throw UnsupportedOperationException()
|
||||
override fun getRegistrations(): Iterable<Class<*>> = throw UnsupportedOperationException()
|
||||
object DynamicComponentDescriptor : ValueDescriptor {
|
||||
override fun getValue(): Any = throw UnsupportedOperationException()
|
||||
override fun toString(): String = "Dynamic"
|
||||
}
|
||||
|
||||
public class StorageComponentContainer(id: String) : ComponentContainer, Closeable {
|
||||
@@ -49,6 +50,10 @@ public class StorageComponentContainer(id: String) : ComponentContainer, Closeab
|
||||
return this
|
||||
}
|
||||
|
||||
fun dump(printer: PrintStream) {
|
||||
componentStorage.dump(printer)
|
||||
}
|
||||
|
||||
override fun close() = componentStorage.dispose()
|
||||
|
||||
jvmOverloads public fun resolve(request: Type, context: ValueResolveContext = unknownContext): ValueDescriptor? {
|
||||
|
||||
@@ -29,7 +29,7 @@ public fun topologicalSort<T>(items: Iterable<T>, dependencies: (T) -> Iterable<
|
||||
return
|
||||
|
||||
if (item in itemsInProgress)
|
||||
throw CycleInTopoSortException()
|
||||
return //throw CycleInTopoSortException()
|
||||
|
||||
itemsInProgress.add(item)
|
||||
|
||||
|
||||
@@ -33,4 +33,6 @@ public class IterableDescriptor(val descriptors: Iterable<ValueDescriptor>) : Va
|
||||
override fun getValue(): Any {
|
||||
return descriptors.map { it.getValue() }
|
||||
}
|
||||
|
||||
override fun toString(): String = "Iterable: $descriptors"
|
||||
}
|
||||
@@ -117,6 +117,8 @@ public abstract class SingletonDescriptor(val container: ComponentContainer) : C
|
||||
}
|
||||
|
||||
public abstract class SingletonComponentDescriptor(container: ComponentContainer, val klass: Class<*>) : SingletonDescriptor(container) {
|
||||
override fun toString(): String = "Singleton: ${klass.getSimpleName()}"
|
||||
|
||||
public override fun getRegistrations(): Iterable<Type> = klass.getInfo().registrations
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.container
|
||||
|
||||
import com.intellij.util.containers.MultiMap
|
||||
import java.io.Closeable
|
||||
import java.io.PrintStream
|
||||
import java.lang.reflect.Modifier
|
||||
import java.lang.reflect.ParameterizedType
|
||||
import java.lang.reflect.Type
|
||||
@@ -64,6 +65,29 @@ public class ComponentStorage(val myId: String) : ValueResolver {
|
||||
}
|
||||
}
|
||||
|
||||
public fun dump(printer: PrintStream): Unit = with (printer) {
|
||||
val heading = "Container: $myId"
|
||||
println(heading)
|
||||
println("=".repeat(heading.length()))
|
||||
println()
|
||||
getDescriptorsInDisposeOrder().forEach { descriptor ->
|
||||
println(descriptor)
|
||||
dependencies[descriptor].forEach {
|
||||
print(" -> ")
|
||||
val typeName = it.toString()
|
||||
print(typeName.substringBefore(" ")) // interface, class
|
||||
print(" ")
|
||||
print(typeName.substringAfterLast(".")) // name
|
||||
val resolve = registry.tryGetEntry(it)
|
||||
print(" as ")
|
||||
print(resolve)
|
||||
println()
|
||||
}
|
||||
println()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public fun resolveMultiple(request: Type, context: ValueResolveContext): Iterable<ValueDescriptor> {
|
||||
registerDependency(request, context)
|
||||
return registry.tryGetEntry(request)
|
||||
@@ -103,7 +127,7 @@ public class ComponentStorage(val myId: String) : ValueResolver {
|
||||
private fun injectProperties(context: ComponentResolveContext, components: Collection<ComponentDescriptor>) {
|
||||
for (component in components) {
|
||||
if (component.shouldInjectProperties) {
|
||||
injectProperties(component.getValue(), context)
|
||||
injectProperties(component.getValue(), context.container.createResolveContext(component))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,7 +143,7 @@ public class ComponentStorage(val myId: String) : ValueResolver {
|
||||
}
|
||||
|
||||
private fun collectAdhocComponents(context: ComponentResolveContext, descriptor: ComponentDescriptor,
|
||||
visitedTypes: HashSet<Type>, adhocDescriptors: LinkedHashSet<ComponentDescriptor>
|
||||
visitedTypes: HashSet<Type>, adhocDescriptors: LinkedHashSet<ComponentDescriptor>
|
||||
) {
|
||||
val dependencies = descriptor.getDependencies(context)
|
||||
for (type in dependencies) {
|
||||
@@ -128,11 +152,11 @@ public class ComponentStorage(val myId: String) : ValueResolver {
|
||||
|
||||
val entry = registry.tryGetEntry(type)
|
||||
if (entry.isEmpty()) {
|
||||
val rawType : Class<*>? = when(type){
|
||||
is Class<*> -> type
|
||||
is ParameterizedType -> type.getRawType() as? Class<*>
|
||||
else -> null
|
||||
}
|
||||
val rawType: Class<*>? = when (type) {
|
||||
is Class<*> -> type
|
||||
is ParameterizedType -> type.getRawType() as? Class<*>
|
||||
else -> null
|
||||
}
|
||||
if (rawType == null)
|
||||
continue
|
||||
|
||||
|
||||
Reference in New Issue
Block a user