diff options
author | Błażej Kardyś <bkardys@virtuslab.com> | 2020-03-24 05:04:10 +0100 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-03-25 12:40:43 +0100 |
commit | 646d2fbd2a0d1e898a14ac942c43511bfd0a1c95 (patch) | |
tree | 3b1a4dad8129f2772c17eb4a1fb1436fd0f33abf /plugins/base/src/main/kotlin/translators/psi | |
parent | c09bde34ff729ef9b1f3bea602fb53cd4e6dca42 (diff) | |
download | dokka-646d2fbd2a0d1e898a14ac942c43511bfd0a1c95.tar.gz dokka-646d2fbd2a0d1e898a14ac942c43511bfd0a1c95.tar.bz2 dokka-646d2fbd2a0d1e898a14ac942c43511bfd0a1c95.zip |
Fixing incorrect psi parsing
Diffstat (limited to 'plugins/base/src/main/kotlin/translators/psi')
-rw-r--r-- | plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt | 39 | ||||
-rw-r--r-- | plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt | 31 |
2 files changed, 21 insertions, 49 deletions
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))) } |