diff options
30 files changed, 638 insertions, 533 deletions
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml index 79ee123c..6e6eec11 100644 --- a/.idea/codeStyles/codeStyleConfig.xml +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -1,5 +1,6 @@ <component name="ProjectCodeStyleConfiguration"> <state> <option name="USE_PER_PROJECT_SETTINGS" value="true" /> + <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" /> </state> </component>
\ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 71547e0e..5d169de7 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -11,14 +11,6 @@ <entry name="!?*.kt" /> <entry name="!?*.clj" /> </wildcardResourcePatterns> - <annotationProcessing> - <profile name="Maven default annotation processors profile" enabled="true"> - <sourceOutputDir name="target/generated-sources/annotations" /> - <sourceTestOutputDir name="target/generated-test-sources/test-annotations" /> - <outputRelativeToContentRoot value="true" /> - <module name="dokka-maven-plugin" /> - </profile> - </annotationProcessing> <bytecodeTargetLevel> <module name="android-gradle-plugin_main" target="1.8" /> <module name="android-gradle-plugin_test" target="1.8" /> diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 00000000..664d1ad2 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,80 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="RemoteRepositoriesConfiguration"> + <remote-repository> + <option name="id" value="central" /> + <option name="name" value="Maven Central repository" /> + <option name="url" value="https://repo1.maven.org/maven2" /> + </remote-repository> + <remote-repository> + <option name="id" value="jboss.community" /> + <option name="name" value="JBoss Community repository" /> + <option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" /> + </remote-repository> + <remote-repository> + <option name="id" value="maven8" /> + <option name="name" value="maven8" /> + <option name="url" value="https://www.jetbrains.com/intellij-repository/snapshots" /> + </remote-repository> + <remote-repository> + <option name="id" value="maven5" /> + <option name="name" value="maven5" /> + <option name="url" value="https://kotlin.bintray.com/kotlinx" /> + </remote-repository> + <remote-repository> + <option name="id" value="MavenRepo" /> + <option name="name" value="MavenRepo" /> + <option name="url" value="https://repo.maven.apache.org/maven2/" /> + </remote-repository> + <remote-repository> + <option name="id" value="maven4" /> + <option name="name" value="maven4" /> + <option name="url" value="https://teamcity.jetbrains.com/guestAuth/repository/download/Kotlin_dev_CompilerAllPlugins/1.3.20-dev-564/maven" /> + </remote-repository> + <remote-repository> + <option name="id" value="MavenLocal" /> + <option name="name" value="MavenLocal" /> + <option name="url" value="file:$MAVEN_REPOSITORY$/" /> + </remote-repository> + <remote-repository> + <option name="id" value="maven7" /> + <option name="name" value="maven7" /> + <option name="url" value="https://dl.bintray.com/orangy/maven" /> + </remote-repository> + <remote-repository> + <option name="id" value="maven" /> + <option name="name" value="maven" /> + <option name="url" value="https://dl.bintray.com/jetbrains/markdown" /> + </remote-repository> + <remote-repository> + <option name="id" value="BintrayJCenter" /> + <option name="name" value="BintrayJCenter" /> + <option name="url" value="https://jcenter.bintray.com/" /> + </remote-repository> + <remote-repository> + <option name="id" value="maven9" /> + <option name="name" value="maven9" /> + <option name="url" value="https://www.jetbrains.com/intellij-repository/releases" /> + </remote-repository> + <remote-repository> + <option name="id" value="maven2" /> + <option name="name" value="maven2" /> + <option name="url" value="https://dl.bintray.com/kotlin/kotlin-eap" /> + </remote-repository> + <remote-repository> + <option name="id" value="maven3" /> + <option name="name" value="maven3" /> + <option name="url" value="https://dl.bintray.com/kotlin/kotlin-dev" /> + </remote-repository> + <remote-repository> + <option name="id" value="maven6" /> + <option name="name" value="maven6" /> + <option name="url" value="https://dl.bintray.com/kotlin/kotlinx" /> + </remote-repository> + <remote-repository> + <option name="id" value="Google" /> + <option name="name" value="Google" /> + <option name="url" value="https://dl.google.com/dl/android/maven2/" /> + </remote-repository> + </component> +</project>
\ No newline at end of file diff --git a/.idea/kotlinScripting.xml b/.idea/kotlinScripting.xml new file mode 100644 index 00000000..a6fe551d --- /dev/null +++ b/.idea/kotlinScripting.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="KotlinScriptingSettings"> + <option name="isAutoReloadEnabled" value="true" /> + </component> +</project>
\ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..3e81c6d4 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,35 @@ +## Branches + +As of late January 2020: + +* master is the latest released version (0.10.0). +* dev-0.10.1 is the maintenance branch for 0.10.0. It will contain mostly bugfixes. +* dev-0.11.0 is a big rewrite of dokka, it's changing fast and things may break but this is where new features should be developed. + +## Building dokka + +Dokka is built with Gradle. To build it, use `./gradlew build`. +Alternatively, open the project directory in IntelliJ IDEA and use the IDE to build and run dokka. + +Here's how to import and configure Dokka in IntelliJ IDEA: + * Select "Open" from the IDEA welcome screen, or File > Open if a project is + already open +* Select the directory with your clone of Dokka + * Note: IDEA may have an error after the project is initally opened; it is OK + to ignore this as the next step will address this error +* After IDEA opens the project, select File > New > Module from existing sources + and select the `build.gradle` file from the root directory of your Dokka clone +* Use the default options and select "OK" +* After Dokka is loaded into IDEA, open the Gradle tool window (View > Tool + Windows > Gradle) and click on the top left "Refresh all Gradle projects" + button +* Verify the following project settings. In File > Settings > Build, Execution, + Deployment > Build Tools > Gradle > Runner: + * Ensure "Delegate IDE build/run actions to gradle" is checked + * "Gradle Test Runner" should be selected in the "Run tests using" drop-down + menu +* Note: After closing and re-opening the project, IDEA may give an error + message: "Error Loading Project: Cannot load 3 modules". Open up the details + of the error, and click "Remove Selected", as these module `.iml` files are + safe to remove. + @@ -29,7 +29,7 @@ or using the plugins block: ```groovy plugins { - id 'org.jetbrains.dokka' version '0.10.0' + id 'org.jetbrains.dokka' version '0.10.1' } repositories { jcenter() // or maven { url 'https://dl.bintray.com/kotlin/dokka' } @@ -106,9 +106,6 @@ dokka { // Property used for manual addition of files to the classpath // This property does not override the classpath collected automatically but appends to it classpath = [new File("$buildDir/other.jar")] - - // By default, sourceRoots are taken from Kotlin Plugin, subProjects and kotlinTasks, following roots will be appended to them - sourceRoots = [files('src/main/kotlin')] // List of files with module and package documentation // https://kotlinlang.org/docs/reference/kotlin-doc.html#module-and-package-documentation @@ -316,7 +313,7 @@ repositories { } dependencies { - dokkaRuntime "org.jetbrains.dokka:dokka-fatjar:0.10.0" + dokkaRuntime "org.jetbrains.dokka:dokka-fatjar:0.10.1" } dokka { @@ -339,7 +336,7 @@ To use your Fat Jar, just set the path to it: } dependencies { - dokkaRuntime files("/path/to/fatjar/dokka-fatjar-0.10.0.jar") + dokkaRuntime files("/path/to/fatjar/dokka-fatjar-0.10.1.jar") } dokka { @@ -376,8 +373,15 @@ apply plugin: 'org.jetbrains.dokka' ``` There is also a `noAndroidSdkLink` configuration parameter that works similar to `noJdkLink` and `noStdlibLink` -By default the variant documented by dokka is the first release variant encountered. If you want to change that, -you can disable the autoconfiguration and configure dokka manually. +By default the variant documented by dokka is the first release variant encountered. +You can override that by setting the `androidVariants` property inside the `configuration` (or specific platform) block: +```groovy +dokka { + configuration { + androidVariants = ["debug", "release"] + } +} +``` ### Using the Maven plugin @@ -579,7 +583,7 @@ Inside the `dokka` tag you can create another tags named `<passconfig/>` that su ### Using the Command Line -To run Dokka from the command line, download the [Dokka jar](https://github.com/Kotlin/dokka/releases/download/0.10.0/dokka-fatjar-0.10.0.jar). +To run Dokka from the command line, download the [Dokka jar](https://github.com/Kotlin/dokka/releases/download/0.10.1/dokka-fatjar-0.10.1.jar). To generate documentation, run the following command: java -jar dokka-fatjar.jar <arguments> @@ -634,29 +638,3 @@ doesn't affect analysis of source code, it just changes the result. You can thin * `native` * `common` -## Building dokka - -Dokka is built with Gradle. To build it, use `./gradlew build`. -Alternatively, open the project directory in IntelliJ IDEA and use the IDE to build and run dokka. - -Here's how to import and configure Dokka in IntelliJ IDEA: - * Select "Open" from the IDEA welcome screen, or File > Open if a project is - already open -* Select the directory with your clone of Dokka - * Note: IDEA may have an error after the project is initally opened; it is OK - to ignore this as the next step will address this error -* After IDEA opens the project, select File > New > Module from existing sources - and select the `build.gradle` file from the root directory of your Dokka clone -* Use the default options and select "OK" -* After Dokka is loaded into IDEA, open the Gradle tool window (View > Tool - Windows > Gradle) and click on the top left "Refresh all Gradle projects" - button -* Verify the following project settings. In File > Settings > Build, Execution, - Deployment > Build Tools > Gradle > Runner: - * Ensure "Delegate IDE build/run actions to gradle" is checked - * "Gradle Test Runner" should be selected in the "Run tests using" drop-down - menu -* Note: After closing and re-opening the project, IDEA may give an error - message: "Error Loading Project: Cannot load 3 modules". Open up the details - of the error, and click "Remove Selected", as these module `.iml` files are - safe to remove. diff --git a/build.gradle b/build.gradle index 73636b24..777d45dd 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,3 @@ -import org.jetbrains.DependenciesVersionGetter - allprojects { ext { if (!project.findProperty("dokka_version")) { @@ -41,6 +39,8 @@ allprojects { jcenter() mavenCentral() mavenLocal() + maven { url 'https://kotlin.bintray.com/kotlin-plugin' } + maven { url 'https://www.jetbrains.com/intellij-repository/releases' } maven { url "https://dl.bintray.com/jetbrains/markdown" } maven { url "https://dl.bintray.com/kotlin/kotlin-eap" } maven { url "https://dl.bintray.com/kotlin/kotlin-dev" } @@ -78,10 +78,6 @@ def bintrayPublication(project, List<String> _publications) { }) } -def versions = DependenciesVersionGetter.getVersions(project, bundled_kotlin_compiler_version) - -ext.ideaVersion = versions["idea.build.id"] -ext.markdownVersion = versions["markdown.build.id"].replace("%20", " ") configurations { ideaIC @@ -89,13 +85,14 @@ configurations { } repositories { + maven { url 'https://kotlin.bintray.com/kotlin-plugin' } maven { url 'https://www.jetbrains.com/intellij-repository/snapshots' } maven { url 'https://www.jetbrains.com/intellij-repository/releases' } } dependencies { - intellijCore "com.jetbrains.intellij.idea:intellij-core:$ideaVersion" - ideaIC "com.jetbrains.intellij.idea:ideaIC:$ideaVersion" + intellijCore "com.jetbrains.intellij.idea:intellij-core:$idea_version" + ideaIC "com.jetbrains.intellij.idea:ideaIC:$idea_version" } def intellijCoreAnalysis() { @@ -116,17 +113,6 @@ configurations { kotlin_plugin_full } -dependencies { - final String ijVersion = "20" + ideaVersion.take(2) + "." + ideaVersion[2] - kotlin_plugin_full "teamcity:kotlin-plugin-$bundled_kotlin_compiler_version-IJ$ijVersion-1:$bundled_kotlin_compiler_version@zip" -} - -def kotlinPluginDependency() { - return zipTree(configurations.kotlin_plugin_full.singleFile).matching({ - include("Kotlin/lib/kotlin-plugin.jar") - }) -} - allprojects { diff --git a/core/build.gradle b/core/build.gradle index 697fd726..9e3026cb 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -28,12 +28,11 @@ dependencies { compile "org.jetbrains.kotlin:kotlin-compiler:$bundled_kotlin_compiler_version" compile "org.jetbrains.kotlin:kotlin-script-runtime:$bundled_kotlin_compiler_version" - compile "teamcity:kotlin-ide-common:$bundled_kotlin_compiler_version" - compile "org.jetbrains:markdown:$markdownVersion" + compile "org.jetbrains:markdown:0.1.41" compile intellijCoreAnalysis() - - compile kotlinPluginDependency() + + compile "org.jetbrains.kotlin:kotlin-plugin-ij193:$kotlin_plugin_version" //TODO: parametrize ij version after 1.3.70 compile 'org.jetbrains.kotlinx:kotlinx-html-jvm:0.6.8' diff --git a/core/src/main/kotlin/Analysis/AnalysisEnvironment.kt b/core/src/main/kotlin/Analysis/AnalysisEnvironment.kt index c816106e..f5705c89 100644 --- a/core/src/main/kotlin/Analysis/AnalysisEnvironment.kt +++ b/core/src/main/kotlin/Analysis/AnalysisEnvironment.kt @@ -3,8 +3,10 @@ package org.jetbrains.dokka import com.google.common.collect.ImmutableMap import com.intellij.core.CoreApplicationEnvironment import com.intellij.core.CoreModuleManager +import com.intellij.mock.MockApplication import com.intellij.mock.MockComponentManager import com.intellij.openapi.Disposable +import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.extensions.Extensions import com.intellij.openapi.module.Module import com.intellij.openapi.module.ModuleManager @@ -16,16 +18,13 @@ import com.intellij.openapi.util.Disposer import com.intellij.openapi.vfs.StandardFileSystems import com.intellij.psi.PsiElement import com.intellij.psi.search.GlobalSearchScope -import com.intellij.util.io.URLUtil -import org.jetbrains.dokka.Analysis.DokkaJsAnalyzerFacade -import org.jetbrains.dokka.Analysis.DokkaNativeAnalyzerFacade import org.jetbrains.kotlin.analyzer.* import org.jetbrains.kotlin.analyzer.common.CommonAnalysisParameters -import org.jetbrains.kotlin.analyzer.common.CommonAnalyzerFacade +import org.jetbrains.kotlin.analyzer.common.CommonPlatformAnalyzerServices +import org.jetbrains.kotlin.analyzer.common.CommonResolverForModuleFactory import org.jetbrains.kotlin.builtins.DefaultBuiltIns import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.jvm.JvmBuiltIns -import org.jetbrains.kotlin.caches.project.LibraryModuleInfo import org.jetbrains.kotlin.caches.resolve.KotlinCacheService import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys import org.jetbrains.kotlin.cli.common.config.ContentRoot @@ -42,20 +41,36 @@ import org.jetbrains.kotlin.config.* import org.jetbrains.kotlin.container.getService import org.jetbrains.kotlin.container.tryGetService import org.jetbrains.kotlin.context.ProjectContext +import org.jetbrains.kotlin.context.withModule import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor +import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl +import org.jetbrains.kotlin.ide.konan.NativeLibraryInfo +import org.jetbrains.kotlin.ide.konan.analyzer.NativeResolverForModuleFactory +import org.jetbrains.kotlin.ide.konan.decompiler.KotlinNativeLoadingMetadataCache import org.jetbrains.kotlin.idea.resolve.ResolutionFacade import org.jetbrains.kotlin.js.config.JSConfigurationKeys -import org.jetbrains.kotlin.js.resolve.JsPlatform +import org.jetbrains.kotlin.js.resolve.JsPlatformAnalyzerServices +import org.jetbrains.kotlin.js.resolve.JsResolverForModuleFactory +import org.jetbrains.kotlin.library.impl.createKotlinLibrary import org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.platform.CommonPlatforms +import org.jetbrains.kotlin.platform.TargetPlatform +import org.jetbrains.kotlin.platform.js.JsPlatforms +import org.jetbrains.kotlin.platform.jvm.JvmPlatforms +import org.jetbrains.kotlin.platform.jvm.JvmPlatforms.unspecifiedJvmPlatform +import org.jetbrains.kotlin.platform.konan.KonanPlatforms import org.jetbrains.kotlin.psi.* -import org.jetbrains.kotlin.resolve.* +import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.BindingTrace +import org.jetbrains.kotlin.resolve.CompilerEnvironment +import org.jetbrains.kotlin.resolve.PlatformDependentAnalyzerServices import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics -import org.jetbrains.kotlin.resolve.jvm.JvmAnalyzerFacade import org.jetbrains.kotlin.resolve.jvm.JvmPlatformParameters -import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform -import org.jetbrains.kotlin.resolve.konan.platform.KonanPlatform +import org.jetbrains.kotlin.resolve.jvm.JvmResolverForModuleFactory +import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatformAnalyzerServices +import org.jetbrains.kotlin.resolve.konan.platform.NativePlatformAnalyzerServices import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.resolve.lazy.ResolveSession import org.jetbrains.kotlin.types.KotlinType @@ -63,6 +78,9 @@ import org.jetbrains.kotlin.util.slicedMap.ReadOnlySlice import org.jetbrains.kotlin.util.slicedMap.WritableSlice import java.io.File +const val JAR_SEPARATOR = "!/" +const val KLIB_EXTENSION = "klib" + /** * Kotlin as a service entry point * @@ -86,65 +104,83 @@ class AnalysisEnvironment(val messageCollector: MessageCollector, val analysisPl Platform.native -> EnvironmentConfigFiles.NATIVE_CONFIG_FILES Platform.js -> EnvironmentConfigFiles.JS_CONFIG_FILES } + val environment = KotlinCoreEnvironment.createForProduction(this, configuration, configFiles) val projectComponentManager = environment.project as MockComponentManager - val projectFileIndex = CoreProjectFileIndex(environment.project, - environment.configuration.getList(CLIConfigurationKeys.CONTENT_ROOTS)) - + val projectFileIndex = CoreProjectFileIndex( + environment.project, + environment.configuration.getList(CLIConfigurationKeys.CONTENT_ROOTS) + ) val moduleManager = object : CoreModuleManager(environment.project, this) { override fun getModules(): Array<out Module> = arrayOf(projectFileIndex.module) } - CoreApplicationEnvironment.registerComponentInstance(projectComponentManager.picoContainer, - ModuleManager::class.java, moduleManager) + CoreApplicationEnvironment.registerComponentInstance( + projectComponentManager.picoContainer, + ModuleManager::class.java, moduleManager + ) Extensions.registerAreaClass("IDEA_MODULE", null) - CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), - OrderEnumerationHandler.EP_NAME, OrderEnumerationHandler.Factory::class.java) + CoreApplicationEnvironment.registerExtensionPoint( + Extensions.getRootArea(), + OrderEnumerationHandler.EP_NAME, OrderEnumerationHandler.Factory::class.java + ) + + projectComponentManager.registerService( + ProjectFileIndex::class.java, + projectFileIndex + ) + + projectComponentManager.registerService( + ProjectRootManager::class.java, + CoreProjectRootManager(projectFileIndex) + ) - projectComponentManager.registerService(ProjectFileIndex::class.java, - projectFileIndex) - projectComponentManager.registerService(ProjectRootManager::class.java, - CoreProjectRootManager(projectFileIndex)) return environment } - fun createSourceModuleSearchScope(project: Project, sourceFiles: List<KtFile>): GlobalSearchScope = + private fun createSourceModuleSearchScope(project: Project, sourceFiles: List<KtFile>): GlobalSearchScope = when (analysisPlatform) { Platform.jvm -> TopDownAnalyzerFacadeForJVM.newModuleSearchScope(project, sourceFiles) - Platform.js, Platform.common, Platform.native -> GlobalSearchScope.filesScope(project, sourceFiles.map { it.virtualFile }.toSet()) + Platform.js, Platform.common, Platform.native -> GlobalSearchScope.filesScope( + project, + sourceFiles.map { it.virtualFile }.toSet() + ) } - fun createResolutionFacade(environment: KotlinCoreEnvironment): Pair<DokkaResolutionFacade, DokkaResolutionFacade> { - - val projectContext = ProjectContext(environment.project) + val projectContext = ProjectContext(environment.project, "Dokka") val sourceFiles = environment.getSourceFiles() val targetPlatform = when (analysisPlatform) { - Platform.js -> JsPlatform - Platform.common -> TargetPlatform.Common - Platform.native -> KonanPlatform - Platform.jvm -> JvmPlatform + Platform.js -> JsPlatforms.defaultJsPlatform + Platform.common -> CommonPlatforms.defaultCommonPlatform + Platform.native -> KonanPlatforms.defaultKonanPlatform + Platform.jvm -> JvmPlatforms.defaultJvmPlatform } - val library = object : LibraryModuleInfo { - override val platform: TargetPlatform - get() = targetPlatform - - override fun getLibraryRoots(): Collection<String> { - return classpath.map { it.absolutePath } - } + val nativeLibraries = classpath.filter { it.extension == KLIB_EXTENSION } + .map { createNativeLibraryModuleInfo(it) } + val library = object : LibraryModuleInfo { + override val analyzerServices: PlatformDependentAnalyzerServices = + analysisPlatform.analyzerServices() override val name: Name = Name.special("<library>") + override val platform: TargetPlatform = targetPlatform override fun dependencies(): List<ModuleInfo> = listOf(this) + override fun getLibraryRoots(): Collection<String> = + classpath.filterNot { it.extension == KLIB_EXTENSION }.map { it.absolutePath } } + val module = object : ModuleInfo { + override val analyzerServices: PlatformDependentAnalyzerServices = + analysisPlatform.analyzerServices() override val name: Name = Name.special("<module>") - override fun dependencies(): List<ModuleInfo> = listOf(this, library) + override val platform: TargetPlatform = targetPlatform + override fun dependencies(): List<ModuleInfo> = listOf(this, library) + nativeLibraries } val sourcesScope = createSourceModuleSearchScope(environment.project, sourceFiles) @@ -152,6 +188,7 @@ class AnalysisEnvironment(val messageCollector: MessageCollector, val analysisPl when (it) { library -> ModuleContent(it, emptyList(), GlobalSearchScope.notScope(sourcesScope)) module -> ModuleContent(it, emptyList(), GlobalSearchScope.allScope(environment.project)) + in nativeLibraries -> ModuleContent(it, emptyList(), GlobalSearchScope.notScope(sourcesScope)) else -> throw IllegalArgumentException("Unexpected module info") } } @@ -160,20 +197,39 @@ class AnalysisEnvironment(val messageCollector: MessageCollector, val analysisPl val resolverForProject = when (analysisPlatform) { Platform.jvm -> { - builtIns = JvmBuiltIns(projectContext.storageManager) - createJvmResolverForProject(projectContext, module, library, modulesContent, sourcesScope, builtIns) + builtIns = JvmBuiltIns( + projectContext.storageManager, + JvmBuiltIns.Kind.FROM_CLASS_LOADER + ) // TODO we should use FROM_DEPENDENCIES + createJvmResolverForProject( + projectContext, + module, + library, + modulesContent, + sourcesScope, + builtIns + ) } - Platform.common -> createCommonResolverForProject(projectContext, module, library, modulesContent, environment) + Platform.common -> createCommonResolverForProject( + projectContext, + module, + library, + modulesContent, + environment + ) Platform.js -> createJsResolverForProject(projectContext, module, library, modulesContent) Platform.native -> createNativeResolverForProject(projectContext, module, library, modulesContent) } - val resolverForLibrary = resolverForProject.resolverForModule(library) // Required before module to initialize library properly - val resolverForModule = resolverForProject.resolverForModule(module) val libraryModuleDescriptor = resolverForProject.descriptorForModule(library) val moduleDescriptor = resolverForProject.descriptorForModule(module) builtIns?.initialize(moduleDescriptor, true) - val libraryResolutionFacade = DokkaResolutionFacade(environment.project, libraryModuleDescriptor, resolverForLibrary) + + val resolverForLibrary = + resolverForProject.resolverForModule(library) // Required before module to initialize library properly + val resolverForModule = resolverForProject.resolverForModule(module) + val libraryResolutionFacade = + DokkaResolutionFacade(environment.project, libraryModuleDescriptor, resolverForLibrary) val created = DokkaResolutionFacade(environment.project, moduleDescriptor, resolverForModule) val projectComponentManager = environment.project as MockComponentManager projectComponentManager.registerService(KotlinCacheService::class.java, CoreKotlinCacheService(created)) @@ -181,29 +237,64 @@ class AnalysisEnvironment(val messageCollector: MessageCollector, val analysisPl return created to libraryResolutionFacade } + private fun Platform.analyzerServices() = when (this) { + Platform.js -> JsPlatformAnalyzerServices + Platform.common -> CommonPlatformAnalyzerServices + Platform.native -> NativePlatformAnalyzerServices + Platform.jvm -> JvmPlatformAnalyzerServices + } + + private fun createNativeLibraryModuleInfo(libraryFile: File): LibraryModuleInfo { + val kotlinLibrary = createKotlinLibrary(org.jetbrains.kotlin.konan.file.File(libraryFile.absolutePath), false) + return object : LibraryModuleInfo { + override val analyzerServices: PlatformDependentAnalyzerServices = + analysisPlatform.analyzerServices() + override val name: Name = Name.special("<klib>") + override val platform: TargetPlatform = KonanPlatforms.defaultKonanPlatform + override fun dependencies(): List<ModuleInfo> = listOf(this) + override fun getLibraryRoots(): Collection<String> = listOf(libraryFile.absolutePath) + override val capabilities: Map<ModuleDescriptor.Capability<*>, Any?> + get() = super.capabilities + (NativeLibraryInfo.NATIVE_LIBRARY_CAPABILITY to kotlinLibrary) + } + } + private fun createCommonResolverForProject( projectContext: ProjectContext, module: ModuleInfo, library: LibraryModuleInfo, modulesContent: (ModuleInfo) -> ModuleContent<ModuleInfo>, environment: KotlinCoreEnvironment - ): ResolverForProjectImpl<ModuleInfo> { - return ResolverForProjectImpl( - debugName = "Dokka", - projectContext = projectContext, - modules = listOf(module, library), - modulesContent = modulesContent, - modulePlatforms = { MultiTargetPlatform.Common }, - modul |
