diff options
author | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2018-01-20 17:26:00 +0300 |
---|---|---|
committer | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2018-01-20 17:26:00 +0300 |
commit | 7723826054f0bc87b1bbf8c0b07127d86aa99363 (patch) | |
tree | ca8c352cc8c563883cbdc3f5b58f5b248ca23906 /core/src | |
parent | fab08907d55b91da0ca78d7d9aeab7c0035874da (diff) | |
download | dokka-7723826054f0bc87b1bbf8c0b07127d86aa99363.tar.gz |
Support constants from Java in KK mode
Diffstat (limited to 'core/src')
4 files changed, 25 insertions, 20 deletions
diff --git a/core/src/main/kotlin/Formats/JavaLayoutHtml/JavaLayoutHtmlFormatOutputBuilder.kt b/core/src/main/kotlin/Formats/JavaLayoutHtml/JavaLayoutHtmlFormatOutputBuilder.kt index 5e841b4a1..a8b754f65 100644 --- a/core/src/main/kotlin/Formats/JavaLayoutHtml/JavaLayoutHtmlFormatOutputBuilder.kt +++ b/core/src/main/kotlin/Formats/JavaLayoutHtml/JavaLayoutHtmlFormatOutputBuilder.kt @@ -609,11 +609,6 @@ open class JavaLayoutHtmlFormatOutputBuilder( } } - fun DocumentationNode.constantValue(): String? = - detailOrNull(NodeKind.Value)?.name.takeIf { - kind == NodeKind.Property - } - protected open fun FlowContent.fullMemberDocs(node: DocumentationNode) { div { id = node.signatureForAnchor(logger) @@ -718,9 +713,7 @@ open class JavaLayoutHtmlFormatOutputBuilder( val nestedClasses = node.members.filter { it.kind in NodeKind.classLike } - val constants = - node.members(NodeKind.CompanionObjectProperty) - .filter { it.details(NodeKind.Modifier).any { it.name == "const" } } + val constants = node.members.filter { it.constantValue() != null } val constructors = node.members(NodeKind.Constructor) val functions = node.members(functionKind) @@ -769,12 +762,7 @@ open class JavaLayoutHtmlFormatOutputBuilder( private val externalClassExtensionProperties = node.members(NodeKind.ExternalClass).flatMap { it.members(NodeKind.Property) } - val constants = node.members(NodeKind.Property) - .filter { - it.details(NodeKind.Modifier).any { - it.name == "const" - } - } + val constants = node.members(NodeKind.Property).filter { it.constantValue() != null } val functions = node.members(NodeKind.Function) + externalClassExtensionFunctions @@ -797,4 +785,9 @@ class JavaLayoutHtmlFormatOutputBuilderFactoryImpl @Inject constructor( override fun createOutputBuilder(output: Appendable, uri: URI): JavaLayoutHtmlFormatOutputBuilder { return JavaLayoutHtmlFormatOutputBuilder(output, languageService, uriProvider, templateService, logger, uri) } -}
\ No newline at end of file +} + +fun DocumentationNode.constantValue(): String? = + detailOrNull(NodeKind.Value)?.name.takeIf { + kind == NodeKind.Property || kind == NodeKind.CompanionObjectProperty + }
\ No newline at end of file diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt index 5bfabf3e5..88f517bd5 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -2,6 +2,7 @@ package org.jetbrains.dokka import com.google.inject.Inject import com.intellij.openapi.util.text.StringUtil +import com.intellij.psi.PsiField import com.intellij.psi.PsiJavaFile import org.jetbrains.dokka.DokkaConfiguration.* import org.jetbrains.dokka.Kotlin.DescriptorDocumentationParser @@ -780,12 +781,18 @@ class DocumentationBuilder if (isVar) { node.appendTextNode("var", NodeKind.Modifier) } + if (isConst) { - val psi = sourcePsi() as? KtVariableDeclaration - val text = psi?.initializer?.text - text?.let { node.appendTextNode(it, NodeKind.Value) } + val psi = sourcePsi() + val valueText = when (psi) { + is KtVariableDeclaration -> psi.initializer?.text + is PsiField -> psi.initializer?.text + else -> null + } + valueText?.let { node.appendTextNode(it, NodeKind.Value) } } + getter?.let { if (!it.isDefault) { node.addAccessorDocumentation(descriptorDocumentationParser.parseDocumentation(it), "Getter") diff --git a/core/src/test/kotlin/format/JavaLayoutHtmlFormatTest.kt b/core/src/test/kotlin/format/JavaLayoutHtmlFormatTest.kt index 4557ce8ea..160b3cb43 100644 --- a/core/src/test/kotlin/format/JavaLayoutHtmlFormatTest.kt +++ b/core/src/test/kotlin/format/JavaLayoutHtmlFormatTest.kt @@ -50,4 +50,9 @@ class JavaLayoutHtmlFormatTest : JavaLayoutHtmlFormatTestCase() { model.members.single().members(NodeKind.Class) } } + + @Test + fun constJava() { + verifyNode("ConstJava.java", noStdlibLink = true) + } }
\ No newline at end of file diff --git a/core/src/test/kotlin/format/JavaLayoutHtmlFormatTestCase.kt b/core/src/test/kotlin/format/JavaLayoutHtmlFormatTestCase.kt index 656829904..50af8f2f7 100644 --- a/core/src/test/kotlin/format/JavaLayoutHtmlFormatTestCase.kt +++ b/core/src/test/kotlin/format/JavaLayoutHtmlFormatTestCase.kt @@ -93,8 +93,8 @@ abstract class JavaLayoutHtmlFormatTestCase { } } - protected fun verifyNode(fileName: String) { - verifyNode(fileName) { model -> listOf(model.members.single().members.single()) } + protected fun verifyNode(fileName: String, noStdlibLink: Boolean = false) { + verifyNode(fileName, noStdlibLink) { model -> listOf(model.members.single().members.single()) } } protected fun verifyPackageNode(fileName: String, noStdlibLink: Boolean = false) { |