diff options
author | Marcin Aman <marcin.aman@gmail.com> | 2020-11-12 12:01:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-12 12:01:00 +0100 |
commit | 6a1c05c2d340a6812a8b58d3027d8e5712db45a2 (patch) | |
tree | b14c5b0a26fbb61bb5492b1a778e5df57fcd584d /plugins/base/src/main/kotlin/translators/psi/PsiInheritance.kt | |
parent | 7db15c357a417ccd9ff8ad1f90f5aff84eec132f (diff) | |
download | dokka-6a1c05c2d340a6812a8b58d3027d8e5712db45a2.tar.gz dokka-6a1c05c2d340a6812a8b58d3027d8e5712db45a2.tar.bz2 dokka-6a1c05c2d340a6812a8b58d3027d8e5712db45a2.zip |
Javadoc @inheritDoc tag support (#1608)
Diffstat (limited to 'plugins/base/src/main/kotlin/translators/psi/PsiInheritance.kt')
-rw-r--r-- | plugins/base/src/main/kotlin/translators/psi/PsiInheritance.kt | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/plugins/base/src/main/kotlin/translators/psi/PsiInheritance.kt b/plugins/base/src/main/kotlin/translators/psi/PsiInheritance.kt new file mode 100644 index 00000000..dcfbb8e3 --- /dev/null +++ b/plugins/base/src/main/kotlin/translators/psi/PsiInheritance.kt @@ -0,0 +1,47 @@ +package org.jetbrains.dokka.base.translators.psi + +import com.intellij.psi.PsiClass +import com.intellij.psi.PsiMethod +import org.jetbrains.dokka.utilities.DokkaLogger +import org.jetbrains.kotlin.idea.refactoring.fqName.getKotlinFqName +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.utils.addToStdlib.safeAs + +internal fun PsiClass.implementsInterface(fqName: FqName): Boolean { + return allInterfaces().any { it.getKotlinFqName() == fqName } +} + +internal fun PsiClass.allInterfaces(): Sequence<PsiClass> { + return sequence { + this.yieldAll(interfaces.toList()) + interfaces.forEach { yieldAll(it.allInterfaces()) } + } +} + +/** + * Workaround for failing [PsiMethod.findSuperMethods]. + * This might be resolved once ultra light classes are enabled for dokka + * See [KT-39518](https://youtrack.jetbrains.com/issue/KT-39518) + */ +internal fun PsiMethod.findSuperMethodsOrEmptyArray(logger: DokkaLogger): Array<PsiMethod> { + return try { + /* + We are not even attempting to call "findSuperMethods" on all methods called "getGetter" or "getSetter" + on any object implementing "kotlin.reflect.KProperty", since we know that those methods will fail + (KT-39518). Just catching the exception is not good enough, since "findSuperMethods" will + print the whole exception to stderr internally and then spoil the console. + */ + val kPropertyFqName = FqName("kotlin.reflect.KProperty") + if ( + this.parent?.safeAs<PsiClass>()?.implementsInterface(kPropertyFqName) == true && + (this.name == "getSetter" || this.name == "getGetter") + ) { + logger.warn("Skipped lookup of super methods for ${getKotlinFqName()} (KT-39518)") + return emptyArray() + } + findSuperMethods() + } catch (exception: Throwable) { + logger.warn("Failed to lookup of super methods for ${getKotlinFqName()} (KT-39518)") + emptyArray() + } +}
\ No newline at end of file |