org.jetbrains.dokka.analysis.DokkaResolutionFacade.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
@file:OptIn(FrontendInternals::class)
package org.jetbrains.dokka.analysis
import com.google.common.collect.ImmutableMap
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.analyzer.AnalysisResult
import org.jetbrains.kotlin.analyzer.ModuleInfo
import org.jetbrains.kotlin.analyzer.ResolverForModule
import org.jetbrains.kotlin.analyzer.ResolverForProject
import org.jetbrains.kotlin.container.getService
import org.jetbrains.kotlin.container.tryGetService
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.kotlin.psi.KtParameter
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.util.slicedMap.ReadOnlySlice
import org.jetbrains.kotlin.util.slicedMap.WritableSlice
class DokkaResolutionFacade(
override val project: Project,
override val moduleDescriptor: ModuleDescriptor,
val resolverForModule: ResolverForModule
) : ResolutionFacade {
override fun analyzeWithAllCompilerChecks(
elements: Collection,
callback: DiagnosticSink.DiagnosticsCallback?
): AnalysisResult {
throw UnsupportedOperationException()
}
@OptIn(FrontendInternals::class)
override fun tryGetFrontendService(element: PsiElement, serviceClass: Class): T? {
return resolverForModule.componentProvider.tryGetService(serviceClass)
}
override fun resolveToDescriptor(
declaration: KtDeclaration,
bodyResolveMode: BodyResolveMode
): DeclarationDescriptor {
return resolveSession.resolveToDescriptor(declaration)
}
override fun analyze(elements: Collection, bodyResolveMode: BodyResolveMode): BindingContext {
throw UnsupportedOperationException()
}
val resolveSession: ResolveSession get() = getFrontendService(ResolveSession::class.java)
override fun analyze(element: KtElement, bodyResolveMode: BodyResolveMode): BindingContext {
if (element is KtDeclaration) {
val descriptor = resolveToDescriptor(element)
return object : BindingContext {
override fun getKeys(p0: WritableSlice?): Collection {
throw UnsupportedOperationException()
}
override fun getType(p0: KtExpression): KotlinType? {
throw UnsupportedOperationException()
}
override fun get(slice: ReadOnlySlice?, key: K): V? {
if (key != element) {
throw UnsupportedOperationException()
}
@Suppress("UNCHECKED_CAST")
return when {
slice == BindingContext.DECLARATION_TO_DESCRIPTOR -> descriptor as V
slice == BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER && (element as KtParameter).hasValOrVar() -> descriptor as V
else -> null
}
}
override fun getDiagnostics(): Diagnostics {
throw UnsupportedOperationException()
}
override fun addOwnDataTo(p0: BindingTrace, p1: Boolean) {
throw UnsupportedOperationException()
}
override fun getSliceContents(p0: ReadOnlySlice): ImmutableMap {
throw UnsupportedOperationException()
}
}
}
throw UnsupportedOperationException()
}
override fun getFrontendService(element: PsiElement, serviceClass: Class): T {
throw UnsupportedOperationException()
}
override fun getFrontendService(serviceClass: Class): T {
return resolverForModule.componentProvider.getService(serviceClass)
}
override fun getFrontendService(moduleDescriptor: ModuleDescriptor, serviceClass: Class): T {
return resolverForModule.componentProvider.getService(serviceClass)
}
override fun getIdeService(serviceClass: Class): T {
throw UnsupportedOperationException()
}
override fun getResolverForProject(): ResolverForProject {
throw UnsupportedOperationException()
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy