From e3c76cba8e9838b3ab2635261e3c143690fbc0c8 Mon Sep 17 00:00:00 2001 From: Ignat Beresnev Date: Thu, 30 Jun 2022 16:03:56 +0200 Subject: Mark synthetic methods generated for Java enums as obvious (#2554) Fixes #2548 --- .../translators/psi/DefaultPsiToDocumentableTranslator.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'plugins/base/src/main/kotlin/translators') diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt index f64eb261..500b0728 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -112,9 +112,6 @@ class DefaultPsiToDocumentableTranslator( private val PsiClassType.shouldBeIgnored: Boolean get() = isClass("java.lang.Enum") || isClass("java.lang.Object") - private val DRI.isObvious: Boolean - get() = packageName == "java.lang" && (classNames == "Object" || classNames == "Enum") - private fun PsiClassType.isClass(qName: String): Boolean { val shortName = qName.substringAfterLast('.') if (className == shortName) { @@ -446,7 +443,7 @@ class DefaultPsiToDocumentableTranslator( (psi.annotations.toList() .toListOfAnnotations() + it.toListOfAnnotations()).toSourceSetDependent() .toAnnotations(), - ObviousMember.takeIf { inheritedFrom != null && inheritedFrom.isObvious }, + ObviousMember.takeIf { psi.isObvious(inheritedFrom) }, psi.throwsList.toDriList().takeIf { it.isNotEmpty() } ?.let { CheckedExceptions(it.toSourceSetDependent()) } ) @@ -454,6 +451,14 @@ class DefaultPsiToDocumentableTranslator( ) } + private fun PsiMethod.isObvious(inheritedFrom: DRI? = null): Boolean { + return this is SyntheticElement || inheritedFrom?.isObvious() == true + } + + private fun DRI.isObvious(): Boolean { + return packageName == "java.lang" && (classNames == "Object" || classNames == "Enum") + } + private fun PsiReferenceList.toDriList() = referenceElements.mapNotNull { it?.resolve()?.let { DRI.from(it) } } private fun PsiModifierListOwner.additionalExtras() = listOfNotNull( -- cgit