From aa3f05136ca743eac15a9f8deb939f69cff6eb70 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 13 Feb 2015 17:04:58 +0100 Subject: import Java type parameters into documentation model --- src/Java/JavaDocumentationBuilder.kt | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'src/Java') diff --git a/src/Java/JavaDocumentationBuilder.kt b/src/Java/JavaDocumentationBuilder.kt index 760a9a3a..879c0b2c 100644 --- a/src/Java/JavaDocumentationBuilder.kt +++ b/src/Java/JavaDocumentationBuilder.kt @@ -14,6 +14,7 @@ import com.intellij.psi.PsiPrimitiveType import com.intellij.psi.PsiModifierListOwner import com.intellij.psi.PsiModifier import com.intellij.psi.PsiArrayType +import com.intellij.psi.PsiTypeParameter public class JavaDocumentationBuilder() { fun appendFile(file: PsiJavaFile, module: DocumentationModule) { @@ -48,6 +49,12 @@ public class JavaDocumentationBuilder() { } } + fun DocumentationNode.appendMembers(elements: Array, buildFn: T.() -> DocumentationNode) = + appendChildren(elements, DocumentationReference.Kind.Member, buildFn) + + fun DocumentationNode.appendDetails(elements: Array, buildFn: T.() -> DocumentationNode) = + appendChildren(elements, DocumentationReference.Kind.Detail, buildFn) + fun PsiClass.build(): DocumentationNode { val kind = when { isInterface() -> DocumentationNode.Kind.Interface @@ -58,14 +65,16 @@ public class JavaDocumentationBuilder() { val node = DocumentationNode(this, kind) getExtendsListTypes().forEach { node.appendType(it, Kind.Supertype) } getImplementsListTypes().forEach { node.appendType(it, Kind.Supertype) } - node.appendChildren(getMethods()) { build() } + node.appendDetails(getTypeParameters()) { build() } + node.appendMembers(getMethods()) { build() } return node } fun PsiMethod.build(): DocumentationNode { val node = DocumentationNode(this, Kind.Function) node.appendType(getReturnType()) - node.appendChildren(getParameterList().getParameters(), DocumentationReference.Kind.Detail) { build() } + node.appendDetails(getParameterList().getParameters()) { build() } + node.appendDetails(getTypeParameters()) { build() } return node } @@ -75,6 +84,13 @@ public class JavaDocumentationBuilder() { return node } + fun PsiTypeParameter.build(): DocumentationNode { + val node = DocumentationNode(this, Kind.TypeParameter) + getExtendsListTypes().forEach { node.appendType(it, Kind.UpperBound) } + getImplementsListTypes().forEach { node.appendType(it, Kind.UpperBound) } + return node + } + fun DocumentationNode.appendModifiers(element: PsiModifierListOwner) { val modifierList = element.getModifierList() if (modifierList == null) { @@ -92,9 +108,16 @@ public class JavaDocumentationBuilder() { if (psiType == null) { return } - val name = mapTypeName(psiType) + append(psiType.build(kind), DocumentationReference.Kind.Detail) + } + + fun PsiType.build(kind: DocumentationNode.Kind = DocumentationNode.Kind.Type): DocumentationNode { + val name = mapTypeName(this) val node = DocumentationNode(name, Content.Empty, kind) - append(node, DocumentationReference.Kind.Detail) + if (this is PsiClassType) { + node.appendDetails(getParameters()) { build(Kind.TypeParameter) } + } + return node } private fun mapTypeName(psiType: PsiType): String = when (psiType) { -- cgit