From f60beb6e45720ff44ba4e4db915f5e462fb3b907 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 30 Oct 2015 12:24:33 +0100 Subject: fix Kotlin warnings --- src/Utilities/GuiceModule.kt | 22 +++++++++++----------- src/Utilities/ServiceLocator.kt | 16 +++++----------- 2 files changed, 16 insertions(+), 22 deletions(-) (limited to 'src/Utilities') diff --git a/src/Utilities/GuiceModule.kt b/src/Utilities/GuiceModule.kt index 57bad468..855d70b6 100644 --- a/src/Utilities/GuiceModule.kt +++ b/src/Utilities/GuiceModule.kt @@ -10,8 +10,8 @@ import java.io.File class GuiceModule(val config: DokkaGenerator) : Module { override fun configure(binder: Binder) { - binder.bind(javaClass()).toInstance(config) - binder.bind(javaClass()).annotatedWith(Names.named("outputDir")).toInstance(File(config.outputDir)) + binder.bind(DokkaGenerator::class.java).toInstance(config) + binder.bind(File::class.java).annotatedWith(Names.named("outputDir")).toInstance(File(config.outputDir)) binder.bindNameAnnotated("singleFolder") binder.bindNameAnnotated("singleFolder") @@ -19,11 +19,11 @@ class GuiceModule(val config: DokkaGenerator) : Module { binder.bindNameAnnotated("folders") // defaults - binder.bind(javaClass()).to(javaClass()) - binder.bind(javaClass()).to(javaClass()) - binder.bind(javaClass()).to(javaClass()) + binder.bind(LocationService::class.java).to(FoldersLocationService::class.java) + binder.bind(FileLocationService::class.java).to(FoldersLocationService::class.java) + binder.bind(LanguageService::class.java).to(KotlinLanguageService::class.java) - binder.bind(javaClass()).toProvider(object : Provider { + binder.bind(HtmlTemplateService::class.java).toProvider(object : Provider { override fun get(): HtmlTemplateService = HtmlTemplateService.default("/dokka/styles/style.css") }) @@ -35,12 +35,12 @@ class GuiceModule(val config: DokkaGenerator) : Module { val descriptor = ServiceLocator.lookup("format", config.outputFormat, config) descriptor.outlineServiceClass?.let { clazz -> - binder.bind(javaClass()).to(clazz) + binder.bind(OutlineFormatService::class.java).to(clazz) } descriptor.formatServiceClass?.let { clazz -> - binder.bind(javaClass()).to(clazz) + binder.bind(FormatService::class.java).to(clazz) } - binder.bind(javaClass()).to(descriptor.generatorServiceClass) + binder.bind(Generator::class.java).to(descriptor.generatorServiceClass) } } @@ -48,11 +48,11 @@ class GuiceModule(val config: DokkaGenerator) : Module { private inline fun Binder.registerCategory(category: String) { ServiceLocator.allServices(category).forEach { @Suppress("UNCHECKED_CAST") - bind(javaClass()).annotatedWith(Names.named(it.name)).to(javaClass().classLoader.loadClass(it.className) as Class) + bind(T::class.java).annotatedWith(Names.named(it.name)).to(T::class.java.classLoader.loadClass(it.className) as Class) } } private inline fun Binder.bindNameAnnotated(name: String) { - bind(javaClass()).annotatedWith(Names.named(name)).to(javaClass()) + bind(Base::class.java).annotatedWith(Names.named(name)).to(T::class.java) } diff --git a/src/Utilities/ServiceLocator.kt b/src/Utilities/ServiceLocator.kt index bc04238f..57d2f47b 100644 --- a/src/Utilities/ServiceLocator.kt +++ b/src/Utilities/ServiceLocator.kt @@ -15,8 +15,8 @@ public object ServiceLocator { val descriptor = lookupDescriptor(category, implementationName) val loadedClass = javaClass.classLoader.loadClass(descriptor.className) val constructor = loadedClass.constructors - .filter { it.parameterTypes.isEmpty() || (it.parameterTypes.size() == 1 && conf.javaClass.isInstance(it.parameterTypes[0])) } - .sortedByDescending { it.parameterTypes.size() } + .filter { it.parameterTypes.isEmpty() || (it.parameterTypes.size == 1 && conf.javaClass.isInstance(it.parameterTypes[0])) } + .sortedByDescending { it.parameterTypes.size } .firstOrNull() ?: throw ServiceLookupException("Class ${descriptor.className} has no corresponding constructor") val implementationRawType: Any = if (constructor.parameterTypes.isEmpty()) constructor.newInstance() else constructor.newInstance(constructor) @@ -81,20 +81,14 @@ public object ServiceLocator { } ?: emptyList() } -public inline fun ServiceLocator.lookup(category: String, implementationName: String, conf: DokkaGenerator): T = lookup(javaClass(), category, implementationName, conf) -public inline fun ServiceLocator.lookupClass(category: String, implementationName: String): Class = lookupClass(javaClass(), category, implementationName) +public inline fun ServiceLocator.lookup(category: String, implementationName: String, conf: DokkaGenerator): T = lookup(T::class.java, category, implementationName, conf) +public inline fun ServiceLocator.lookupClass(category: String, implementationName: String): Class = lookupClass(T::class.java, category, implementationName) public inline fun ServiceLocator.lookupOrNull(category: String, implementationName: String, conf: DokkaGenerator): T? = try { - lookup(javaClass(), category, implementationName, conf) + lookup(T::class.java, category, implementationName, conf) } catch (any: Throwable) { null } -fun main(args: Array) { - ServiceLocator.allServices("format").forEach { - println(it) - } -} - private val ZipEntry.fileName: String get() = name.substringAfterLast("/", name) -- cgit