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
|
package org.jetbrains.kotlin.load.java.structure.impl
|
||||||
|
|
||||||
|
import com.intellij.openapi.diagnostic.Logger
|
||||||
import com.intellij.psi.PsiClass
|
import com.intellij.psi.PsiClass
|
||||||
import com.intellij.psi.PsiTypeParameter
|
import com.intellij.psi.PsiTypeParameter
|
||||||
import org.jetbrains.kotlin.asJava.KtLightClassMarker
|
import org.jetbrains.kotlin.asJava.KtLightClassMarker
|
||||||
@@ -63,22 +64,31 @@ class JavaClassImpl(psiClass: PsiClass) : JavaClassifierImpl<PsiClass>(psiClass)
|
|||||||
override val supertypes: Collection<JavaClassifierType>
|
override val supertypes: Collection<JavaClassifierType>
|
||||||
get() = classifierTypes(psi.superTypes)
|
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)
|
// Return type seems to be null for example for the 'clone' Groovy method generated by @AutoClone (see EA-73795)
|
||||||
val methods: Collection<JavaMethod>
|
return methods(psi.methods.filter { method -> !method.isConstructor && method.returnType != null }).distinct()
|
||||||
get() = 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)
|
override val fields: Collection<JavaField>
|
||||||
val fields: Collection<JavaField>
|
get() {
|
||||||
get() = fields(psi.fields.filter { field ->
|
assertNotLightClass()
|
||||||
val name = field.name
|
return fields(psi.fields.filter { field ->
|
||||||
name != null && Name.isValidIdentifier(name)
|
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
|
// which is present in getConstructors(), but its isConstructor() returns false
|
||||||
val constructors: Collection<JavaConstructor>
|
return constructors(psi.constructors.filter { method -> method.isConstructor })
|
||||||
get() = constructors(psi.constructors.filter { method -> method.isConstructor })
|
}
|
||||||
|
|
||||||
override val isAbstract: Boolean
|
override val isAbstract: Boolean
|
||||||
get() = JavaElementUtil.isAbstract(this)
|
get() = JavaElementUtil.isAbstract(this)
|
||||||
@@ -93,7 +103,19 @@ class JavaClassImpl(psiClass: PsiClass) : JavaClassifierImpl<PsiClass>(psiClass)
|
|||||||
get() = JavaElementUtil.getVisibility(this)
|
get() = JavaElementUtil.getVisibility(this)
|
||||||
|
|
||||||
override val lightClassOriginKind: LightClassOriginKind?
|
override val lightClassOriginKind: LightClassOriginKind?
|
||||||
get() = (psi as? KtLightClassMarker)?.originKind
|
get() = (psi as? KtLightClassMarker)?.originKind
|
||||||
|
|
||||||
override fun getAnnotationOwnerPsi() = psi.modifierList
|
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