org.jetbrains.dokka.analysis.EnvironmentAndFacade.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dokka-analysis Show documentation
Show all versions of dokka-analysis Show documentation
Dokka is an API documentation engine for Kotlin and Java, performing the same function as Javadoc for Java
package org.jetbrains.dokka.analysis
import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.Platform
import org.jetbrains.dokka.utilities.DokkaLogger
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.utils.PathUtil
internal fun createEnvironmentAndFacade(
logger: DokkaLogger,
sourceSets: List,
sourceSet: DokkaConfiguration.DokkaSourceSet
): EnvironmentAndFacade =
AnalysisEnvironment(DokkaMessageCollector(logger), sourceSet.analysisPlatform).run {
if (analysisPlatform == Platform.jvm) {
configureJdkClasspathRoots()
}
val parentSourceSets = sourceSets.filter { it.sourceSetID in sourceSet.dependentSourceSets }
addClasspath(sourceSet.classpath + parentSourceSets.flatMap { it.classpath })
addSources(sourceSet.sourceRoots + parentSourceSets.flatMap { it.sourceRoots })
loadLanguageVersionSettings(sourceSet.languageVersion, sourceSet.apiVersion)
val environment = createCoreEnvironment()
val (facade, _) = createResolutionFacade(environment)
EnvironmentAndFacade(environment, facade)
}
class DokkaMessageCollector(private val logger: DokkaLogger) : MessageCollector {
override fun clear() {
seenErrors = false
}
private var seenErrors = false
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageSourceLocation?) {
if (severity == CompilerMessageSeverity.ERROR) {
seenErrors = true
}
logger.info(MessageRenderer.PLAIN_FULL_PATHS.render(severity, message, location))
}
override fun hasErrors() = seenErrors
}
// It is not data class due to ill-defined equals
class EnvironmentAndFacade(val environment: KotlinCoreEnvironment, val facade: DokkaResolutionFacade) {
operator fun component1() = environment
operator fun component2() = facade
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy