aboutsummaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/kotlin/Analysis/AnalysisEnvironment.kt97
-rw-r--r--core/src/main/kotlin/Analysis/CoreKotlinCacheService.kt18
-rw-r--r--core/src/main/kotlin/Analysis/CoreProjectFileIndex.kt28
-rw-r--r--core/src/main/kotlin/Analysis/JavaResolveExtension.kt7
-rw-r--r--core/src/main/kotlin/Formats/DacHtmlFormat.kt3
-rw-r--r--core/src/main/kotlin/Formats/JavaLayoutHtml/JavaLayoutHtmlFormat.kt8
-rw-r--r--core/src/main/kotlin/Formats/JavaLayoutHtml/JavaLayoutHtmlFormatOutputBuilder.kt5
-rw-r--r--core/src/main/kotlin/Formats/JavaLayoutHtml/JavaLayoutHtmlGenerator.kt6
-rw-r--r--core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt11
-rw-r--r--core/src/main/kotlin/Java/JavadocParser.kt24
-rw-r--r--core/src/main/kotlin/Kotlin/DocumentationBuilder.kt20
-rw-r--r--core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt6
-rw-r--r--core/src/main/kotlin/Kotlin/KotlinLanguageService.kt2
-rw-r--r--core/src/main/kotlin/Languages/NewJavaLanguageService.kt4
-rw-r--r--core/src/main/kotlin/Model/DocumentationNode.kt29
-rw-r--r--core/src/test/kotlin/javadoc/JavadocTest.kt6
-rw-r--r--core/src/test/kotlin/model/ClassTest.kt2
-rw-r--r--core/src/test/kotlin/model/FunctionTest.kt14
18 files changed, 202 insertions, 88 deletions
diff --git a/core/src/main/kotlin/Analysis/AnalysisEnvironment.kt b/core/src/main/kotlin/Analysis/AnalysisEnvironment.kt
index b47f8bdb1..9fea67407 100644
--- a/core/src/main/kotlin/Analysis/AnalysisEnvironment.kt
+++ b/core/src/main/kotlin/Analysis/AnalysisEnvironment.kt
@@ -15,9 +15,13 @@ import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.vfs.StandardFileSystems
import com.intellij.psi.PsiElement
+import com.intellij.psi.impl.source.javadoc.JavadocManagerImpl
+import com.intellij.psi.javadoc.CustomJavadocTagProvider
+import com.intellij.psi.javadoc.JavadocManager
+import com.intellij.psi.javadoc.JavadocTagInfo
import com.intellij.psi.search.GlobalSearchScope
-import com.intellij.util.io.URLUtil
import org.jetbrains.kotlin.analyzer.*
+import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.jvm.JvmBuiltIns
import org.jetbrains.kotlin.caches.resolve.KotlinCacheService
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
@@ -35,19 +39,25 @@ 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.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl
import org.jetbrains.kotlin.name.Name
+import org.jetbrains.kotlin.platform.TargetPlatform
+import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
+import org.jetbrains.kotlin.platform.konan.KonanPlatforms
import org.jetbrains.kotlin.psi.*
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.jvm.JvmResolverForModuleFactory
+import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatformAnalyzerServices
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
import org.jetbrains.kotlin.types.KotlinType
@@ -89,10 +99,19 @@ class AnalysisEnvironment(val messageCollector: MessageCollector) : Disposable {
CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(),
OrderEnumerationHandler.EP_NAME, OrderEnumerationHandler.Factory::class.java)
+ CoreApplicationEnvironment.registerExtensionPoint(Extensions.getArea(environment.project),
+ JavadocTagInfo.EP_NAME, JavadocTagInfo::class.java)
+ CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(),
+ CustomJavadocTagProvider.EP_NAME, CustomJavadocTagProvider::class.java)
+
projectComponentManager.registerService(ProjectFileIndex::class.java,
projectFileIndex)
projectComponentManager.registerService(ProjectRootManager::class.java,
CoreProjectRootManager(projectFileIndex))
+ projectComponentManager.registerService(JavadocManager::class.java,
+ JavadocManagerImpl(environment.project))
+ projectComponentManager.registerService(CustomJavadocTagProvider::class.java,
+ CustomJavadocTagProvider { emptyList() })
return environment
}
@@ -104,29 +123,40 @@ class AnalysisEnvironment(val messageCollector: MessageCollector) : Disposable {
fun createResolutionFacade(environment: KotlinCoreEnvironment): Pair<DokkaResolutionFacade, DokkaResolutionFacade> {
- val projectContext = ProjectContext(environment.project)
+ val projectContext = ProjectContext(environment.project, "Dokka")
val sourceFiles = environment.getSourceFiles()
val library = object : ModuleInfo {
override val name: Name = Name.special("<library>")
+ override val platform: TargetPlatform
+ get() = JvmPlatforms.defaultJvmPlatform
+ override val analyzerServices: PlatformDependentAnalyzerServices =
+ JvmPlatformAnalyzerServices
override fun dependencies(): List<ModuleInfo> = listOf(this)
}
val module = object : ModuleInfo {
override val name: Name = Name.special("<module>")
+ override val platform: TargetPlatform
+ get() = JvmPlatforms.defaultJvmPlatform
+ override val analyzerServices: PlatformDependentAnalyzerServices =
+ JvmPlatformAnalyzerServices
override fun dependencies(): List<ModuleInfo> = listOf(this, library)
}
val sourcesScope = createSourceModuleSearchScope(environment.project, sourceFiles)
- val builtIns = JvmBuiltIns(projectContext.storageManager)
+ val builtIns = JvmBuiltIns(
+ projectContext.storageManager,
+ JvmBuiltIns.Kind.FROM_CLASS_LOADER
+ )
val javaRoots = classpath
.mapNotNull {
val rootFile = when {
it.extension == "jar" ->
- StandardFileSystems.jar().findFileByPath("${it.absolutePath}${URLUtil.JAR_SEPARATOR}")
+ StandardFileSystems.jar().findFileByPath("${it.absolutePath}${"!/"}")
else ->
StandardFileSystems.local().findFileByPath(it.absolutePath)
}
@@ -134,38 +164,51 @@ class AnalysisEnvironment(val messageCollector: MessageCollector) : Disposable {
rootFile?.let { JavaRoot(it, JavaRoot.RootType.BINARY) }
}
- val resolverForProject = ResolverForProjectImpl(
+ val resolverForProject = object : AbstractResolverForProject<ModuleInfo>(
"Dokka",
projectContext,
- listOf(library, module),
- {
- when (it) {
- library -> ModuleContent(it, emptyList(), GlobalSearchScope.notScope(sourcesScope))
- module -> ModuleContent(it, emptyList(), sourcesScope)
+ modules = listOf(module, library)
+ ) {
+ override fun modulesContent(module: ModuleInfo): ModuleContent<ModuleInfo> =
+ when (module) {
+ library -> ModuleContent(module, emptyList(), GlobalSearchScope.notScope(sourcesScope))
+ module -> ModuleContent(module, emptyList(), sourcesScope)
else -> throw IllegalArgumentException("Unexpected module info")
}
- },
- {
- JvmPlatform.multiTargetPlatform
- },
- LanguageSettingsProvider.Default /* TODO: Fix this */,
- { JvmAnalyzerFacade },
- {
+
+ override fun builtInsForModule(module: ModuleInfo): KotlinBuiltIns = builtIns
+
+ override fun createResolverForModule(
+ descriptor: ModuleDescriptor,
+ moduleInfo: ModuleInfo
+ ): ResolverForModule = JvmResolverForModuleFactory(
JvmPlatformParameters({ content ->
- JvmPackagePartProvider(configuration.languageVersionSettings, content.moduleContentScope).apply {
- addRoots(javaRoots, messageCollector)
- }
+ JvmPackagePartProvider(
+ configuration.languageVersionSettings,
+ content.moduleContentScope
+ )
+ .apply {
+ addRoots(javaRoots, messageCollector)
+ }
}, {
val file = (it as JavaClassImpl).psi.containingFile.virtualFile
if (file in sourcesScope)
module
else
library
- })
- },
- CompilerEnvironment,
- builtIns = builtIns
- )
+ }),
+ CompilerEnvironment,
+ KonanPlatforms.defaultKonanPlatform
+ ).createResolverForModule(
+ descriptor as ModuleDescriptorImpl,
+ projectContext.withModule(descriptor),
+ modulesContent(moduleInfo),
+ this,
+ LanguageVersionSettingsImpl.DEFAULT
+ )
+
+ override fun sdkDependency(module: ModuleInfo): ModuleInfo? = null
+ }
val resolverForLibrary = resolverForProject.resolverForModule(library) // Required before module to initialize library properly
val resolverForModule = resolverForProject.resolverForModule(module)
diff --git a/core/src/main/kotlin/Analysis/CoreKotlinCacheService.kt b/core/src/main/kotlin/Analysis/CoreKotlinCacheService.kt
index 31b8ffc76..d9093760c 100644
--- a/core/src/main/kotlin/Analysis/CoreKotlinCacheService.kt
+++ b/core/src/main/kotlin/Analysis/CoreKotlinCacheService.kt
@@ -5,7 +5,6 @@ import org.jetbrains.kotlin.analyzer.ModuleInfo
import org.jetbrains.kotlin.caches.resolve.KotlinCacheService
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.psi.KtElement
-import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.resolve.diagnostics.KotlinSuppressCache
@@ -14,11 +13,24 @@ class CoreKotlinCacheService(private val resolutionFacade: DokkaResolutionFacade
return resolutionFacade
}
- override fun getResolutionFacadeByFile(file: PsiFile, platform: TargetPlatform): ResolutionFacade {
+ override fun getResolutionFacade(
+ elements: List<KtElement>,
+ platform: org.jetbrains.kotlin.platform.TargetPlatform
+ ): ResolutionFacade {
return resolutionFacade
}
- override fun getResolutionFacadeByModuleInfo(moduleInfo: ModuleInfo, platform: TargetPlatform): ResolutionFacade? {
+ override fun getResolutionFacadeByFile(
+ file: PsiFile,
+ platform: org.jetbrains.kotlin.platform.TargetPlatform
+ ): ResolutionFacade? {
+ return resolutionFacade
+ }
+
+ override fun getResolutionFacadeByModuleInfo(
+ moduleInfo: ModuleInfo,
+ platform: org.jetbrains.kotlin.platform.TargetPlatform
+ ): ResolutionFacade? {
return resolutionFacade
}
diff --git a/core/src/main/kotlin/Analysis/CoreProjectFileIndex.kt b/core/src/main/kotlin/Analysis/CoreProjectFileIndex.kt
index 319d85b14..4ece8d300 100644
--- a/core/src/main/kotlin/Analysis/CoreProjectFileIndex.kt
+++ b/core/src/main/kotlin/Analysis/CoreProjectFileIndex.kt
@@ -15,6 +15,7 @@ import com.intellij.openapi.util.Condition
import com.intellij.openapi.util.Key
import com.intellij.openapi.util.UserDataHolderBase
import com.intellij.openapi.vfs.StandardFileSystems
+import com.intellij.openapi.vfs.VfsUtilCore.getVirtualFileForJar
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.VirtualFileFilter
import com.intellij.psi.search.GlobalSearchScope
@@ -166,9 +167,8 @@ class CoreProjectFileIndex(private val project: Project, contentRoots: List<Cont
private val sdk: Sdk = object : Sdk, RootProvider {
override fun getFiles(rootType: OrderRootType): Array<out VirtualFile> = classpathRoots
- .map { StandardFileSystems.local().findFileByPath(it.file.path) }
- .filterNotNull()
- .toTypedArray()
+ .mapNotNull { StandardFileSystems.local().findFileByPath(it.file.path) }
+ .toTypedArray()
override fun addRootSetChangedListener(p0: RootProvider.RootSetChangedListener) {
throw UnsupportedOperationException()
@@ -329,7 +329,7 @@ class CoreProjectFileIndex(private val project: Project, contentRoots: List<Cont
throw UnsupportedOperationException()
}
- override fun <R : Any?> processOrder(p0: RootPolicy<R>?, p1: R): R {
+ override fun <R : Any?> processOrder(p0: RootPolicy<R>, p1: R): R {
throw UnsupportedOperationException()
}
@@ -354,11 +354,11 @@ class CoreProjectFileIndex(private val project: Project, contentRoots: List<Cont
}
override fun orderEntries(): OrderEnumerator =
- ProjectOrderEnumerator(project, null).using(object : RootModelProvider {
- override fun getModules(): Array<out Module> = arrayOf(module)
+ ProjectOrderEnumerator(project, null).using(object : RootModelProvider {
+ override fun getModules(): Array<out Module> = arrayOf(module)
- override fun getRootModel(p0: Module): ModuleRootModel = this@MyModuleRootManager
- })
+ override fun getRootModel(p0: Module): ModuleRootModel = this@MyModuleRootManager
+ })
override fun <T : Any?> getModuleExtension(p0: Class<T>): T {
throw UnsupportedOperationException()
@@ -404,7 +404,7 @@ class CoreProjectFileIndex(private val project: Project, contentRoots: List<Cont
throw UnsupportedOperationException()
}
- override fun isDependsOn(p0: Module?): Boolean {
+ override fun isDependsOn(p0: Module): Boolean {
throw UnsupportedOperationException()
}
@@ -462,7 +462,7 @@ class CoreProjectFileIndex(private val project: Project, contentRoots: List<Cont
}
override fun getModuleForFile(file: VirtualFile): Module? =
- if (sourceRoots.contains(file)) module else null
+ if (sourceRoots.contains(file)) module else null
private fun List<ContentRoot>.contains(file: VirtualFile): Boolean = any { it.contains(file) }
@@ -516,7 +516,7 @@ class CoreProjectRootManager(val projectFileIndex: CoreProjectFileIndex) : Proje
throw UnsupportedOperationException()
}
- override fun getContentRootsFromAllModules(): Array<out VirtualFile>? {
+ override fun getContentRootsFromAllModules(): Array<out VirtualFile> {
throw UnsupportedOperationException()
}
@@ -524,7 +524,7 @@ class CoreProjectRootManager(val projectFileIndex: CoreProjectFileIndex) : Proje
throw UnsupportedOperationException()
}
- override fun setProjectSdkName(p0: String?) {
+ override fun setProjectSdkName(p0: String) {
throw UnsupportedOperationException()
}
@@ -559,11 +559,11 @@ class CoreProjectRootManager(val projectFileIndex: CoreProjectFileIndex) : Proje
fun ContentRoot.contains(file: VirtualFile) = when (this) {
is JvmContentRoot -> {
val path = if (file.fileSystem.protocol == StandardFileSystems.JAR_PROTOCOL)
- StandardFileSystems.getVirtualFileForJar(file)?.path ?: file.path
+ getVirtualFileForJar(file)?.path ?: file.path
else
file.path
File(path).startsWith(this.file.absoluteFile)
}
is KotlinSourceRoot -> File(file.path).startsWith(File(this.path).absoluteFile)
else -> false
-}
+} \ No newline at end of file
diff --git a/core/src/main/kotlin/Analysis/JavaResolveExtension.kt b/core/src/main/kotlin/Analysis/JavaResolveExtension.kt
index 4dc6b3662..4a4c78e56 100644
--- a/core/src/main/kotlin/Analysis/JavaResolveExtension.kt
+++ b/core/src/main/kotlin/Analysis/JavaResolveExtension.kt
@@ -19,7 +19,6 @@
package org.jetbrains.dokka
import com.intellij.psi.*
-import org.jetbrains.kotlin.asJava.classes.KtLightClass
import org.jetbrains.kotlin.asJava.unwrapped
import org.jetbrains.kotlin.caches.resolve.KotlinCacheService
import org.jetbrains.kotlin.descriptors.*
@@ -29,11 +28,9 @@ 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.psi.KtClassOrObject
+import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
import org.jetbrains.kotlin.psi.KtDeclaration
-import org.jetbrains.kotlin.psi.psiUtil.parameterIndex
import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolver
-import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.MemberScope
@@ -128,4 +125,4 @@ private fun <T : DeclarationDescriptorWithSource> Collection<T>.findByJavaElemen
}
fun PsiElement.javaResolutionFacade() =
- KotlinCacheService.getInstance(project).getResolutionFacadeByFile(this.originalElement.containingFile, JvmPlatform)!!
+ KotlinCacheService.getInstance(project).getResolutionFacadeByFile(this.originalElement.containingFile, JvmPlatforms.defaultJvmPlatform)!!
diff --git a/core/src/main/kotlin/Formats/DacHtmlFormat.kt b/core/src/main/kotlin/Formats/DacHtmlFormat.kt
index 7038a7fbe..bc6429bf5 100644
--- a/core/src/main/kotlin/Formats/DacHtmlFormat.kt
+++ b/core/src/main/kotlin/Formats/DacHtmlFormat.kt
@@ -75,7 +75,7 @@ class DevsiteLayoutHtmlFormatOutputBuilder(
attributes["data-version-added"] = node.apiLevel.name
h3(classes = "api-name") {
//id = node.signatureForAnchor(logger).urlEncoded()
- +node.name
+ +node.prettyName
}
apiAndDeprecatedVersions(node)
pre(classes = "api-signature no-pretty-print") { renderedSignature(node, LanguageService.RenderMode.FULL) }
@@ -514,6 +514,7 @@ class DevsiteLayoutHtmlFormatOutputBuilder(
bodyContent = {
h1 { +page.node.name }
nodeContent(page.node)
+ summaryNodeGroup(page.interfaces.sortedBy { it.nameWithOuterClass().toLowerCase() }, "Interfaces", headerAsRow = false) { classLikeRow(it) }
summaryNodeGroup(page.classes.sortedBy { it.nameWithOuterClass().toLowerCase() }, "Classes", headerAsRow = false) { classLikeRow(it) }
summaryNodeGroup(page.exceptions.sortedBy { it.nameWithOuterClass().toLowerCase() }, "Exceptions", headerAsRow = false) { classLikeRow(it) }
summaryNodeGroup(page.typeAliases.sortedBy { it.nameWithOuterClass().toLowerCase() }, "Type-aliases", headerAsRow = false) { classLikeRow(it) }
diff --git a/core/src/main/kotlin/Formats/JavaLayoutHtml/JavaLayoutHtmlFormat.kt b/core/src/main/kotlin/Formats/JavaLayoutHtml/JavaLayoutHtmlFormat.kt
index 66ded62a6..b94886693 100644
--- a/core/src/main/kotlin/Formats/JavaLayoutHtml/JavaLayoutHtmlFormat.kt
+++ b/core/src/main/kotlin/Formats/JavaLayoutHtml/JavaLayoutHtmlFormat.kt
@@ -70,7 +70,7 @@ interface JavaLayoutHtmlUriProvider {
}
fun mainUriOrWarn(node: DocumentationNode): URI? = tryGetMainUri(node) ?: (null).also {
- AssertionError("Not implemented mainUri for ${node.kind}").printStackTrace()
+ AssertionError("Not implemented mainUri for ${node.kind} (${node})").printStackTrace()
}
}
@@ -119,7 +119,7 @@ fun DocumentationNode.signatureForAnchor(logger: DokkaLogger): String {
append("Companion.")
}
appendReceiverIfSo()
- append(name)
+ append(prettyName)
details(NodeKind.Parameter).joinTo(this, prefix = "(", postfix = ")") { it.detail(NodeKind.Type).qualifiedNameFromType() }
}
NodeKind.Property, NodeKind.CompanionObjectProperty -> buildString {
@@ -139,7 +139,3 @@ fun DocumentationNode.signatureForAnchor(logger: DokkaLogger): String {
}
}
-fun DocumentationNode.classNodeNameWithOuterClass(): String {
- assert(kind in NodeKind.classLike)
- return path.dropWhile { it.kind == NodeKind.Package || it.kind == NodeKind.Module }.joinToString(separator = ".") { it.name }
-}
diff --git a/core/src/main/kotlin/Formats/JavaLayoutHtml/JavaLayoutHtmlFormatOutputBuilder.kt b/core/src/main/kotlin/Formats/JavaLayoutHtml/JavaLayoutHtmlFormatOutputBuilder.kt
index 23cb81a1a..f12128f64 100644
--- a/core/src/main/kotlin/Formats/JavaLayoutHtml/JavaLayoutHtmlFormatOutputBuilder.kt
+++ b/core/src/main/kotlin/Formats/JavaLayoutHtml/JavaLayoutHtmlFormatOutputBuilder.kt
@@ -253,7 +253,7 @@ open class JavaLayoutHtmlFormatOutputBuilder(
renderedSignature(receiver.detail(NodeKind.Type), SUMMARY)
+"."
}
- a(href = node) { +node.name }
+ a(href = node) { +node.prettyName }
shortFunctionParametersList(node)
}
}
@@ -392,6 +392,7 @@ open class JavaLayoutHtmlFormatOutputBuilder(
bodyContent = {
h1 { +page.node.name }
nodeContent(page.node)
+ summaryNodeGroup(page.interfaces, "Interfaces", headerAsRow = false) { classLikeRow(it) }
summaryNodeGroup(page.classes, "Classes", headerAsRow = false) { classLikeRow(it) }
summaryNodeGroup(page.exceptions, "Exceptions", headerAsRow = false) { classLikeRow(it) }
summaryNodeGroup(page.typeAliases, "Type-aliases", headerAsRow = false) { classLikeRow(it) }
@@ -1088,6 +1089,8 @@ open class JavaLayoutHtmlFormatOutputBuilder(
assert(node.kind == NodeKind.Package)
}
+ val interfaces = node.members(NodeKind.Interface) +
+ node.members(NodeKind.Class).flatMap { it.members(NodeKind.Interface) }
val classes = node.members(NodeKind.Class)
val exceptions = node.members(NodeKind.Exception)
val typeAliases = node.members(NodeKind.TypeAlias)
diff --git a/core/src/main/kotlin/Formats/JavaLayoutHtml/JavaLayoutHtmlGenerator.kt b/core/src/main/kotlin/Formats/JavaLayoutHtml/JavaLayoutHtmlGenerator.kt
index dc0df2a9e..9928a8e9e 100644
--- a/core/src/main/kotlin/Formats/JavaLayoutHtml/JavaLayoutHtmlGenerator.kt
+++ b/core/src/main/kotlin/Formats/JavaLayoutHtml/JavaLayoutHtmlGenerator.kt
@@ -32,6 +32,7 @@ class JavaLayoutHtmlFormatGenerator @Inject constructor(
return when (node.kind) {
NodeKind.Module -> URI("/").resolve(node.name + "/")
NodeKind.Package -> tryGetContainerUri(node.getOwnerOrReport())?.resolve(node.name.replace('.', '/') + '/')
+ NodeKind.GroupNode -> tryGetContainerUri(node.getOwnerOrReport())
in NodeKind.classLike -> tryGetContainerUri(node.getOwnerOrReport())?.resolve("${node.classNodeNameWithOuterClass()}.html")
else -> null
}
@@ -81,7 +82,7 @@ class JavaLayoutHtmlFormatGenerator @Inject constructor(
fun buildPackage(node: DocumentationNode, parentDir: File) {
assert(node.kind == NodeKind.Package)
- val members = node.members
+ var members = node.members
val directoryForPackage = parentDir.resolve(node.name.replace('.', File.separatorChar))
directoryForPackage.mkdirsOrFail()
@@ -89,6 +90,9 @@ class JavaLayoutHtmlFormatGenerator @Inject constructor(
createOutputBuilderForNode(node, it).generatePage(Page.PackagePage(node))
}
+ members.filter { it.kind == NodeKind.GroupNode }.forEach {
+ members += it.members
+ }
members.filter { it.kind in NodeKind.classLike }.forEach {
buildClass(it, directoryForPackage)
}
diff --git a/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt b/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt
index ed4d36687..a7df4e482 100644
--- a/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt
+++ b/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt
@@ -29,12 +29,13 @@ fun getSignature(element: PsiElement?) = when(element) {
private fun PsiType.typeSignature(): String = when(this) {
is PsiArrayType -> "Array((${componentType.typeSignature()}))"
is PsiPrimitiveType -> "kotlin." + canonicalText.capitalize()
+ is PsiClassType -> resolve()?.qualifiedName ?: className
else -> mapTypeName(this)
}
private fun mapTypeName(psiType: PsiType): String = when (psiType) {
is PsiPrimitiveType -> psiType.canonicalText
- is PsiClassType -> psiType.resolve()?.qualifiedName ?: psiType.className
+ is PsiClassType -> psiType.resolve()?.name ?: psiType.className
is PsiEllipsisType -> mapTypeName(psiType.componentType)
is PsiArrayType -> "kotlin.Array"
else -> psiType.canonicalText
@@ -119,8 +120,12 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder {
if (modifierList != null) {
modifierList.annotations.filter { !ignoreAnnotation(it) }.forEach {
val annotation = it.build()
- node.append(annotation,
- if (it.qualifiedName == "java.lang.Deprecated") RefKind.Deprecation else RefKind.Annotation)
+ if (it.qualifiedName == "java.lang.Deprecated" || it.qualifiedName == "kotlin.Deprecated") {
+ node.append(annotation, RefKind.Deprecation)
+ annotation.convertDeprecationDetailsToChildren()
+ } else {
+ node.append(annotation, RefKind.Annotation)
+ }
}
}
}
diff --git a/core/src/main/kotlin/Java/JavadocParser.kt b/core/src/main/kotlin/Java/JavadocParser.kt
index 04de29087..21cc2bbdf 100644
--- a/core/src/main/kotlin/Java/JavadocParser.kt
+++ b/core/src/main/kotlin/Java/JavadocParser.kt
@@ -1,12 +1,11 @@
package org.jetbrains.dokka
import com.intellij.psi.*
-import com.intellij.psi.impl.source.javadoc.CorePsiDocTagValueImpl
+import com.intellij.psi.impl.source.javadoc.PsiDocTagValueImpl
import com.intellij.psi.impl.source.tree.JavaDocElementType
import com.intellij.psi.javadoc.*
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.util.IncorrectOperationException
-import com.intellij.util.containers.isNullOrEmpty
import org.jetbrains.dokka.Model.CodeNode
import org.jetbrains.kotlin.utils.join
import org.jetbrains.kotlin.utils.keysToMap
@@ -172,7 +171,7 @@ class JavadocParser(
fun PsiDocTag.getApiLevel(): String? {
if (dataElements.isNotEmpty()) {
val data = dataElements
- if (data[0] is CorePsiDocTagValueImpl) {
+ if (data[0] is PsiDocTagValueImpl) {
val docTagValue = data[0]
if (docTagValue.firstChild != null) {
val apiLevel = docTagValue.firstChild
@@ -420,11 +419,12 @@ class JavadocParser(
linkNode
}
linkSignature != null -> {
+ @Suppress("USELESS_CAST")
+ val signature: String = linkSignature as String
val linkNode =
ContentNodeLazyLink(
- (tag.valueElement ?: linkElement).text,
- { -> refGraph.lookupOrWarn(linkSignature, logger) }
- )
+ (tag.valueElement ?: linkElement).text
+ ) { refGraph.lookupOrWarn(signature, logger) }
linkNode.append(text)
linkNode
}
@@ -439,7 +439,13 @@ class JavadocParser(
val externalLink = resolveExternalLink(valueElement)
val linkSignature by lazy { resolveInternalLink(valueElement) }
if (externalLink != null || linkSignature != null) {
- val labelText = tag.dataElements.firstOrNull { it is PsiDocToken }?.text ?: valueElement!!.text
+
+ // sometimes `dataElements` contains multiple `PsiDocToken` elements and some have whitespace in them
+ // this is best effort to find the first non-empty one before falling back to using the symbol name.
+ val labelText = tag.dataElements.firstOrNull {
+ it is PsiDocToken && it.text?.trim()?.isNotEmpty() ?: false
+ }?.text ?: valueElement!!.text
+
val linkTarget = if (externalLink != null) "href=\"$externalLink\"" else "docref=\"$linkSignature\""
val link = "<a $linkTarget>$labelText</a>"
if (tag.name == "link") "<code>$link</code>" else link
@@ -560,7 +566,7 @@ class JavadocParser(
val superMethods = current.findSuperMethods()
for (method in superMethods) {
val docs = method.docComment?.descriptionElements?.dropWhile { it.text.trim().isEmpty() }
- if (!docs.isNullOrEmpty()) {
+ if (docs?.isNotEmpty() == true) {
return method
}
}
@@ -648,7 +654,7 @@ class JavadocParser(
appendContentBetweenIncludes(path, betweenTag)
}
} catch (e: java.lang.Exception) {
- logger.error("No file found when processing Java @sample. Path to sample: $path")
+ logger.error("No file found when processing Java @sample. Path to sample: $path\n")
}
}
diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt
index 0b5e74339..b9fe8483e 100644
--- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt
+++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotated
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
+import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.EnumEntrySyntheticClassDescriptor
import org.jetbrains.kotlin.idea.kdoc.findKDoc
import org.jetbrains.kotlin.idea.util.fuzzyExtensionReceiverType
@@ -309,8 +310,8 @@ class DocumentationBuilder
else -> return@forEach
}
append(annotationNode, refKind)
+ if (refKind == RefKind.Deprecation) annotationNode.convertDeprecationDetailsToChildren()
}
-
}
}
}
@@ -739,7 +740,7 @@ class DocumentationBuilder
}
fun FunctionDescriptor.build(external: Boolean = false): DocumentationNode {
- if (ErrorUtils.containsErrorType(this)) {
+ if (ErrorUtils.containsErrorTypeInParameters(this) || ErrorUtils.containsErrorType(this.returnType)) {
logger.warn("Found an unresolved type in ${signatureWithSourceLocation()}")
}
@@ -908,14 +909,19 @@ class DocumentationBuilder
return node
}
- fun AnnotationDescriptor.build(): DocumentationNode? {
+ fun AnnotationDescriptor.build(isWithinReplaceWith: Boolean = false): DocumentationNode? {
val annotationClass = type.constructor.declarationDescriptor
if (annotationClass == null || ErrorUtils.isError(annotationClass)) {
return null
}
val node = DocumentationNode(annotationClass.name.asString(), Content.Empty, NodeKind.Annotation)
- allValueArguments.forEach { (name, value) ->
- val valueNode = value.toDocumentationNode()
+ allValueArguments.forEach foreach@{ (name, value) ->
+ if (name.toString() == "imports" && value.toString() == "[]") return@foreach
+ var valueNode: DocumentationNode? = null
+ if (value.toString() == "@kotlin.ReplaceWith") {
+ valueNode = (value.value as AnnotationDescriptor).build(true)
+ }
+ else valueNode = value.toDocumentationNode(isWithinReplaceWith)
if (valueNode != null) {
val paramNode = DocumentationNode(name.asString(), Content.Empty, NodeKind.Parameter)
paramNode.append(valueNode, RefKind.Detail)
@@ -925,10 +931,10 @@ class DocumentationBuilder
return node
}
- fun ConstantValue<*>.toDocumentationNode(): DocumentationNode? = value?.let { value ->
+ fun ConstantValue<*>.toDocumentationNode(isWithinReplaceWith: Boolean = false): DocumentationNode? = value?.let { value ->
when (value) {
is String ->
- "\"" + StringUtil.escapeStringCharacters(value) + "\""
+ (if (isWithinReplaceWith) "Replace with: " else "") + "\"" + StringUtil.escapeStringCharacters(value) + "\""
is EnumEntrySyntheticClassDescriptor ->
value.containingDeclaration.name.asString() + "." + value.name.asString()
is Pair<*, *> -> {
diff --git a/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt b/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt
index 4e394c466..d09bc1c9f 100644
--- a/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt
+++ b/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt
@@ -42,7 +42,7 @@ class ExternalDocumentationLinkResolver @Inject constructor(
override fun toString(): String = rootUrl.toString()
}
- val cacheDir: Path? = options.cacheRoot?.resolve("packageListCache")?.apply { createDirectories() }
+ val cacheDir: Path? = options.cacheRoot?.resolve("packageListCache")?.apply { toFile().mkdirs() }
val cachedProtocols = setOf("http", "https", "ftp")
@@ -86,13 +86,13 @@ class ExternalDocumentationLinkResolver @Inject constructor(
val digest = MessageDigest.getInstance("SHA-256")
val hash = digest.digest(packageListLink.toByteArray(Charsets.UTF_8)).toHexString()
- val cacheEntry = cacheDir.resolve(hash)
+ val cacheEntry = cacheDir.resolve(hash).toFile()
if (cacheEntry.exists()) {
try {
val connection = packageListUrl.doOpenConnectionToReadContent()
val originModifiedDate = connection.date
- val cacheDate = cacheEntry.lastModified().toMillis()
+ val cacheDate = cacheEntry.lastModified()
if (originModifiedDate > cacheDate || originModifiedDate == 0L) {
if (originModifiedDate == 0L)
logger.warn("No date header for $packageListUrl, downloading anyway")
diff --git a/core/src/main/kotlin/Kotlin/KotlinLanguageService.kt b/core/src/main/kotlin/Kotlin/KotlinLanguageService.kt
index 757221ce5..8a33ff8b7 100644
--- a/core/src/main/kotlin/Kotlin/KotlinLanguageService.kt
+++ b/core/src/main/kotlin/Kotlin/KotlinLanguageService.kt
@@ -1,6 +1,6 @@
package org.jetbrains.dokka
-import org.jetbrains.dokka.Formats.classNodeNameWithOuterClass
+import org.jetbrains.dokka.classNodeNameWithOuterClass
import org.jetbrains.dokka.LanguageService.RenderMode
/**
diff --git a/core/src/main/kotlin/Languages/NewJavaLanguageService.kt b/core/src/main/kotlin/Languages/NewJavaLanguageService.kt
index 10715d0da..c4b5fa090 100644
--- a/core/src/main/kotlin/Languages/NewJavaLanguageService.kt
+++ b/core/src/main/kotlin/Languages/NewJavaLanguageService.kt
@@ -1,6 +1,6 @@
package org.jetbrains.dokka
-import org.jetbrains.dokka.Formats.classNodeNameWithOuterClass
+import org.jetbrains.dokka.classNodeNameWithOuterClass
import org.jetbrains.dokka.LanguageService.RenderMode
/**
@@ -247,4 +247,4 @@ class NewJavaLanguageService : CommonLanguageService() {
text(" ")
identifier(node.name)
}
-} \ No newline at end of file
+}
diff --git a/core/src/main/kotlin/Model/DocumentationNode.kt b/core/src/main/kotlin/Model/DocumentationNode.kt
index e8a85a2bd..c84d4169d 100644
--- a/core/src/main/kotlin/Model/DocumentationNode.kt
+++ b/core/src/main/kotlin/Model/DocumentationNode.kt
@@ -134,6 +134,12 @@ open class DocumentationNode(val name: String,
get() = details(NodeKind.Supertype)
val signatureName = detailOrNull(NodeKind.Signature)?.name
+ val prettyName : String
+ get() = when(kind) {
+ NodeKind.Constructor -> owner!!.name
+ else -> name
+ }
+
val superclassType: DocumentationNode?
get() = when (kind) {
NodeKind.Supertype -> {
@@ -266,7 +272,7 @@ private fun DocumentationNode.isSuperclassFor(node: DocumentationNode): Boolean
fun DocumentationNode.classNodeNameWithOuterClass(): String {
assert(kind in NodeKind.classLike)
- return path.dropWhile { it.kind == NodeKind.Package || it.kind == NodeKind.Module }.joinToString(separator = ".") { it.name }
+ return path.dropWhile { it.kind !in NodeKind.classLike }.joinToString(separator = ".") { it.name }
}
fun DocumentationNode.deprecatedLevelMessage(): String {
@@ -279,3 +285,24 @@ fun DocumentationNode.deprecatedLevelMessage(): String {
}
return "This $kindName was deprecated in API level ${deprecatedLevel.name}."
}
+
+fun DocumentationNode.convertDeprecationDetailsToChildren() {
+ val toProcess = details.toMutableList()
+ while (!toProcess.isEmpty()) {
+ var child = toProcess.removeAt(0)
+ if (child.details.isEmpty() && child.name != "") {
+ updateContent { text(child.name.cleanForAppending()) }
+ }
+ else toProcess.addAll(0, child.details)
+ }
+}
+
+ /*
+ * Removes extraneous quotation marks and adds a ". " to make appending children readable.
+ */
+fun String.cleanForAppending(): String {
+ var result = this
+ if (this.first() == this.last() && this.first() == '"') result = result.substring(1, result.length - 1)
+ if (result[result.length - 2] != '.' && result.last() != ' ') result += ". "
+ return result
+} \ No newline at end of file
diff --git a/core/src/test/kotlin/javadoc/JavadocTest.kt b/core/src/test/kotlin/javadoc/JavadocTest.kt
index 74265cbb8..a42d63933 100644
--- a/core/src/test/kotlin/javadoc/JavadocTest.kt
+++ b/core/src/test/kotlin/javadoc/JavadocTest.kt
@@ -16,8 +16,8 @@ class JavadocTest {
val type = method.returnType()
assertFalse(type.asClassDoc().isIncluded)
- assertEquals("java.lang.String", type.qualifiedTypeName())
- assertEquals("java.lang.String", type.asClassDoc().qualifiedName())
+ assertEquals("String", type.qualifiedTypeName())
+ assertEquals("String", type.asClassDoc().qualifiedName())
val params = method.parameters()
assertTrue(params[0].type().isPrimitive)
@@ -119,7 +119,7 @@ class JavadocTest {
val methodParamType = doc.classNamed("TypealiasesKt")!!.methods()
.find { it.name() == "some" }!!.parameters().first()
.type()
- assertEquals("kotlin.jvm.functions.Function1", methodParamType.qualifiedTypeName())
+ assertEquals("Function1", methodParamType.qualifiedTypeName())
assertEquals("? super A, C", methodParamType.asParameterizedType().typeArguments()
.map(Type::qualifiedTypeName).joinToString())
}
diff --git a/core/src/test/kotlin/model/ClassTest.kt b/core/src/test/kotlin/model/ClassTest.kt
index 56a38fd3d..6bc45db10 100644
--- a/core/src/test/kotlin/model/ClassTest.kt
+++ b/core/src/test/kotlin/model/ClassTest.kt
@@ -181,7 +181,7 @@ class ClassTest {
with(model.members.single().members.single()) {
with(deprecation!!) {
assertEquals("Deprecated", name)
- assertEquals(Content.Empty, content)
+ // assertEquals(Content.Empty, content) // this is now an empty MutableContent instead
assertEquals(NodeKind.Annotation, kind)
assertEquals(1, details.count())
with(details[0]) {
diff --git a/core/src/test/kotlin/model/FunctionTest.kt b/core/src/test/kotlin/model/FunctionTest.kt
index 329106829..c94d7e990 100644
--- a/core/src/test/kotlin/model/FunctionTest.kt
+++ b/core/src/test/kotlin/model/FunctionTest.kt
@@ -234,4 +234,18 @@ Documentation""", content.description.toTestString())
}
}
}
+
+ // Test for b/159470920, to ensure that we correctly parse annotated function types without resolving 'ERROR CLASS'
+ // types. Note that the actual annotation is not included in the type information, this is tracked in b/145517104.
+ @Test fun functionWithAnnotatedLambdaParam() {
+ verifyModel("testdata/functions/functionWithAnnotatedLambdaParam.kt") { model ->
+ with(model.members.single().members.single { it.name == "function" }) {
+ with(details(NodeKind.Parameter).first()) {
+ with(details(NodeKind.Type).first()) {
+ assertEquals("Function0", name)
+ }
+ }
+ }
+ }
+ }
}