diff options
author | Dmitry Jemerov <yole@jetbrains.com> | 2015-10-29 13:31:16 +0100 |
---|---|---|
committer | Dmitry Jemerov <yole@jetbrains.com> | 2015-10-29 13:31:16 +0100 |
commit | 4e09ac20457e2c4398406a1c23bf1f435f31349e (patch) | |
tree | 87e074f00e3d31ac3c73a2b1d64ad7fc20375f8d /javadoc/src/main/kotlin/docbase.kt | |
parent | c9d59e9ae85f76e021d53c77ef18bfce0ff7ec7c (diff) | |
parent | 8216501e9a07940ed0a0be3d204733df9a9d811c (diff) | |
download | dokka-4e09ac20457e2c4398406a1c23bf1f435f31349e.tar.gz dokka-4e09ac20457e2c4398406a1c23bf1f435f31349e.tar.bz2 dokka-4e09ac20457e2c4398406a1c23bf1f435f31349e.zip |
Merge branch 'javadoc' of https://github.com/cy6erGn0m/dokka into cy6erGn0m-javadoc
# Conflicts:
# dokka.iml
# javadoc/javadoc.iml
# javadoc/src/main/kotlin/docbase.kt
# javadoc/src/main/kotlin/dokka-adapters.kt
# javadoc/src/main/kotlin/reporter.kt
# javadoc/src/main/kotlin/tags.kt
# src/Analysis/AnalysisEnvironment.kt
# src/Analysis/CompilerAPI.kt
# src/Formats/KotlinWebsiteFormatService.kt
# src/Formats/StructuredFormatService.kt
# src/Java/JavaDocumentationBuilder.kt
# src/Kotlin/ContentBuilder.kt
# src/Kotlin/DocumentationBuilder.kt
# src/Languages/JavaLanguageService.kt
# src/Model/Content.kt
# src/Model/PackageDocs.kt
# src/Utilities/GuiceModule.kt
# src/Utilities/Path.kt
# src/Utilities/ServiceLocator.kt
# test/src/markdown/MarkdownTestRunner.kt
Diffstat (limited to 'javadoc/src/main/kotlin/docbase.kt')
-rw-r--r-- | javadoc/src/main/kotlin/docbase.kt | 133 |
1 files changed, 70 insertions, 63 deletions
diff --git a/javadoc/src/main/kotlin/docbase.kt b/javadoc/src/main/kotlin/docbase.kt index 36371ad8..7625d545 100644 --- a/javadoc/src/main/kotlin/docbase.kt +++ b/javadoc/src/main/kotlin/docbase.kt @@ -5,12 +5,22 @@ import org.jetbrains.dokka.* import java.lang.reflect.Modifier import java.util.Collections import java.util.HashSet +import kotlin.platform.platformStatic +import kotlin.reflect.KClass -open class DocumentationNodeBareAdapter(val docNode: DocumentationNode) : Doc { +private interface HasModule { + val module: ModuleNodeAdapter +} + +private interface HasDocumentationNode { + val node: DocumentationNode +} + +open class DocumentationNodeBareAdapter(override val node: DocumentationNode) : Doc, HasDocumentationNode { private var rawCommentText_ = rawCommentText - override fun name(): String = docNode.name - override fun position(): SourcePosition? = SourcePositionAdapter(docNode) + override fun name(): String = node.name + override fun position(): SourcePosition? = SourcePositionAdapter(node) override fun inlineTags(): Array<out Tag>? = emptyArray() override fun firstSentenceTags(): Array<out Tag>? = emptyArray() @@ -26,46 +36,52 @@ open class DocumentationNodeBareAdapter(val docNode: DocumentationNode) : Doc { override fun getRawCommentText(): String = rawCommentText_ override fun isError(): Boolean = false - override fun isException(): Boolean = docNode.kind == DocumentationNode.Kind.Exception - override fun isEnumConstant(): Boolean = docNode.kind == DocumentationNode.Kind.EnumItem - override fun isEnum(): Boolean = docNode.kind == DocumentationNode.Kind.Enum - override fun isMethod(): Boolean = docNode.kind == DocumentationNode.Kind.Function - override fun isInterface(): Boolean = docNode.kind == DocumentationNode.Kind.Interface - override fun isField(): Boolean = docNode.kind == DocumentationNode.Kind.Property - override fun isClass(): Boolean = docNode.kind == DocumentationNode.Kind.Class - override fun isAnnotationType(): Boolean = docNode.kind == DocumentationNode.Kind.AnnotationClass - override fun isConstructor(): Boolean = docNode.kind == DocumentationNode.Kind.Constructor - override fun isOrdinaryClass(): Boolean = docNode.kind == DocumentationNode.Kind.Class - override fun isAnnotationTypeElement(): Boolean = docNode.kind == DocumentationNode.Kind.Annotation + override fun isException(): Boolean = node.kind == DocumentationNode.Kind.Exception + override fun isEnumConstant(): Boolean = node.kind == DocumentationNode.Kind.EnumItem + 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 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 + override fun isOrdinaryClass(): Boolean = node.kind == DocumentationNode.Kind.Class + override fun isAnnotationTypeElement(): Boolean = node.kind == DocumentationNode.Kind.Annotation override fun compareTo(other: Any?): Int = when (other) { !is DocumentationNodeAdapter -> 1 - else -> docNode.name.compareTo(other.docNode.name) + else -> node.name.compareTo(other.node.name) } - override fun equals(other: Any?): Boolean = docNode.qualifiedName == (other as? DocumentationNodeAdapter)?.docNode?.qualifiedName - override fun hashCode(): Int = docNode.name.hashCode() + override fun equals(other: Any?): Boolean = node.qualifiedName == (other as? DocumentationNodeAdapter)?.node?.qualifiedName + override fun hashCode(): Int = node.name.hashCode() - override fun isIncluded(): Boolean = docNode.kind != DocumentationNode.Kind.ExternalClass + override fun isIncluded(): Boolean = node.kind != DocumentationNode.Kind.ExternalClass } // TODO think of source position instead of null // TODO tags -open class DocumentationNodeAdapter(val module: ModuleNodeAdapter, docNode: DocumentationNode) : DocumentationNodeBareAdapter(docNode) { - override fun inlineTags(): Array<out Tag> = buildInlineTags(module, this, docNode.content).toTypedArray() - override fun firstSentenceTags(): Array<out Tag> = buildInlineTags(module, this, docNode.summary).toTypedArray() - override fun tags(): Array<out Tag> = (buildInlineTags(module, this, docNode.content) + docNode.content.sections.flatMap { +open class DocumentationNodeAdapter(override val module: ModuleNodeAdapter, node: DocumentationNode) : DocumentationNodeBareAdapter(node), HasModule { + override fun inlineTags(): Array<out Tag> = buildInlineTags(module, this, node.content).toTypedArray() + override fun firstSentenceTags(): Array<out Tag> = buildInlineTags(module, this, node.summary).toTypedArray() + override fun tags(): Array<out Tag> = (buildInlineTags(module, this, node.content) + node.content.sections.flatMap { when (it.tag) { - "See Also" -> buildInlineTags(module, this, it) + ContentTags.SeeAlso -> buildInlineTags(module, this, it) else -> emptyList<Tag>() } }).toTypedArray() } -val allClassKinds = setOf(DocumentationNode.Kind.Class, DocumentationNode.Kind.Enum, DocumentationNode.Kind.Interface, DocumentationNode.Kind.Object, DocumentationNode.Kind.Exception) +// should be extension property but can't because of KT-8745 +private fun <T> nodeAnnotations(self: T): List<AnnotationDescAdapter> where T : HasModule, T : HasDocumentationNode + = self.node.annotations.map { AnnotationDescAdapter(self.module, it) } + +private fun DocumentationNode.hasAnnotation(klass: KClass<*>) = klass.qualifiedName in annotations.map { it.qualifiedName } + +private val allClassKinds = setOf(DocumentationNode.Kind.Class, DocumentationNode.Kind.Enum, DocumentationNode.Kind.Interface, DocumentationNode.Kind.Object, DocumentationNode.Kind.Exception) -class PackageAdapter(module: ModuleNodeAdapter, val node: DocumentationNode) : DocumentationNodeAdapter(module, node), PackageDoc { +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 packageFacade = PackageFacadeAdapter(module, node) @@ -96,13 +112,14 @@ class AnnotationDescAdapter(val module: ModuleNodeAdapter, val node: Documentati override fun elementValues(): Array<out AnnotationDesc.ElementValuePair>? = emptyArray() // TODO } -class ProgramElementAdapter(module: ModuleNodeAdapter, val node: DocumentationNode) : DocumentationNodeAdapter(module, node), ProgramElementDoc { +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(platformStatic::class) override fun modifierSpecifier(): Int = Modifier.PUBLIC + if (isStatic) Modifier.STATIC else 0 override fun qualifiedName(): String? = node.qualifiedName - override fun annotations(): Array<out AnnotationDesc>? = node.annotations.map { AnnotationDescAdapter(module, it) }.toTypedArray() + override fun annotations(): Array<out AnnotationDesc>? = nodeAnnotations(this).toTypedArray() override fun modifiers(): String? = "public ${if (isStatic) "static" else ""}".trim() override fun isProtected(): Boolean = false @@ -137,29 +154,14 @@ class ProgramElementAdapter(module: ModuleNodeAdapter, val node: DocumentationNo override fun isIncluded(): Boolean = containingPackage()?.isIncluded ?: false && containingClass()?.let { it.isIncluded } ?: true } -public fun DocumentationNode.getArrayElementType(): DocumentationNode? = when (name) { - "Array" -> details(DocumentationNode.Kind.Type).singleOrNull()?.let { et -> et.getArrayElementType() ?: et } ?: DocumentationNode("Object", content, DocumentationNode.Kind.ExternalClass) - "IntArray", "LongArray", "ShortArray", "ByteArray", "CharArray", "DoubleArray", "FloatArray", "BooleanArray" -> DocumentationNode(name.removeSuffix("Array").toLowerCase(), content, DocumentationNode.Kind.Type) - else -> null -} - -fun DocumentationNode.getArrayDimension(): Int = when (name) { - "Array" -> 1 + (details(DocumentationNode.Kind.Type).singleOrNull()?.getArrayDimension() ?: 0) - "IntArray", "LongArray", "ShortArray", "ByteArray", "CharArray", "DoubleArray", "FloatArray", "BooleanArray" -> 1 - else -> 0 -} +open class TypeAdapter(override val module: ModuleNodeAdapter, override val node: DocumentationNode) : Type, HasDocumentationNode, HasModule { + private val javaLanguageService = JavaLanguageService() -//fun DocumentationNode.convertNativeType(): DocumentationNode = when (name) { -// "Unit" -> DocumentationNode("void", content, kind) -// "Int" -> DocumentationNode("int", content, kind) -//} - -open class TypeAdapter(val module: ModuleNodeAdapter, val node: DocumentationNode) : Type { - override fun qualifiedTypeName(): String = node.getArrayElementType()?.qualifiedName ?: node.qualifiedName - override fun typeName(): String = node.getArrayElementType()?.name ?: node.name + override fun qualifiedTypeName(): String = javaLanguageService.getArrayElementType(node)?.qualifiedName ?: node.qualifiedName + override fun typeName(): String = javaLanguageService.getArrayElementType(node)?.name ?: node.name override fun simpleTypeName(): String = typeName() // TODO difference typeName() vs simpleTypeName() - override fun dimension(): String = Collections.nCopies(node.getArrayDimension(), "[]").joinToString("") + override fun dimension(): String = Collections.nCopies(javaLanguageService.getArrayDimension(node), "[]").joinToString("") override fun isPrimitive(): Boolean = node.name in setOf("Int", "Long", "Short", "Byte", "Char", "Double", "Float", "Boolean", "Unit") override fun asClassDoc(): ClassDoc? = if (isPrimitive) null else elementType?.asClassDoc() ?: @@ -184,7 +186,7 @@ open class TypeAdapter(val module: ModuleNodeAdapter, val node: DocumentationNod override fun asAnnotationTypeDoc(): AnnotationTypeDoc? = if (node.kind == DocumentationNode.Kind.AnnotationClass) AnnotationTypeDocAdapter(module, node) else null override fun asAnnotatedType(): AnnotatedType? = if (node.annotations.isNotEmpty()) AnnotatedTypeAdapter(module, node) else null - override fun getElementType(): Type? = node.getArrayElementType()?.let { et -> TypeAdapter(module, et) } + override fun getElementType(): Type? = javaLanguageService.getArrayElementType(node)?.let { et -> TypeAdapter(module, et) } override fun asWildcardType(): WildcardType? = null override fun toString(): String = qualifiedTypeName() + dimension() @@ -194,7 +196,7 @@ open class TypeAdapter(val module: ModuleNodeAdapter, val node: DocumentationNod class AnnotatedTypeAdapter(module: ModuleNodeAdapter, node: DocumentationNode) : TypeAdapter(module, node), AnnotatedType { override fun underlyingType(): Type? = this - override fun annotations(): Array<out AnnotationDesc> = node.annotations.map { AnnotationDescAdapter(module, it) }.toTypedArray() + override fun annotations(): Array<out AnnotationDesc> = nodeAnnotations(this).toTypedArray() } class WildcardTypeAdapter(module: ModuleNodeAdapter, node: DocumentationNode) : TypeAdapter(module, node), WildcardType { @@ -227,7 +229,6 @@ class TypeVariableAdapter(module: ModuleNodeAdapter, node: DocumentationNode) : override fun equals(other: Any?): Boolean = other is Type && other.typeName() == typeName() && other.asTypeVariable()?.owner() == owner() override fun asTypeVariable(): TypeVariableAdapter = this - // override fun asClassDoc(): ClassDoc? = null } class ParameterizedTypeAdapter(module: ModuleNodeAdapter, node: DocumentationNode) : TypeAdapter(module, node), ParameterizedType { @@ -254,17 +255,23 @@ class ParameterizedTypeAdapter(module: ModuleNodeAdapter, node: DocumentationNod } } -class ParameterAdapter(module: ModuleNodeAdapter, val node: DocumentationNode) : DocumentationNodeAdapter(module, node), Parameter { +class ParameterAdapter(module: ModuleNodeAdapter, node: DocumentationNode) : DocumentationNodeAdapter(module, node), Parameter { override fun typeName(): String? = JavaLanguageService().renderType(node.detail(DocumentationNode.Kind.Type)) override fun type(): Type? = TypeAdapter(module, node.detail(DocumentationNode.Kind.Type)) - override fun annotations(): Array<out AnnotationDesc>? = node.details(DocumentationNode.Kind.Annotation).map { AnnotationDescAdapter(module, it) }.toTypedArray() + override fun annotations(): Array<out AnnotationDesc> = nodeAnnotations(this).toTypedArray() } -class ReceiverParameterAdapter(module: ModuleNodeAdapter, val receiverType: DocumentationNode) : DocumentationNodeAdapter(module, receiverType), Parameter { +class ReceiverParameterAdapter(module: ModuleNodeAdapter, val receiverType: DocumentationNode, val parent: ExecutableMemberAdapter) : DocumentationNodeAdapter(module, receiverType), Parameter { override fun typeName(): String? = receiverType.name override fun type(): Type? = TypeAdapter(module, receiverType) - override fun annotations(): Array<out AnnotationDesc> = emptyArray() - override fun name(): String = "receiver" + override fun annotations(): Array<out AnnotationDesc> = nodeAnnotations(this).toTypedArray() + override fun name(): String = tryName("receiver") + + tailRecursive + private fun tryName(name: String): String = when (name) { + in parent.parameters().drop(1).map { it.name() } -> tryName("$$name") + else -> name + } } fun classOf(fqName: String, kind: DocumentationNode.Kind = DocumentationNode.Kind.Class) = DocumentationNode(fqName.substringAfterLast(".", fqName), Content.Empty, kind).let { node -> @@ -276,7 +283,7 @@ fun classOf(fqName: String, kind: DocumentationNode.Kind = DocumentationNode.Kin node } -open class ExecutableMemberAdapter(module: ModuleNodeAdapter, val node: DocumentationNode) : DocumentationNodeAdapter(module, node), ProgramElementDoc by ProgramElementAdapter(module, node), ExecutableMemberDoc { +open class ExecutableMemberAdapter(module: ModuleNodeAdapter, node: DocumentationNode) : DocumentationNodeAdapter(module, node), ProgramElementDoc by ProgramElementAdapter(module, node), ExecutableMemberDoc { override fun isSynthetic(): Boolean = false override fun isNative(): Boolean = node.annotations.any { it.name == "native" } @@ -303,7 +310,7 @@ open class ExecutableMemberAdapter(module: ModuleNodeAdapter, val node: Document override fun signature(): String = node.details(DocumentationNode.Kind.Parameter).map { JavaLanguageService().renderType(it) }.joinToString(", ", "(", ")") // TODO it should be FQ types override fun parameters(): Array<out Parameter> = - ((receiverNode()?.let { receiver -> listOf<Parameter>(ReceiverParameterAdapter(module, receiver)) } ?: emptyList()) + ((receiverNode()?.let { receiver -> listOf<Parameter>(ReceiverParameterAdapter(module, receiver, this)) } ?: emptyList()) + node.details(DocumentationNode.Kind.Parameter).map { ParameterAdapter(module, it) } ).toTypedArray() @@ -325,7 +332,7 @@ class ConstructorAdapter(module: ModuleNodeAdapter, node: DocumentationNode) : E override fun name(): String = node.owner?.name ?: throw IllegalStateException("No owner for $node") } -class MethodAdapter(module: ModuleNodeAdapter, val node: DocumentationNode) : DocumentationNodeAdapter(module, node), ExecutableMemberDoc by ExecutableMemberAdapter(module, node), MethodDoc { +class MethodAdapter(module: ModuleNodeAdapter, node: DocumentationNode) : DocumentationNodeAdapter(module, node), ExecutableMemberDoc by ExecutableMemberAdapter(module, node), MethodDoc { override fun overrides(meth: MethodDoc?): Boolean = false // TODO override fun overriddenType(): Type? = node.overrides.firstOrNull()?.owner?.let { owner -> TypeAdapter(module, owner) } @@ -340,17 +347,17 @@ class MethodAdapter(module: ModuleNodeAdapter, val node: DocumentationNode) : Do override fun returnType(): Type = TypeAdapter(module, node.detail(DocumentationNode.Kind.Type)) } -class FieldAdapter(module: ModuleNodeAdapter, val node: DocumentationNode) : DocumentationNodeAdapter(module, node), ProgramElementDoc by ProgramElementAdapter(module, node), FieldDoc { +class FieldAdapter(module: ModuleNodeAdapter, node: DocumentationNode) : DocumentationNodeAdapter(module, node), ProgramElementDoc by ProgramElementAdapter(module, node), FieldDoc { override fun isSynthetic(): Boolean = false - override fun constantValueExpression(): String? = null // TODO - override fun constantValue(): Any? = null + override fun constantValueExpression(): String? = node.details(DocumentationNode.Kind.Value).firstOrNull()?.let { it.name } + override fun constantValue(): Any? = constantValueExpression() override fun type(): Type = TypeAdapter(module, node.detail(DocumentationNode.Kind.Type)) - override fun isTransient(): Boolean = false // TODO + override fun isTransient(): Boolean = node.hasAnnotation(transient::class) override fun serialFieldTags(): Array<out SerialFieldTag> = emptyArray() - override fun isVolatile(): Boolean = false // TODO + override fun isVolatile(): Boolean = node.hasAnnotation(volatile::class) } open class ClassDocumentationNodeAdapter(module: ModuleNodeAdapter, val classNode: DocumentationNode) : DocumentationNodeAdapter(module, classNode), Type by TypeAdapter(module, classNode), ProgramElementDoc by ProgramElementAdapter(module, classNode), ClassDoc { |