JavaClassImpl: add assertion on querying members of light classes
Hopefully this assertion happens before deadlock KT-12966
This commit is contained in:
+35
-13
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.load.java.structure.impl
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.PsiTypeParameter
|
||||
import org.jetbrains.kotlin.asJava.KtLightClassMarker
|
||||
@@ -63,22 +64,31 @@ class JavaClassImpl(psiClass: PsiClass) : JavaClassifierImpl<PsiClass>(psiClass)
|
||||
override val supertypes: Collection<JavaClassifierType>
|
||||
get() = classifierTypes(psi.superTypes)
|
||||
|
||||
override // We apply distinct here because PsiClass#getMethods() can return duplicate PSI methods, for example in Lombok (see KT-11778)
|
||||
override val methods: Collection<JavaMethod>
|
||||
get() {
|
||||
assertNotLightClass()
|
||||
// We apply distinct here because PsiClass#getMethods() can return duplicate PSI methods, for example in Lombok (see KT-11778)
|
||||
// Return type seems to be null for example for the 'clone' Groovy method generated by @AutoClone (see EA-73795)
|
||||
val methods: Collection<JavaMethod>
|
||||
get() = methods(psi.methods.filter { method -> !method.isConstructor && method.returnType != null }).distinct()
|
||||
return methods(psi.methods.filter { method -> !method.isConstructor && method.returnType != null }).distinct()
|
||||
}
|
||||
|
||||
override // ex. Android plugin generates LightFields for resources started from '.' (.DS_Store file etc)
|
||||
val fields: Collection<JavaField>
|
||||
get() = fields(psi.fields.filter { field ->
|
||||
val name = field.name
|
||||
name != null && Name.isValidIdentifier(name)
|
||||
})
|
||||
override val fields: Collection<JavaField>
|
||||
get() {
|
||||
assertNotLightClass()
|
||||
return fields(psi.fields.filter { field ->
|
||||
val name = field.name
|
||||
// ex. Android plugin generates LightFields for resources started from '.' (.DS_Store file etc)
|
||||
name != null && Name.isValidIdentifier(name)
|
||||
})
|
||||
}
|
||||
|
||||
override // See for example org.jetbrains.plugins.scala.lang.psi.light.ScFunctionWrapper,
|
||||
override val constructors: Collection<JavaConstructor>
|
||||
get() {
|
||||
assertNotLightClass()
|
||||
// See for example org.jetbrains.plugins.scala.lang.psi.light.ScFunctionWrapper,
|
||||
// which is present in getConstructors(), but its isConstructor() returns false
|
||||
val constructors: Collection<JavaConstructor>
|
||||
get() = constructors(psi.constructors.filter { method -> method.isConstructor })
|
||||
return constructors(psi.constructors.filter { method -> method.isConstructor })
|
||||
}
|
||||
|
||||
override val isAbstract: Boolean
|
||||
get() = JavaElementUtil.isAbstract(this)
|
||||
@@ -93,7 +103,19 @@ class JavaClassImpl(psiClass: PsiClass) : JavaClassifierImpl<PsiClass>(psiClass)
|
||||
get() = JavaElementUtil.getVisibility(this)
|
||||
|
||||
override val lightClassOriginKind: LightClassOriginKind?
|
||||
get() = (psi as? KtLightClassMarker)?.originKind
|
||||
get() = (psi as? KtLightClassMarker)?.originKind
|
||||
|
||||
override fun getAnnotationOwnerPsi() = psi.modifierList
|
||||
|
||||
private fun assertNotLightClass() {
|
||||
val psiClass = psi
|
||||
if (psiClass !is KtLightClassMarker) return
|
||||
|
||||
val message = "Querying members of JavaClass created for $psiClass of type ${psiClass.javaClass} defined in file ${psiClass.containingFile?.virtualFile?.canonicalPath}"
|
||||
LOGGER.error(message)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val LOGGER = Logger.getInstance(JavaClassImpl::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user