aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Analysis/AnalysisEnvironment.kt21
-rw-r--r--src/Kotlin/DocumentationBuilder.kt9
-rw-r--r--src/Kotlin/KotlinAsJavaDocumentationBuilder.kt2
-rw-r--r--src/main.kt68
4 files changed, 50 insertions, 50 deletions
diff --git a/src/Analysis/AnalysisEnvironment.kt b/src/Analysis/AnalysisEnvironment.kt
index af9859d6..11bd7ac4 100644
--- a/src/Analysis/AnalysisEnvironment.kt
+++ b/src/Analysis/AnalysisEnvironment.kt
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.config.CommonConfigurationKeys
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.ContentRoot
import org.jetbrains.kotlin.config.KotlinSourceRoot
-import org.jetbrains.kotlin.container.get
import org.jetbrains.kotlin.container.getService
import org.jetbrains.kotlin.context.ProjectContext
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
@@ -58,19 +57,14 @@ import java.io.File
* $messageCollector: required by compiler infrastructure and will receive all compiler messages
* $body: optional and can be used to configure environment without creating local variable
*/
-public class AnalysisEnvironment(val messageCollector: MessageCollector, body: AnalysisEnvironment.() -> Unit = {}) : Disposable {
+public class AnalysisEnvironment(val messageCollector: MessageCollector) : Disposable {
val configuration = CompilerConfiguration();
init {
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector)
- body()
}
- /**
- * Executes [processor] when analysis is complete.
- * $processor: function to receive compiler environment, module and context for symbol resolution
- */
- public fun <T> withContext(processor: (KotlinCoreEnvironment, ResolutionFacade, ResolveSession) -> T): T {
+ fun createCoreEnvironment(): KotlinCoreEnvironment {
val environment = KotlinCoreEnvironment.createForProduction(this, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
val projectComponentManager = environment.project as MockComponentManager
@@ -98,7 +92,10 @@ public class AnalysisEnvironment(val messageCollector: MessageCollector, body: A
KotlinCacheService(environment.project))
projectComponentManager.registerService(KotlinOutOfBlockCompletionModificationTracker::class.java,
KotlinOutOfBlockCompletionModificationTracker())
+ return environment
+ }
+ fun createResolutionFacade(environment: KotlinCoreEnvironment): DokkaResolutionFacade {
val projectContext = ProjectContext(environment.project)
val sourceFiles = environment.getSourceFiles()
@@ -116,9 +113,7 @@ public class AnalysisEnvironment(val messageCollector: MessageCollector, body: A
)
val resolverForModule = resolverForProject.resolverForModule(module)
- val resolveSession = resolverForModule.componentProvider.get<ResolveSession>()
- val facade = DokkaResolutionFacade(environment.project, resolverForProject.descriptorForModule(module), resolverForModule)
- return processor(environment, facade, resolveSession)
+ return DokkaResolutionFacade(environment.project, resolverForProject.descriptorForModule(module), resolverForModule)
}
/**
@@ -183,6 +178,8 @@ class DokkaResolutionFacade(override val project: Project,
override val moduleDescriptor: ModuleDescriptor,
val resolverForModule: ResolverForModule) : ResolutionFacade {
+ val resolveSession: ResolveSession get() = getFrontendService(ResolveSession::class.java)
+
override fun analyze(element: KtElement, bodyResolveMode: BodyResolveMode): BindingContext {
throw UnsupportedOperationException()
}
@@ -208,6 +205,6 @@ class DokkaResolutionFacade(override val project: Project,
}
override fun resolveToDescriptor(declaration: KtDeclaration): DeclarationDescriptor {
- throw UnsupportedOperationException()
+ return resolveSession.resolveToDescriptor(declaration)
}
}
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt
index c48f1495..31c2d3e1 100644
--- a/src/Kotlin/DocumentationBuilder.kt
+++ b/src/Kotlin/DocumentationBuilder.kt
@@ -14,7 +14,6 @@ import org.jetbrains.kotlin.descriptors.impl.EnumEntrySyntheticClassDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.KotlinCacheService
import org.jetbrains.kotlin.idea.caches.resolve.getModuleInfo
import org.jetbrains.kotlin.idea.kdoc.KDocFinder
-import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.kdoc.psi.impl.KDocSection
import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag
@@ -33,7 +32,6 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.resolve.descriptorUtil.isDocumentedAnnotation
import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolver
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
-import org.jetbrains.kotlin.resolve.lazy.ResolveSession
import org.jetbrains.kotlin.resolve.source.PsiSourceElement
import org.jetbrains.kotlin.resolve.source.getPsi
import org.jetbrains.kotlin.types.ErrorUtils
@@ -59,8 +57,7 @@ interface PackageDocumentationBuilder {
declarations: List<DeclarationDescriptor>)
}
-class DocumentationBuilder(val resolutionFacade: ResolutionFacade,
- val session: ResolveSession,
+class DocumentationBuilder(val resolutionFacade: DokkaResolutionFacade,
val linkResolver: DeclarationLinkResolver,
val options: DocumentationOptions,
val refGraph: NodeReferenceGraph,
@@ -134,8 +131,8 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade,
deepestDescriptor = deepestDescriptor.overriddenDescriptors.first()
}
if (DescriptorUtils.getFqName(deepestDescriptor.containingDeclaration).asString() == "kotlin.Any") {
- val anyClassDescriptors = session.getTopLevelClassDescriptors(FqName.fromSegments(listOf("kotlin", "Any")),
- NoLookupLocation.UNSORTED)
+ val anyClassDescriptors = resolutionFacade.resolveSession.getTopLevelClassDescriptors(
+ FqName.fromSegments(listOf("kotlin", "Any")), NoLookupLocation.UNSORTED)
anyClassDescriptors.forEach {
val anyMethod = it.getMemberScope(listOf()).getFunctions(descriptor.name, NoLookupLocation.UNSORTED).single()
val kdoc = KDocFinder.findKDoc(anyMethod)
diff --git a/src/Kotlin/KotlinAsJavaDocumentationBuilder.kt b/src/Kotlin/KotlinAsJavaDocumentationBuilder.kt
index 1bd930e2..8c6e5701 100644
--- a/src/Kotlin/KotlinAsJavaDocumentationBuilder.kt
+++ b/src/Kotlin/KotlinAsJavaDocumentationBuilder.kt
@@ -41,7 +41,7 @@ class KotlinAsJavaDocumentationParser(val documentationBuilder: DocumentationBui
return JavadocParseResult.Empty
}
}
- val descriptor = documentationBuilder.session.resolveToDescriptor(origin)
+ val descriptor = documentationBuilder.resolutionFacade.resolveToDescriptor(origin)
val content = documentationBuilder.parseDocumentation(descriptor)
return JavadocParseResult(content, null)
}
diff --git a/src/main.kt b/src/main.kt
index 1bb0d643..633e4659 100644
--- a/src/main.kt
+++ b/src/main.kt
@@ -177,7 +177,9 @@ class DokkaGenerator(val logger: DokkaLogger,
}
fun createAnalysisEnvironment(): AnalysisEnvironment {
- val environment = AnalysisEnvironment(DokkaMessageCollector(logger)) {
+ val environment = AnalysisEnvironment(DokkaMessageCollector(logger))
+
+ environment.apply {
addClasspath(PathUtil.getJdkClassesRoots())
// addClasspath(PathUtil.getKotlinPathsForCompiler().getRuntimePath())
for (element in this@DokkaGenerator.classpath) {
@@ -187,6 +189,7 @@ class DokkaGenerator(val logger: DokkaLogger,
addSources(this@DokkaGenerator.sources)
addSources(this@DokkaGenerator.samples)
}
+
return environment
}
@@ -208,42 +211,45 @@ fun buildDocumentationModule(environment: AnalysisEnvironment,
packageDocumentationBuilder: PackageDocumentationBuilder? = null,
javaDocumentationBuilder: JavaDocumentationBuilder? = null,
logger: DokkaLogger): DocumentationModule {
- val documentation = environment.withContext { coreEnvironment, resolutionFacade, session ->
- val fragmentFiles = coreEnvironment.getSourceFiles().filter(filesToDocumentFilter)
- val analyzer = resolutionFacade.getFrontendService(LazyTopDownAnalyzerForTopLevel::class.java)
- analyzer.analyzeDeclarations(TopDownAnalysisMode.TopLevelDeclarations, fragmentFiles)
-
- val fragments = fragmentFiles.map { session.getPackageFragment(it.packageFqName) }.filterNotNull().distinct()
-
- val refGraph = NodeReferenceGraph()
- val linkResolver = DeclarationLinkResolver(resolutionFacade, refGraph, logger)
- val documentationBuilder = DocumentationBuilder(resolutionFacade, session, linkResolver, options, refGraph, logger)
- val packageDocs = PackageDocs(linkResolver, fragments.firstOrNull(), logger)
- for (include in includes) {
- packageDocs.parse(include)
- }
- val documentationModule = DocumentationModule(moduleName, packageDocs.moduleContent)
- with(documentationBuilder) {
- if (packageDocumentationBuilder != null) {
- documentationModule.appendFragments(fragments, packageDocs.packageContent, packageDocumentationBuilder)
- }
- else {
- documentationModule.appendFragments(fragments, packageDocs.packageContent)
- }
- }
+ val coreEnvironment = environment.createCoreEnvironment()
+ val resolutionFacade = environment.createResolutionFacade(coreEnvironment)
- val javaFiles = coreEnvironment.getJavaSourceFiles().filter(filesToDocumentFilter)
- with(javaDocumentationBuilder ?: documentationBuilder) {
- javaFiles.map { appendFile(it, documentationModule, packageDocs.packageContent) }
- }
+ val fragmentFiles = coreEnvironment.getSourceFiles().filter(filesToDocumentFilter)
+ val analyzer = resolutionFacade.getFrontendService(LazyTopDownAnalyzerForTopLevel::class.java)
+ analyzer.analyzeDeclarations(TopDownAnalysisMode.TopLevelDeclarations, fragmentFiles)
- refGraph.resolveReferences()
+ val fragments = fragmentFiles
+ .map { resolutionFacade.resolveSession.getPackageFragment(it.packageFqName) }
+ .filterNotNull()
+ .distinct()
- documentationModule
+ val refGraph = NodeReferenceGraph()
+ val linkResolver = DeclarationLinkResolver(resolutionFacade, refGraph, logger)
+ val documentationBuilder = DocumentationBuilder(resolutionFacade, linkResolver, options, refGraph, logger)
+ val packageDocs = PackageDocs(linkResolver, fragments.firstOrNull(), logger)
+ for (include in includes) {
+ packageDocs.parse(include)
}
+ val documentationModule = DocumentationModule(moduleName, packageDocs.moduleContent)
+
+ with(documentationBuilder) {
+ if (packageDocumentationBuilder != null) {
+ documentationModule.appendFragments(fragments, packageDocs.packageContent, packageDocumentationBuilder)
+ }
+ else {
+ documentationModule.appendFragments(fragments, packageDocs.packageContent)
+ }
+ }
+
+ val javaFiles = coreEnvironment.getJavaSourceFiles().filter(filesToDocumentFilter)
+ with(javaDocumentationBuilder ?: documentationBuilder) {
+ javaFiles.map { appendFile(it, documentationModule, packageDocs.packageContent) }
+ }
+
+ refGraph.resolveReferences()
- return documentation
+ return documentationModule
}