diff options
| author | Szymon Świstun <sswistun@virtuslab.com> | 2020-03-05 11:40:22 +0100 | 
|---|---|---|
| committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-03-17 12:36:45 +0100 | 
| commit | 8658fd40e3674e29ef10e1fc4289d26caea1e762 (patch) | |
| tree | dbde63dcb27449907f256b77e7aad437ef697c7c /core/src/main/kotlin/plugability | |
| parent | 4002c4e91cb42ef77e93cac57ac49823629d33da (diff) | |
| download | dokka-8658fd40e3674e29ef10e1fc4289d26caea1e762.tar.gz dokka-8658fd40e3674e29ef10e1fc4289d26caea1e762.tar.bz2 dokka-8658fd40e3674e29ef10e1fc4289d26caea1e762.zip | |
Add warning when unused extension points are found
Diffstat (limited to 'core/src/main/kotlin/plugability')
| -rw-r--r-- | core/src/main/kotlin/plugability/DokkaContext.kt | 24 | 
1 files changed, 16 insertions, 8 deletions
| diff --git a/core/src/main/kotlin/plugability/DokkaContext.kt b/core/src/main/kotlin/plugability/DokkaContext.kt index 5d5a8ebf..c5a08a56 100644 --- a/core/src/main/kotlin/plugability/DokkaContext.kt +++ b/core/src/main/kotlin/plugability/DokkaContext.kt @@ -1,9 +1,9 @@  package org.jetbrains.dokka.plugability  import org.jetbrains.dokka.DokkaConfiguration -import org.jetbrains.dokka.utilities.DokkaLogger  import org.jetbrains.dokka.EnvironmentAndFacade  import org.jetbrains.dokka.pages.PlatformData +import org.jetbrains.dokka.utilities.DokkaLogger  import java.io.File  import java.net.URLClassLoader  import java.util.* @@ -22,6 +22,8 @@ interface DokkaContext {      val logger: DokkaLogger      val configuration: DokkaConfiguration      val platforms: Map<PlatformData, EnvironmentAndFacade> +    val unusedPoints: Collection<ExtensionPoint<*>> +      companion object {          fun create( @@ -43,7 +45,7 @@ interface DokkaContext {      }  } -inline fun <reified T: DokkaPlugin> DokkaContext.plugin(): T = plugin(T::class) +inline fun <reified T : DokkaPlugin> DokkaContext.plugin(): T = plugin(T::class)      ?: throw java.lang.IllegalStateException("Plugin ${T::class.qualifiedName} is not present in context.")  interface DokkaContextConfiguration { @@ -58,6 +60,10 @@ private class DokkaContextConfigurationImpl(      private val plugins = mutableMapOf<KClass<*>, DokkaPlugin>()      private val pluginStubs = mutableMapOf<KClass<*>, DokkaPlugin>()      internal val extensions = mutableMapOf<ExtensionPoint<*>, MutableList<Extension<*>>>() +    val pointsUsed: MutableSet<ExtensionPoint<*>> = mutableSetOf() +    val pointsPopulated: MutableSet<ExtensionPoint<*>> = mutableSetOf() +    override val unusedPoints: Set<ExtensionPoint<*>> +        get() = pointsPopulated - pointsUsed      private enum class State {          UNVISITED, @@ -74,9 +80,9 @@ private class DokkaContextConfigurationImpl(          fun visit(n: Extension<*>) {              val state = verticesWithState[n] -            if(state == State.VISITED) +            if (state == State.VISITED)                  return -            if(state == State.VISITING) +            if (state == State.VISITING)                  throw Error("Detected cycle in plugins graph")              verticesWithState[n] = State.VISITING              adjacencyList[n]?.forEach { visit(it) } @@ -84,24 +90,26 @@ private class DokkaContextConfigurationImpl(              result += n          } -        for((vertex, state) in verticesWithState) { -            if(state == State.UNVISITED) +        for ((vertex, state) in verticesWithState) { +            if (state == State.UNVISITED)                  visit(vertex)          }          result.asReversed().forEach { +            pointsPopulated += it.extensionPoint              extensions.getOrPut(it.extensionPoint, ::mutableListOf) += it          }      }      @Suppress("UNCHECKED_CAST")      override operator fun <T, E> get(point: E) where T : Any, E : ExtensionPoint<T> = -        actions(point).orEmpty() as List<T> +        actions(point).also { pointsUsed += point }.orEmpty() as List<T>      @Suppress("UNCHECKED_CAST")      override fun <T, E> single(point: E): T where T : Any, E : ExtensionPoint<T> {          fun throwBadArity(substitution: String): Nothing = throw IllegalStateException(              "$point was expected to have exactly one extension registered, but $substitution found."          ) +        pointsUsed += point          val extensions = extensions[point].orEmpty() as List<Extension<T>>          return when (extensions.size) { @@ -109,7 +117,7 @@ private class DokkaContextConfigurationImpl(              1 -> extensions.single().action.get(this)              else -> {                  val notFallbacks = extensions.filterNot { it.isFallback } -                if (notFallbacks.size == 1)  notFallbacks.single().action.get(this) else throwBadArity("many were") +                if (notFallbacks.size == 1) notFallbacks.single().action.get(this) else throwBadArity("many were")              }          }      } | 
