diff options
-rw-r--r-- | dokka.iml | 2 | ||||
-rw-r--r-- | javadoc/src/main/kotlin/docbase.kt | 27 | ||||
-rw-r--r-- | javadoc/src/main/kotlin/utils.kt | 3 | ||||
-rw-r--r-- | src/Formats/StructuredFormatService.kt | 9 | ||||
-rw-r--r-- | src/Java/JavaPsiDocumentationBuilder.kt | 27 | ||||
-rw-r--r-- | src/Kotlin/KotlinLanguageService.kt | 6 | ||||
-rw-r--r-- | src/Model/DocumentationNode.kt | 8 | ||||
-rw-r--r-- | test/src/model/KotlinAsJavaTest.kt | 4 |
8 files changed, 36 insertions, 50 deletions
@@ -24,7 +24,7 @@ <orderEntry type="library" name="protobuf" level="project" /> <orderEntry type="library" name="asm" level="project" /> <orderEntry type="library" name="jps-model" level="project" /> - <orderEntry type="library" name="com.google.inject:guice:4.0" level="project" /> + <orderEntry type="library" exported="" name="com.google.inject:guice:4.0" level="project" /> <orderEntry type="library" name="jansi" level="project" /> </component> </module>
\ No newline at end of file diff --git a/javadoc/src/main/kotlin/docbase.kt b/javadoc/src/main/kotlin/docbase.kt index a9a7f23b..318aa3d5 100644 --- a/javadoc/src/main/kotlin/docbase.kt +++ b/javadoc/src/main/kotlin/docbase.kt @@ -39,7 +39,7 @@ open class DocumentationNodeBareAdapter(override val node: DocumentationNode) : override fun isEnum(): Boolean = node.kind == DocumentationNode.Kind.Enum override fun isMethod(): Boolean = node.kind == DocumentationNode.Kind.Function override fun isInterface(): Boolean = node.kind == DocumentationNode.Kind.Interface - override fun isField(): Boolean = node.kind == DocumentationNode.Kind.Property + override fun isField(): Boolean = node.kind == DocumentationNode.Kind.Field override fun isClass(): Boolean = node.kind == DocumentationNode.Kind.Class override fun isAnnotationType(): Boolean = node.kind == DocumentationNode.Kind.AnnotationClass override fun isConstructor(): Boolean = node.kind == DocumentationNode.Kind.Constructor @@ -76,11 +76,11 @@ private fun <T> nodeAnnotations(self: T): List<AnnotationDescAdapter> where T : = self.node.annotations.map { AnnotationDescAdapter(self.module, it) } private fun DocumentationNode.hasAnnotation(klass: KClass<*>) = klass.qualifiedName in annotations.map { it.qualifiedName } +private fun DocumentationNode.hasModifier(name: String) = details(DocumentationNode.Kind.Modifier).any { it.name == name } -val allClassKinds = setOf(DocumentationNode.Kind.Class, DocumentationNode.Kind.Enum, DocumentationNode.Kind.Interface, DocumentationNode.Kind.Object, DocumentationNode.Kind.Exception) class PackageAdapter(module: ModuleNodeAdapter, node: DocumentationNode) : DocumentationNodeAdapter(module, node), PackageDoc { - private val allClasses = node.members.filter { it.kind in allClassKinds }.toMap { it.name } + private val allClasses = node.members.filter { it.kind in DocumentationNode.Kind.classLike }.toMap { it.name } override fun findClass(className: String?): ClassDoc? = allClasses.get(className)?.let { ClassDocumentationNodeAdapter(module, it) } @@ -111,15 +111,14 @@ class AnnotationDescAdapter(val module: ModuleNodeAdapter, val node: Documentati class ProgramElementAdapter(module: ModuleNodeAdapter, node: DocumentationNode) : DocumentationNodeAdapter(module, node), ProgramElementDoc { override fun isPublic(): Boolean = true override fun isPackagePrivate(): Boolean = false - override fun isStatic(): Boolean = node.owner?.kind in listOf(DocumentationNode.Kind.Package, DocumentationNode.Kind.ExternalClass) - || node.hasAnnotation(JvmStatic::class) + override fun isStatic(): Boolean = node.hasModifier("static") override fun modifierSpecifier(): Int = Modifier.PUBLIC + if (isStatic) Modifier.STATIC else 0 override fun qualifiedName(): String? = node.qualifiedName override fun annotations(): Array<out AnnotationDesc>? = nodeAnnotations(this).toTypedArray() override fun modifiers(): String? = "public ${if (isStatic) "static" else ""}".trim() override fun isProtected(): Boolean = false - override fun isFinal(): Boolean = node.details(DocumentationNode.Kind.Modifier).any { it.name == "final" } + override fun isFinal(): Boolean = node.hasModifier("final") override fun containingPackage(): PackageDoc? { var owner: DocumentationNode? = node @@ -356,13 +355,19 @@ class FieldAdapter(module: ModuleNodeAdapter, node: DocumentationNode) : Documen override fun isVolatile(): Boolean = node.hasAnnotation(Volatile::class) } -open class ClassDocumentationNodeAdapter(module: ModuleNodeAdapter, val classNode: DocumentationNode, val name: String = classNode.name) +open class ClassDocumentationNodeAdapter(module: ModuleNodeAdapter, val classNode: DocumentationNode) : DocumentationNodeAdapter(module, classNode), Type by TypeAdapter(module, classNode), ProgramElementDoc by ProgramElementAdapter(module, classNode), ClassDoc { - override fun name(): String = name + override fun name(): String { + val parent = classNode.owner + if (parent?.kind in DocumentationNode.Kind.classLike) { + return parent!!.name + "." + classNode.name + } + return classNode.name + } override fun constructors(filter: Boolean): Array<out ConstructorDoc> = classNode.members(DocumentationNode.Kind.Constructor).map { ConstructorAdapter(module, it) }.toTypedArray() override fun constructors(): Array<out ConstructorDoc> = constructors(true) @@ -392,8 +397,8 @@ open class ClassDocumentationNodeAdapter(module: ModuleNodeAdapter, val classNod ParamTagAdapter(module, this, it.subjectName ?: "?", true, it.children) }).toTypedArray() - override fun fields(): Array<out FieldDoc> = emptyArray() - override fun fields(filter: Boolean): Array<out FieldDoc> = emptyArray() + override fun fields(): Array<out FieldDoc> = fields(true) + override fun fields(filter: Boolean): Array<out FieldDoc> = classNode.members(DocumentationNode.Kind.Field).map { FieldAdapter(module, it) }.toTypedArray() override fun findClass(className: String?): ClassDoc? = null // TODO !!! override fun serializableFields(): Array<out FieldDoc> = emptyArray() @@ -425,7 +430,7 @@ open class ClassDocumentationNodeAdapter(module: ModuleNodeAdapter, val classNod return false } - override fun innerClasses(): Array<out ClassDoc> = classNode.members(DocumentationNode.Kind.Class).map { ClassDocumentationNodeAdapter(module, it, name + "." + it.name) }.toTypedArray() + override fun innerClasses(): Array<out ClassDoc> = classNode.members(DocumentationNode.Kind.Class).map { ClassDocumentationNodeAdapter(module, it) }.toTypedArray() override fun innerClasses(filter: Boolean): Array<out ClassDoc> = innerClasses() } diff --git a/javadoc/src/main/kotlin/utils.kt b/javadoc/src/main/kotlin/utils.kt index 661de0c8..96f2d64c 100644 --- a/javadoc/src/main/kotlin/utils.kt +++ b/javadoc/src/main/kotlin/utils.kt @@ -2,9 +2,8 @@ package org.jetbrains.dokka.javadoc import org.jetbrains.dokka.DocumentationNode import org.jetbrains.dokka.path -import java.util.* val DocumentationNode.qualifiedName: String - get() = this.path.filter { it.kind == DocumentationNode.Kind.Package || it.kind in allClassKinds } + get() = this.path.filter { it.kind == DocumentationNode.Kind.Package || it.kind in DocumentationNode.Kind.classLike } .map { it.name } .joinToString(".") diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt index 41ffc61d..6bc28522 100644 --- a/src/Formats/StructuredFormatService.kt +++ b/src/Formats/StructuredFormatService.kt @@ -308,14 +308,7 @@ abstract class StructuredFormatService(locationService: LocationService, } appendSection(location, "Packages", node.members(DocumentationNode.Kind.Package), node, to) - appendSection(location, "Types", node.members.filter { - it.kind in setOf( - DocumentationNode.Kind.Class, - DocumentationNode.Kind.Interface, - DocumentationNode.Kind.Enum, - DocumentationNode.Kind.Object, - DocumentationNode.Kind.AnnotationClass) - }, node, to) + appendSection(location, "Types", node.members.filter { it.kind in DocumentationNode.Kind.classLike }, node, to) appendSection(location, "Extensions for External Classes", node.members(DocumentationNode.Kind.ExternalClass), node, to) appendSection(location, "Enum Values", node.members(DocumentationNode.Kind.EnumItem), node, to) appendSection(location, "Constructors", node.members(DocumentationNode.Kind.Constructor), node, to) diff --git a/src/Java/JavaPsiDocumentationBuilder.kt b/src/Java/JavaPsiDocumentationBuilder.kt index a5ee891e..bdc6a368 100644 --- a/src/Java/JavaPsiDocumentationBuilder.kt +++ b/src/Java/JavaPsiDocumentationBuilder.kt @@ -186,14 +186,10 @@ private fun PsiType.typeSignature(): String = when(this) { } private fun mapTypeName(psiType: PsiType): String = when (psiType) { - PsiType.VOID -> "Unit" - is PsiPrimitiveType -> psiType.canonicalText.capitalize() - is PsiClassType -> { - val psiClass = psiType.resolve() - if (psiClass?.qualifiedName == "java.lang.Object") "Any" else psiType.className - } + is PsiPrimitiveType -> psiType.canonicalText + is PsiClassType -> psiType.className is PsiEllipsisType -> mapTypeName(psiType.componentType) - is PsiArrayType -> "Array" + is PsiArrayType -> mapTypeName(psiType.componentType) + "[]" else -> psiType.canonicalText } @@ -236,6 +232,7 @@ class JavaPsiDocumentationBuilder(private val options: DocumentationOptions, refGraph.link(qualifiedName, node, kind) } } + fun DocumentationNode(element: PsiNamedElement, kind: Kind, name: String = element.name ?: "<anonymous>"): DocumentationNode { @@ -326,18 +323,15 @@ class JavaPsiDocumentationBuilder(private val options: DocumentationOptions, fun PsiField.build(): DocumentationNode { val node = DocumentationNode(this, nodeKind()) - if (!hasModifierProperty(PsiModifier.FINAL)) { - node.appendTextNode("var", Kind.Modifier) - } node.appendType(type) + node.appendModifiers(this) register(this, node) return node } private fun PsiField.nodeKind(): Kind = when { this is PsiEnumConstant -> Kind.EnumItem - hasModifierProperty(PsiModifier.STATIC) -> Kind.CompanionObjectProperty - else -> Kind.Property + else -> Kind.Field } fun PsiMethod.build(): DocumentationNode { @@ -355,7 +349,6 @@ class JavaPsiDocumentationBuilder(private val options: DocumentationOptions, private fun PsiMethod.nodeKind(): Kind = when { isConstructor -> Kind.Constructor - hasModifierProperty(PsiModifier.STATIC) -> Kind.CompanionObjectFunction else -> Kind.Function } @@ -363,7 +356,7 @@ class JavaPsiDocumentationBuilder(private val options: DocumentationOptions, val node = DocumentationNode(this, Kind.Parameter) node.appendType(type) if (type is PsiEllipsisType) { - node.appendTextNode("vararg", Kind.Annotation, DocumentationReference.Kind.Annotation) + node.appendTextNode("vararg", Kind.Modifier, DocumentationReference.Kind.Detail) } return node } @@ -379,14 +372,10 @@ class JavaPsiDocumentationBuilder(private val options: DocumentationOptions, val modifierList = element.modifierList ?: return PsiModifier.MODIFIERS.forEach { - if (it != "static" && modifierList.hasExplicitModifier(it)) { + if (modifierList.hasExplicitModifier(it)) { appendTextNode(it, Kind.Modifier) } } - if ((element is PsiClass || (element is PsiMethod && !element.isConstructor)) && - !element.hasModifierProperty(PsiModifier.FINAL)) { - appendTextNode("open", Kind.Modifier) - } } fun DocumentationNode.appendType(psiType: PsiType?, kind: DocumentationNode.Kind = DocumentationNode.Kind.Type) { diff --git a/src/Kotlin/KotlinLanguageService.kt b/src/Kotlin/KotlinLanguageService.kt index 3c4b974f..d07f4c09 100644 --- a/src/Kotlin/KotlinLanguageService.kt +++ b/src/Kotlin/KotlinLanguageService.kt @@ -12,11 +12,7 @@ class KotlinLanguageService : LanguageService { return content { when (node.kind) { DocumentationNode.Kind.Package -> if (renderMode == RenderMode.FULL) renderPackage(node) - DocumentationNode.Kind.Class, - DocumentationNode.Kind.Interface, - DocumentationNode.Kind.Enum, - DocumentationNode.Kind.AnnotationClass, - DocumentationNode.Kind.Object -> renderClass(node, renderMode) + in DocumentationNode.Kind.classLike -> renderClass(node, renderMode) DocumentationNode.Kind.EnumItem, DocumentationNode.Kind.ExternalClass -> if (renderMode == RenderMode.FULL) identifier(node.name) diff --git a/src/Model/DocumentationNode.kt b/src/Model/DocumentationNode.kt index 44e9099e..52881f65 100644 --- a/src/Model/DocumentationNode.kt +++ b/src/Model/DocumentationNode.kt @@ -82,6 +82,7 @@ public open class DocumentationNode(val name: String, Constructor, Function, Property, + Field, CompanionObjectProperty, CompanionObjectFunction, @@ -112,9 +113,12 @@ public open class DocumentationNode(val name: String, * A note which is rendered once on a page documenting a group of overloaded functions. * Needs to be generated equally on all overloads. */ - OverloadGroupNote - } + OverloadGroupNote; + companion object { + val classLike = setOf(Class, Interface, Enum, AnnotationClass, Object) + } + } } public class DocumentationModule(name: String, content: Content = Content.Empty) diff --git a/test/src/model/KotlinAsJavaTest.kt b/test/src/model/KotlinAsJavaTest.kt index 0b609a2b..90ea13c8 100644 --- a/test/src/model/KotlinAsJavaTest.kt +++ b/test/src/model/KotlinAsJavaTest.kt @@ -16,7 +16,7 @@ class KotlinAsJavaTest { val fn = facadeClass.members.single() assertEquals("fn", fn.name) - assertEquals(DocumentationNode.Kind.CompanionObjectFunction, fn.kind) + assertEquals(DocumentationNode.Kind.Function, fn.kind) } } @@ -24,7 +24,7 @@ class KotlinAsJavaTest { verifyModelAsJava("test/data/comments/oneLineDoc.kt") { model -> val facadeClass = model.members.single().members.single { it.name == "OneLineDocKt" } val getter = facadeClass.members.single { it.name == "getProperty" } - assertEquals(DocumentationNode.Kind.CompanionObjectFunction, getter.kind) + assertEquals(DocumentationNode.Kind.Function, getter.kind) assertEquals("doc", getter.content.summary.toTestString()) } } |