Filter out PSI values & valueOf methods from Java structure
These methods were recently added in Java PSI for IJ 201 and now have clash with the methods that we add on our side. Note that we can't start using methods from PSI as is because of different nullability: they have flexible types in their signatures while current methods have not-null types #KT-36095 Fixed
This commit is contained in:
+14
-1
@@ -19,7 +19,9 @@ package org.jetbrains.kotlin.load.java.structure.impl
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.PsiMethod
|
||||
import com.intellij.psi.PsiTypeParameter
|
||||
import com.intellij.psi.SyntheticElement
|
||||
import com.intellij.psi.search.SearchScope
|
||||
import org.jetbrains.kotlin.asJava.KtLightClassMarker
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
@@ -27,6 +29,7 @@ import org.jetbrains.kotlin.load.java.structure.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtPsiUtil
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
|
||||
class JavaClassImpl(psiClass: PsiClass) : JavaClassifierImpl<PsiClass>(psiClass), VirtualFileBoundJavaClass, JavaAnnotationOwnerImpl, JavaModifierListOwnerImpl {
|
||||
init {
|
||||
@@ -75,7 +78,11 @@ class JavaClassImpl(psiClass: PsiClass) : JavaClassifierImpl<PsiClass>(psiClass)
|
||||
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 methods(psi.methods.filter { method -> !method.isConstructor && method.returnType != null }).distinct()
|
||||
return methods(
|
||||
psi.methods.filter { method ->
|
||||
!method.isConstructor && method.returnType != null && !isSyntheticValuesOrValueOfMethod(method)
|
||||
}
|
||||
).distinct()
|
||||
}
|
||||
|
||||
override val fields: Collection<JavaField>
|
||||
@@ -117,6 +124,12 @@ class JavaClassImpl(psiClass: PsiClass) : JavaClassifierImpl<PsiClass>(psiClass)
|
||||
|
||||
override fun getAnnotationOwnerPsi() = psi.modifierList
|
||||
|
||||
private fun isSyntheticValuesOrValueOfMethod(method: PsiMethod): Boolean {
|
||||
if (!isEnum) return false
|
||||
if (method !is SyntheticElement) return false
|
||||
return DescriptorUtils.ENUM_VALUE_OF.asString() == method.name || DescriptorUtils.ENUM_VALUES.asString() == method.name
|
||||
}
|
||||
|
||||
private fun assertNotLightClass() {
|
||||
val psiClass = psi
|
||||
if (psiClass !is KtLightClassMarker) return
|
||||
|
||||
Reference in New Issue
Block a user