aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/links/DRI.kt
diff options
context:
space:
mode:
authorBłażej Kardyś <bkardys@virtuslab.com>2020-03-04 03:30:27 +0100
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-03-04 14:26:18 +0100
commitd41b4c65a0ace7e60f19fc9211947d894a0442f1 (patch)
tree8d4a3444df007da0596c7eacf9f146cf49f00120 /core/src/main/kotlin/links/DRI.kt
parent1efb8d1f776058f488a06198357e4cd2d90ec03c (diff)
downloaddokka-d41b4c65a0ace7e60f19fc9211947d894a0442f1.tar.gz
dokka-d41b4c65a0ace7e60f19fc9211947d894a0442f1.tar.bz2
dokka-d41b4c65a0ace7e60f19fc9211947d894a0442f1.zip
Working javadoc parsing
Diffstat (limited to 'core/src/main/kotlin/links/DRI.kt')
-rw-r--r--core/src/main/kotlin/links/DRI.kt26
1 files changed, 24 insertions, 2 deletions
diff --git a/core/src/main/kotlin/links/DRI.kt b/core/src/main/kotlin/links/DRI.kt
index aefaf8f6..791d2b5e 100644
--- a/core/src/main/kotlin/links/DRI.kt
+++ b/core/src/main/kotlin/links/DRI.kt
@@ -1,6 +1,11 @@
package org.jetbrains.dokka.links
+import com.intellij.psi.PsiClass
+import com.intellij.psi.PsiElement
+import com.intellij.psi.PsiMethod
+import com.intellij.psi.PsiParameter
import org.jetbrains.kotlin.descriptors.*
+import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.resolve.descriptorUtil.parentsWithSelf
import org.jetbrains.kotlin.resolve.scopes.receivers.ExtensionReceiver
@@ -36,6 +41,17 @@ data class DRI(
)
}
+ fun from(psi: PsiElement) = psi.parentsWithSelf.run {
+ val callable = firstIsInstanceOrNull<PsiMethod>()
+ val params = (callable?.parameterList?.parameters).orEmpty()
+ val classes = filterIsInstance<PsiClass>().toList()
+ DRI(
+ classes.lastOrNull()?.qualifiedName?.substringBeforeLast('.', ""),
+ classes.toList().takeIf { it.isNotEmpty() }?.asReversed()?.mapNotNull { it.name }?.joinToString("."),
+ callable?.let { Callable.from(it) },
+ firstIsInstanceOrNull<PsiParameter>()?.let { params.indexOf(it) }
+ )
+ }
val topLevel = DRI()
}
}
@@ -67,6 +83,12 @@ data class Callable(
valueParameters.mapNotNull { TypeReference.from(it) }
)
}
+ fun from(psi: PsiMethod) = with(psi) {
+ Callable(
+ name,
+ null,
+ parameterList.parameters.map { param -> JavaClassReference(param.type.canonicalText) })
+ }
}
}
@@ -110,7 +132,7 @@ sealed class TypeReference {
}
}
-data class JavaClassReference(val name: String): TypeReference() {
+data class JavaClassReference(val name: String) : TypeReference() {
override fun toString(): String = name
}
@@ -132,7 +154,7 @@ data class Nullable(val wrapped: TypeReference) : TypeReference() {
override fun toString() = "$wrapped?"
}
-object StarProjection: TypeReference() {
+object StarProjection : TypeReference() {
override fun toString() = "*"
}