Improve heuristic for filtering synthetic enum methods out

It's not possible to check the exact method signature, as it is
unavailable in dumb stubs for Kotlin's light classes. Yet, it's still
possible to check more things, such as parameter count and access flags.
This commit is contained in:
Yan Zhulanow
2022-03-04 18:16:54 +09:00
parent c334a44e02
commit 8f1a2f4612
@@ -6,10 +6,22 @@
package org.jetbrains.kotlin.asJava
import com.intellij.psi.PsiMethod
import com.intellij.psi.PsiModifier
import com.intellij.psi.SyntheticElement
import org.jetbrains.kotlin.builtins.StandardNames
fun isSyntheticValuesOrValueOfMethod(method: PsiMethod): Boolean {
if (method !is SyntheticElement) return false
return StandardNames.ENUM_VALUE_OF.asString() == method.name || StandardNames.ENUM_VALUES.asString() == method.name
}
if (method is SyntheticElement) {
val name = method.name
if (name == "values" || name == "valueOf") {
if (method.hasModifierProperty(PsiModifier.PUBLIC) && method.hasModifierProperty(PsiModifier.STATIC)) {
val parameterCount = method.parameterList.parametersCount
when (name) {
"values" -> if (parameterCount == 0) return true
"valueOf" -> if (parameterCount == 1) return true
}
}
}
}
return false
}