aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--javadoc/src/main/kotlin/docbase.kt27
-rw-r--r--src/Languages/JavaLanguageService.kt12
2 files changed, 18 insertions, 21 deletions
diff --git a/javadoc/src/main/kotlin/docbase.kt b/javadoc/src/main/kotlin/docbase.kt
index bafc96eb..4e822fc8 100644
--- a/javadoc/src/main/kotlin/docbase.kt
+++ b/javadoc/src/main/kotlin/docbase.kt
@@ -139,29 +139,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
-}
-
-//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
+ private val javaLanguageService = JavaLanguageService()
+
+ 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() ?:
@@ -186,7 +171,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()
diff --git a/src/Languages/JavaLanguageService.kt b/src/Languages/JavaLanguageService.kt
index ad8307c1..488a2dc4 100644
--- a/src/Languages/JavaLanguageService.kt
+++ b/src/Languages/JavaLanguageService.kt
@@ -46,6 +46,18 @@ public class JavaLanguageService : LanguageService {
}
}
+ public fun getArrayElementType(node: DocumentationNode): DocumentationNode? = when (node.name) {
+ "Array" -> node.details(Kind.Type).singleOrNull()?.let { et -> getArrayElementType(et) ?: et } ?: DocumentationNode("Object", node.content, DocumentationNode.Kind.ExternalClass)
+ "IntArray", "LongArray", "ShortArray", "ByteArray", "CharArray", "DoubleArray", "FloatArray", "BooleanArray" -> DocumentationNode(node.name.removeSuffix("Array").toLowerCase(), node.content, DocumentationNode.Kind.Type)
+ else -> null
+ }
+
+ public fun getArrayDimension(node: DocumentationNode): Int = when (node.name) {
+ "Array" -> 1 + (node.details(DocumentationNode.Kind.Type).singleOrNull()?.let { getArrayDimension(it) } ?: 0)
+ "IntArray", "LongArray", "ShortArray", "ByteArray", "CharArray", "DoubleArray", "FloatArray", "BooleanArray" -> 1
+ else -> 0
+ }
+
public fun renderType(node: DocumentationNode): String {
return when (node.name) {
"Unit" -> "void"