aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/src/main/kotlin/links/DRI.kt4
-rw-r--r--plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt39
-rw-r--r--plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt31
3 files changed, 24 insertions, 50 deletions
diff --git a/core/src/main/kotlin/links/DRI.kt b/core/src/main/kotlin/links/DRI.kt
index cc78ab6f..abc88939 100644
--- a/core/src/main/kotlin/links/DRI.kt
+++ b/core/src/main/kotlin/links/DRI.kt
@@ -57,6 +57,7 @@ data class DRI(
}
val DriOfUnit = DRI("kotlin", "Unit")
+val DriOfAny = DRI("kotlin", "Any")
fun DRI.withClass(name: String) = copy(classNames = if (classNames.isNullOrBlank()) name else "$classNames.$name")
@@ -111,6 +112,8 @@ sealed class TypeReference {
fun from(d: ValueParameterDescriptor): TypeReference? =
fromPossiblyNullable(d.type)
+ fun from(p: PsiClass) = TypeReference
+
private fun fromPossiblyNullable(t: KotlinType, self: KotlinType? = null): TypeReference =
from(t, self).let { if (t.isMarkedNullable) Nullable(it) else it }
@@ -127,7 +130,6 @@ sealed class TypeReference {
)
}
-
private fun fromProjection(t: TypeProjection, r: KotlinType? = null): TypeReference =
if (t.isStarProjection) {
StarProjection
diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
index c6e3177b..91a498bc 100644
--- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
+++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
@@ -4,14 +4,13 @@ import com.intellij.lang.jvm.JvmModifier
import com.intellij.lang.jvm.types.JvmReferenceType
import com.intellij.psi.*
import com.intellij.psi.impl.source.PsiClassReferenceType
-import org.jetbrains.dokka.links.Callable
-import org.jetbrains.dokka.links.DRI
-import org.jetbrains.dokka.links.JavaClassReference
-import org.jetbrains.dokka.links.withClass
+import org.jetbrains.dokka.links.*
import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.model.DAnnotation
import org.jetbrains.dokka.model.DEnum
import org.jetbrains.dokka.model.DFunction
+import org.jetbrains.dokka.model.Nullable
+import org.jetbrains.dokka.model.TypeConstructor
import org.jetbrains.dokka.model.properties.PropertyContainer
import org.jetbrains.dokka.pages.PlatformData
import org.jetbrains.dokka.plugability.DokkaContext
@@ -99,12 +98,6 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator {
val superMethodsKeys = hashSetOf<Int>()
val superMethods = mutableListOf<PsiMethod>()
methods.forEach { superMethodsKeys.add(it.hash) }
- fun addAncestors(element: PsiClass) {
- ancestorsSet.add(DRI.from(element))
- element.interfaces.forEach(::addAncestors)
- element.superClass?.let(::addAncestors)
- }
-
fun parseSupertypes(superTypes: Array<PsiClassType>) {
superTypes.forEach { type ->
(type as? PsiClassType)?.takeUnless { type.shouldBeIgnored }?.resolve()?.let {
@@ -117,7 +110,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator {
superMethods.add(method)
}
}
- addAncestors(it)
+ ancestorsSet.add(DRI.from(it))
parseSupertypes(it.superTypes)
}
}
@@ -215,14 +208,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator {
isConstructor: Boolean = false,
isInherited: Boolean = false
): DFunction {
- val dri = parent.copy(
- callable = Callable(
- psi.name,
- JavaClassReference(psi.containingClass?.name.orEmpty()),
- psi.parameterList.parameters.map { parameter ->
- JavaClassReference(parameter.type.canonicalText)
- })
- )
+ val dri = DRI.from(psi).copy(classNames = parent.classNames)
return DFunction(
dri,
if (isConstructor) "<init>" else psi.name,
@@ -304,7 +290,10 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator {
fun mapBounds(bounds: Array<JvmReferenceType>): List<Bound> =
if (bounds.isEmpty()) emptyList() else bounds.mapNotNull {
(it as? PsiClassType)?.let { classType ->
- Nullable(TypeConstructor(DRI.from(classType.resolve()!!), emptyList()))
+ val resolved = classType.resolve()!!
+ val dri = if(resolved.qualifiedName == "java.lang.Object") DriOfAny
+ else DRI.from(resolved)
+ Nullable(TypeConstructor(dri, emptyList()))
}
}
return typeParameters.mapIndexed { index, type ->
@@ -343,13 +332,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator {
}
private fun parseField(psi: PsiField, parent: DRI, accessors: List<PsiMethod>): DProperty {
- val dri = parent.copy(
- callable = Callable(
- psi.name!!, // TODO: Investigate if this is indeed nullable
- JavaClassReference(psi.containingClass?.name.orEmpty()),
- emptyList()
- )
- )
+ val dri = DRI.from(psi)
return DProperty(
dri,
psi.name!!, // TODO: Investigate if this is indeed nullable
@@ -373,7 +356,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator {
}
Annotations.Annotation(
- DRI(fqname.substringBeforeLast("."), fqname.substringAfterLast(".")), // TODO: create a proper DRI
+ DRI.from(annotation),
annotation.attributes.mapNotNull {
if (it is PsiNameValuePair) {
it.attributeName to it.value.toString()
diff --git a/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt b/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt
index a791f256..0e446e51 100644
--- a/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt
+++ b/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt
@@ -5,6 +5,7 @@ import com.intellij.psi.impl.source.javadoc.PsiDocParamRef
import com.intellij.psi.impl.source.tree.JavaDocElementType
import com.intellij.psi.impl.source.tree.LeafPsiElement
import com.intellij.psi.javadoc.*
+import com.intellij.psi.tree.java.IJavaDocElementType
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.doc.*
@@ -83,11 +84,10 @@ class JavadocParser(
"ul" -> Ul(children)
"ol" -> Ol(children)
"li" -> Li(children)
- //"a" -> createLink(element, children) // TODO: add proper inline link handling
+ "a" -> createLink(element, children)
else -> Text(body = element.ownText())
}
}
-/*
private fun createLink(element: Element, children: List<DocTag>): DocTag {
return when {
@@ -95,31 +95,20 @@ class JavadocParser(
A(children, params = mapOf("docref" to element.attr("docref")))
}
element.hasAttr("href") -> {
- val href = element.attr("href")
-
- val uri = try {
- A(children, params = mapOf("href" to href))
- } catch (_: Exception) {
- null
- }
-
- if (uri?.isAbsolute == false) {
- ContentLocalLink(href)
- } else {
- ContentExternalLink(href)
- }
- }
- element.hasAttr("name") -> {
- ContentBookmark(element.attr("name"))
+ A(children, params = mapOf("href" to element.attr("href")))
}
- else -> Text()
+ else -> Text(children = children)
}
- }*/
+ }
+
+ private fun PsiDocToken.isSharpToken() = tokenType.toString() == "DOC_TAG_VALUE_SHARP_TOKEN"
private fun PsiElement.toDocumentationLink(labelElement: PsiElement? = null) =
reference?.resolve()?.let {
val dri = DRI.from(it)
- val label = labelElement ?: children.firstOrNull { it is PsiDocToken && it.text.isNotBlank() } ?: this
+ val label = labelElement ?: children.firstOrNull {
+ it is PsiDocToken && it.text.isNotBlank() && !it.isSharpToken()
+ } ?: this
DocumentationLink(dri, convertJavadocElements(listOfNotNull(label)))
}