aboutsummaryrefslogtreecommitdiff
path: root/src/Java/JavaDocumentationBuilder.kt
diff options
context:
space:
mode:
authorDmitry Jemerov <yole@jetbrains.com>2015-02-20 18:02:00 +0100
committerDmitry Jemerov <yole@jetbrains.com>2015-02-20 18:02:00 +0100
commitfdd2d9a25661b0faba687a168855138dc8ee30fa (patch)
tree28eaafe798e94c0dee18c3a1b2db36f4270b9908 /src/Java/JavaDocumentationBuilder.kt
parent6620764c5f18c87933369131602b24bd2fa490e8 (diff)
downloaddokka-fdd2d9a25661b0faba687a168855138dc8ee30fa.tar.gz
dokka-fdd2d9a25661b0faba687a168855138dc8ee30fa.tar.bz2
dokka-fdd2d9a25661b0faba687a168855138dc8ee30fa.zip
links to supertypes in Java
Diffstat (limited to 'src/Java/JavaDocumentationBuilder.kt')
-rw-r--r--src/Java/JavaDocumentationBuilder.kt53
1 files changed, 33 insertions, 20 deletions
diff --git a/src/Java/JavaDocumentationBuilder.kt b/src/Java/JavaDocumentationBuilder.kt
index 5b4a6bfa..a1724bb9 100644
--- a/src/Java/JavaDocumentationBuilder.kt
+++ b/src/Java/JavaDocumentationBuilder.kt
@@ -1,29 +1,15 @@
package org.jetbrains.dokka
-import com.intellij.psi.PsiJavaFile
-import com.intellij.psi.PsiClass
-import org.jetbrains.dokka.DocumentationNode.Kind
-import com.intellij.psi.PsiMethod
+import com.intellij.psi.*
import com.intellij.psi.javadoc.PsiDocComment
-import com.intellij.psi.PsiType
-import com.intellij.psi.PsiParameter
-import com.intellij.psi.PsiNamedElement
-import com.intellij.psi.PsiDocCommentOwner
-import com.intellij.psi.PsiClassType
-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
import com.intellij.psi.javadoc.PsiDocTag
import com.intellij.psi.javadoc.PsiDocTagValue
-import com.intellij.psi.PsiEllipsisType
-import com.intellij.psi.PsiField
-import com.intellij.psi.PsiAnnotation
-import com.intellij.psi.PsiLiteralExpression
-import com.intellij.psi.PsiEnumConstant
+import org.jetbrains.dokka.DocumentationNode.Kind
+
+public class JavaDocumentationBuilder(private val options: DocumentationOptions,
+ private val pendingReferences: MutableList<PendingDocumentationReference>) {
+ private val signatureToNode = hashMapOf<String, DocumentationNode>()
-public class JavaDocumentationBuilder(private val options: DocumentationOptions) {
fun appendFile(file: PsiJavaFile, module: DocumentationModule) {
val packageNode = module.findOrCreatePackageNode(file.getPackageName())
packageNode.appendChildren(file.getClasses()) { build() }
@@ -55,6 +41,29 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions)
return null
}
+ fun register(element: PsiElement, node: DocumentationNode) {
+ signatureToNode[getSignature(element)] = node
+ }
+
+ fun link(node: DocumentationNode, element: PsiElement?) {
+ val qualifiedName = getSignature(element)
+ if (qualifiedName != null) {
+ pendingReferences.add(PendingDocumentationReference(
+ {() -> node},
+ {() -> signatureToNode[qualifiedName]},
+ DocumentationReference.Kind.Link))
+ }
+ }
+
+ private fun getSignature(element: PsiElement?) = when(element) {
+ is PsiClass -> element.getQualifiedName()
+ is PsiField -> element.getContainingClass().getQualifiedName() + "#" + element.getName()
+ is PsiMethod ->
+ element.getContainingClass().getQualifiedName() + "#" + element.getName() + "(" +
+ element.getParameterList().getParameters().map { it.getType().getCanonicalText() }.join(",") + ")"
+ else -> null
+ }
+
fun DocumentationNode(element: PsiNamedElement,
kind: Kind,
name: String = element.getName() ?: "<anonymous>"): DocumentationNode {
@@ -112,6 +121,7 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions)
node.appendMembers(getMethods()) { build() }
node.appendMembers(getFields()) { build() }
node.appendMembers(getInnerClasses()) { build() }
+ register(this, node)
return node
}
@@ -131,6 +141,7 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions)
node.appendTextNode("var", Kind.Modifier)
}
node.appendType(getType())
+ register(this, node)
return node
}
@@ -149,6 +160,7 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions)
}
node.appendDetails(getParameterList().getParameters()) { build() }
node.appendDetails(getTypeParameters()) { build() }
+ register(this, node)
return node
}
@@ -201,6 +213,7 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions)
val node = DocumentationNode(name, Content.Empty, kind)
if (this is PsiClassType) {
node.appendDetails(getParameters()) { build(Kind.Type) }
+ link(node, resolve())
}
if (this is PsiArrayType && this !is PsiEllipsisType) {
node.append(getComponentType().build(Kind.Type), DocumentationReference.Kind.Detail)