Skip to content

Commit 551a230

Browse files
committed
Add KClass methods to PlugRegistry.
1 parent 3bd2010 commit 551a230

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

atplug-runtime/src/main/java/com/diffplug/atplug/PlugRegistry.kt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,19 @@ import java.net.URL
1313
import java.nio.charset.StandardCharsets
1414
import java.util.jar.Manifest
1515
import java.util.zip.ZipException
16+
import kotlin.reflect.KClass
1617

1718
interface PlugRegistry {
18-
fun <T : Any> registerSocket(socketClass: Class<T>, socketOwner: SocketOwner<T>)
19+
fun <T : Any> registerSocket(socketClass: KClass<T>, socketOwner: SocketOwner<T>)
1920

20-
fun <T : Any> instantiatePlug(socketClass: Class<T>, plugDescriptor: PlugDescriptor): T
21+
fun <T : Any> instantiatePlug(socketClass: KClass<T>, plugDescriptor: PlugDescriptor): T
22+
23+
fun <T : Any> registerSocket(socketClass: Class<T>, socketOwner: SocketOwner<T>) {
24+
registerSocket(socketClass.kotlin, socketOwner)
25+
}
26+
27+
fun <T : Any> instantiatePlug(socketClass: Class<T>, plugDescriptor: PlugDescriptor): T =
28+
instantiatePlug(socketClass.kotlin, plugDescriptor)
2129

2230
companion object {
2331
private val instance: Lazy<PlugRegistry> = lazy { Eager() }
@@ -116,16 +124,16 @@ interface PlugRegistry {
116124
return PlugDescriptor.fromJson(serviceFileContent)
117125
}
118126

119-
override fun <T : Any> registerSocket(socketClass: Class<T>, socketOwner: SocketOwner<T>) {
127+
override fun <T : Any> registerSocket(socketClass: KClass<T>, socketOwner: SocketOwner<T>) {
120128
synchronized(this) {
121-
val prevOwner = owners.put(socketClass.name, socketOwner)
129+
val prevOwner = owners.put(socketClass.qualifiedName!!, socketOwner)
122130
assert(prevOwner == null) { "Multiple owners registered for $socketClass" }
123-
data.descriptorMap[socketClass.name]?.forEach(socketOwner::doRegister)
131+
data.descriptorMap[socketClass.qualifiedName]?.forEach(socketOwner::doRegister)
124132
}
125133
}
126134

127135
override fun <T : Any> instantiatePlug(
128-
socketClass: Class<T>,
136+
socketClass: KClass<T>,
129137
plugDescriptor: PlugDescriptor
130138
): T {
131139
val value =

0 commit comments

Comments
 (0)