Report the error when a declaration in Kotlin accidentally overrides a static member from Java
This commit is contained in:
@@ -17,8 +17,11 @@
|
||||
package org.jetbrains.kotlin.load.java.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaStaticClassScope
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassNotAny
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
@@ -47,3 +50,13 @@ fun copyValueParameters(
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun ClassDescriptor.getParentJavaStaticClassScope(): LazyJavaStaticClassScope? {
|
||||
val superClassDescriptor = getSuperClassNotAny() ?: return null
|
||||
|
||||
val staticScope = superClassDescriptor.staticScope
|
||||
|
||||
if (staticScope !is LazyJavaStaticClassScope) return superClassDescriptor.getParentJavaStaticClassScope()
|
||||
|
||||
return staticScope
|
||||
}
|
||||
|
||||
+2
-7
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.load.java.components.DescriptorResolverUtils
|
||||
import org.jetbrains.kotlin.load.java.descriptors.getParentJavaStaticClassScope
|
||||
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -30,7 +31,6 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.DescriptorFactory.createEnumValueOfMethod
|
||||
import org.jetbrains.kotlin.resolve.DescriptorFactory.createEnumValuesMethod
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassNotAny
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
@@ -104,12 +104,7 @@ public class LazyJavaStaticClassScope(
|
||||
override fun getContainingDeclaration() = super.getContainingDeclaration() as LazyJavaClassDescriptor
|
||||
|
||||
private fun getStaticFunctionsFromJavaSuperClasses(name: Name, descriptor: ClassDescriptor): Set<SimpleFunctionDescriptor> {
|
||||
val superClassDescriptor = descriptor.getSuperClassNotAny() ?: return emptySet()
|
||||
|
||||
val staticScope = superClassDescriptor.staticScope
|
||||
|
||||
if (staticScope !is LazyJavaStaticClassScope) return getStaticFunctionsFromJavaSuperClasses(name, superClassDescriptor)
|
||||
|
||||
val staticScope = descriptor.getParentJavaStaticClassScope() ?: return emptySet()
|
||||
return staticScope.getFunctions(name, NoLookupLocation.WHEN_GET_SUPER_MEMBERS).map { it as SimpleFunctionDescriptor }.toSet()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user