diff options
author | Marcin Aman <marcin.aman@gmail.com> | 2020-12-03 11:28:59 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-03 11:28:59 +0100 |
commit | 80d8991fc572bd145e873ae368dca0b201e069cf (patch) | |
tree | 56addb1dec1817087dafbe9e55bbe6149c577073 /kotlin-analysis/src/main/kotlin/org/jetbrains/dokka | |
parent | 166b4e69854e238c5b7f0a0d999825312129c24f (diff) | |
download | dokka-80d8991fc572bd145e873ae368dca0b201e069cf.tar.gz dokka-80d8991fc572bd145e873ae368dca0b201e069cf.tar.bz2 dokka-80d8991fc572bd145e873ae368dca0b201e069cf.zip |
Bump compiler to 1.4.20, IJ to 201 and coroutines to 1.4.1 (#1641)
Diffstat (limited to 'kotlin-analysis/src/main/kotlin/org/jetbrains/dokka')
5 files changed, 23 insertions, 135 deletions
diff --git a/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/AnalysisEnvironment.kt b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/AnalysisEnvironment.kt index cb65b168..d516d57d 100644 --- a/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/AnalysisEnvironment.kt +++ b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/AnalysisEnvironment.kt @@ -170,7 +170,8 @@ class AnalysisEnvironment(val messageCollector: MessageCollector, val analysisPl JvmIdePlatformKind, JsIdePlatformKind, NativeIdePlatformKind - ) + ), + this ) registerExtensionPoint( @@ -180,7 +181,8 @@ class AnalysisEnvironment(val messageCollector: MessageCollector, val analysisPl JvmPlatformKindResolution(), JsPlatformKindResolution(), NativePlatformKindResolution() - ) + ), + this ) return environment @@ -563,13 +565,14 @@ class AnalysisEnvironment(val messageCollector: MessageCollector, val analysisPl companion object { private fun <T : Any> registerExtensionPoint( appExtension: ApplicationExtensionDescriptor<T>, - instances: List<T> + instances: List<T>, + disposable: Disposable ) { if (Extensions.getRootArea().hasExtensionPoint(appExtension.extensionPointName)) return appExtension.registerExtensionPoint() - instances.forEach(appExtension::registerExtension) + instances.forEach { extension -> appExtension.registerExtension(extension, disposable) } } } } diff --git a/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/CoreProjectFileIndex.kt b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/CoreProjectFileIndex.kt index 346a305e..77be818c 100644 --- a/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/CoreProjectFileIndex.kt +++ b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/CoreProjectFileIndex.kt @@ -508,6 +508,10 @@ class CoreProjectRootManager(val projectFileIndex: CoreProjectFileIndex) : Proje throw UnsupportedOperationException() } + override fun setProjectSdkName(p0: String, p1: String) { + throw UnsupportedOperationException() + } + override fun getModuleSourceRoots(p0: MutableSet<out JpsModuleSourceRootType<*>>): MutableList<VirtualFile> { throw UnsupportedOperationException() } @@ -522,6 +526,10 @@ class CoreProjectRootManager(val projectFileIndex: CoreProjectFileIndex) : Proje throw UnsupportedOperationException() } + override fun getProjectSdkTypeName(): String? { + throw UnsupportedOperationException() + } + override fun getProjectSdk(): Sdk? { throw UnsupportedOperationException() } diff --git a/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/DokkaNativeKlibLibraryInfo.kt b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/DokkaNativeKlibLibraryInfo.kt index a5ee5217..0b56f187 100644 --- a/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/DokkaNativeKlibLibraryInfo.kt +++ b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/DokkaNativeKlibLibraryInfo.kt @@ -5,6 +5,7 @@ import org.jetbrains.kotlin.analyzer.ModuleInfo import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.konan.DeserializedKlibModuleOrigin import org.jetbrains.kotlin.descriptors.konan.KlibModuleOrigin +import org.jetbrains.kotlin.descriptors.ModuleCapability import org.jetbrains.kotlin.idea.klib.safeRead import org.jetbrains.kotlin.library.KotlinLibrary import org.jetbrains.kotlin.library.isInterop @@ -38,11 +39,11 @@ internal class DokkaNativeKlibLibraryInfo( override fun dependencies(): List<ModuleInfo> = listOf(this) + dependencyResolver.resolveDependencies(this) override fun getLibraryRoots(): Collection<String> = listOf(libraryRoot) - override val capabilities: Map<ModuleDescriptor.Capability<*>, Any?> + override val capabilities: Map<ModuleCapability<*>, Any?> get() { val capabilities = super.capabilities.toMutableMap() - capabilities += KlibModuleOrigin.CAPABILITY to DeserializedKlibModuleOrigin(kotlinLibrary) - capabilities += ImplicitIntegerCoercion.MODULE_CAPABILITY to kotlinLibrary.safeRead(false) { isInterop } + capabilities[KlibModuleOrigin.CAPABILITY] = DeserializedKlibModuleOrigin(kotlinLibrary) + capabilities[ImplicitIntegerCoercion.MODULE_CAPABILITY] = kotlinLibrary.safeRead(false) { isInterop } return capabilities } } diff --git a/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/DokkaResolutionFacade.kt b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/DokkaResolutionFacade.kt index 6bf4990c..2c19fb9f 100644 --- a/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/DokkaResolutionFacade.kt +++ b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/DokkaResolutionFacade.kt @@ -1,3 +1,5 @@ +@file:OptIn(FrontendInternals::class) + package org.jetbrains.dokka.analysis import com.google.common.collect.ImmutableMap @@ -11,6 +13,7 @@ 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.idea.FrontendInternals import org.jetbrains.kotlin.idea.resolve.ResolutionFacade import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.psi.KtElement @@ -34,6 +37,7 @@ class DokkaResolutionFacade( throw UnsupportedOperationException() } + @OptIn(FrontendInternals::class) override fun <T : Any> tryGetFrontendService(element: PsiElement, serviceClass: Class<T>): T? { return resolverForModule.componentProvider.tryGetService(serviceClass) } diff --git a/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/JavaResolveExtension.kt b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/JavaResolveExtension.kt deleted file mode 100644 index ab6bec9c..00000000 --- a/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/JavaResolveExtension.kt +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@file:JvmName("JavaResolutionUtils") - -package org.jetbrains.dokka.analysis - -import com.intellij.psi.* -import org.jetbrains.kotlin.asJava.unwrapped -import org.jetbrains.kotlin.caches.resolve.KotlinCacheService -import org.jetbrains.kotlin.descriptors.* -import org.jetbrains.kotlin.idea.resolve.ResolutionFacade -import org.jetbrains.kotlin.incremental.components.NoLookupLocation -import org.jetbrains.kotlin.load.java.sources.JavaSourceElement -import org.jetbrains.kotlin.load.java.structure.* -import org.jetbrains.kotlin.load.java.structure.impl.* -import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.platform.jvm.JvmPlatforms -import org.jetbrains.kotlin.psi.KtDeclaration -import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolver -import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter -import org.jetbrains.kotlin.resolve.scopes.MemberScope - -// TODO: Remove that file - -@JvmOverloads -fun PsiMethod.getJavaMethodDescriptor(resolutionFacade: ResolutionFacade = javaResolutionFacade()): DeclarationDescriptor? { - val method = originalElement as? PsiMethod ?: return null - if (method.containingClass == null || !Name.isValidIdentifier(method.name)) return null - val resolver = method.getJavaDescriptorResolver(resolutionFacade) - return when { - method.isConstructor -> resolver?.resolveConstructor(JavaConstructorImpl(method)) - else -> resolver?.resolveMethod(JavaMethodImpl(method)) - } -} - -@JvmOverloads -fun PsiClass.getJavaClassDescriptor(resolutionFacade: ResolutionFacade = javaResolutionFacade()): ClassDescriptor? { - val psiClass = originalElement as? PsiClass ?: return null - return psiClass.getJavaDescriptorResolver(resolutionFacade)?.resolveClass(JavaClassImpl(psiClass)) -} - -@JvmOverloads -fun PsiField.getJavaFieldDescriptor(resolutionFacade: ResolutionFacade = javaResolutionFacade()): PropertyDescriptor? { - val field = originalElement as? PsiField ?: return null - return field.getJavaDescriptorResolver(resolutionFacade)?.resolveField(JavaFieldImpl(field)) -} - -@JvmOverloads -fun PsiMember.getJavaMemberDescriptor(resolutionFacade: ResolutionFacade = javaResolutionFacade()): DeclarationDescriptor? { - return when (this) { - is PsiEnumConstant -> containingClass?.getJavaClassDescriptor(resolutionFacade) - is PsiClass -> getJavaClassDescriptor(resolutionFacade) - is PsiMethod -> getJavaMethodDescriptor(resolutionFacade) - is PsiField -> getJavaFieldDescriptor(resolutionFacade) - else -> null - } -} - -@JvmOverloads -fun PsiMember.getJavaOrKotlinMemberDescriptor(resolutionFacade: ResolutionFacade = javaResolutionFacade()): DeclarationDescriptor? { - val callable = unwrapped - return when (callable) { - is PsiMember -> getJavaMemberDescriptor(resolutionFacade) - is KtDeclaration -> { - val descriptor = resolutionFacade.resolveToDescriptor(callable) - if (descriptor is ClassDescriptor && this is PsiMethod) descriptor.unsubstitutedPrimaryConstructor else descriptor - } - else -> null - } -} - -private fun PsiElement.getJavaDescriptorResolver(resolutionFacade: ResolutionFacade): JavaDescriptorResolver? { - return resolutionFacade.tryGetFrontendService(this, JavaDescriptorResolver::class.java) -} - -private fun JavaDescriptorResolver.resolveMethod(method: JavaMethod): DeclarationDescriptor? { - return getContainingScope(method) - ?.getContributedDescriptors(nameFilter = { true }, kindFilter = DescriptorKindFilter.CALLABLES) - ?.filterIsInstance<DeclarationDescriptorWithSource>() - ?.findByJavaElement(method) -} - -private fun JavaDescriptorResolver.resolveConstructor(constructor: JavaConstructor): ConstructorDescriptor? { - return resolveClass(constructor.containingClass)?.constructors?.findByJavaElement(constructor) -} - -private fun JavaDescriptorResolver.resolveField(field: JavaField): PropertyDescriptor? { - return getContainingScope(field)?.getContributedVariables(field.name, NoLookupLocation.FROM_IDE)?.findByJavaElement(field) -} - -private fun JavaDescriptorResolver.getContainingScope(member: JavaMember): MemberScope? { - val containingClass = resolveClass(member.containingClass) - return if (member.isStatic) - containingClass?.staticScope - else - containingClass?.defaultType?.memberScope -} - -private fun <T : DeclarationDescriptorWithSource> Collection<T>.findByJavaElement(javaElement: JavaElement): T? { - return firstOrNull { member -> - val memberJavaElement = (member.original.source as? JavaSourceElement)?.javaElement - when { - memberJavaElement == javaElement -> - true - memberJavaElement is JavaElementImpl<*> && javaElement is JavaElementImpl<*> -> - memberJavaElement.psi.isEquivalentTo(javaElement.psi) - else -> - false - } - } -} - -fun PsiElement.javaResolutionFacade() = - KotlinCacheService.getInstance(project).getResolutionFacadeByFile(this.originalElement.containingFile, JvmPlatforms.defaultJvmPlatform)!! |