From f530a332810e952a0f0515717ce50d8c3bf87797 Mon Sep 17 00:00:00 2001 From: Sergey Mashkov Date: Thu, 6 Aug 2015 12:43:21 +0300 Subject: ~ hasAnnotation utility --- javadoc/src/main/kotlin/docbase.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'javadoc/src/main') diff --git a/javadoc/src/main/kotlin/docbase.kt b/javadoc/src/main/kotlin/docbase.kt index 4528391f..7625d545 100644 --- a/javadoc/src/main/kotlin/docbase.kt +++ b/javadoc/src/main/kotlin/docbase.kt @@ -6,6 +6,7 @@ import java.lang.reflect.Modifier import java.util.Collections import java.util.HashSet import kotlin.platform.platformStatic +import kotlin.reflect.KClass private interface HasModule { val module: ModuleNodeAdapter @@ -76,6 +77,8 @@ open class DocumentationNodeAdapter(override val module: ModuleNodeAdapter, node private fun nodeAnnotations(self: T): List 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, node: DocumentationNode) : DocumentationNodeAdapter(module, node), PackageDoc { @@ -113,7 +116,7 @@ class ProgramElementAdapter(module: ModuleNodeAdapter, node: DocumentationNode) 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) - || platformStatic::class.qualifiedName in node.annotations.map { it.qualifiedName } + || 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? = nodeAnnotations(this).toTypedArray() @@ -347,14 +350,14 @@ class MethodAdapter(module: ModuleNodeAdapter, node: DocumentationNode) : Docume 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 = 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 { -- cgit