Refactor 'isVisibleAsFunction' to make it work with SimpleFunctionDescriptor
Also inline 'resolveMethodToFunctionDescriptorWithName'
This commit is contained in:
+13
-13
@@ -88,7 +88,9 @@ public class LazyJavaClassMemberScope(
|
|||||||
).toReadOnlyList()
|
).toReadOnlyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun JavaMethodDescriptor.isVisibleAsFunction(): Boolean {
|
override fun JavaMethodDescriptor.isVisibleAsFunction() = (this as SimpleFunctionDescriptor).isVisibleAsFunction()
|
||||||
|
|
||||||
|
private fun SimpleFunctionDescriptor.isVisibleAsFunction(): Boolean {
|
||||||
// Do not load Java annotation methods as Kotlin functions (load them as properties instead)
|
// Do not load Java annotation methods as Kotlin functions (load them as properties instead)
|
||||||
if (jClass.isAnnotationType) return false
|
if (jClass.isAnnotationType) return false
|
||||||
|
|
||||||
@@ -100,14 +102,12 @@ public class LazyJavaClassMemberScope(
|
|||||||
}
|
}
|
||||||
}) return false
|
}) return false
|
||||||
|
|
||||||
val javaMethod = (source as? JavaSourceElement)?.javaElement as? JavaMethod
|
if (this.doesOverrideRenamedBuiltins()) {
|
||||||
if (javaMethod?.doesOverrideRenamedBuiltins() ?: false) {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name.sameAsBuiltinMethodWithErasedValueParameters && javaMethod != null) {
|
if (name.sameAsBuiltinMethodWithErasedValueParameters) {
|
||||||
val originalMethodDescriptor = super.resolveMethodToFunctionDescriptor(javaMethod)
|
val overridden = firstOverriddenBuiltinFunctionWithErasedValueParameters(this)
|
||||||
val overridden = firstOverriddenBuiltinFunctionWithErasedValueParameters(originalMethodDescriptor)
|
|
||||||
if (overridden != null) {
|
if (overridden != null) {
|
||||||
if (doesClassOverrideBuiltinWithoutMagic(overridden)) return false
|
if (doesClassOverrideBuiltinWithoutMagic(overridden)) return false
|
||||||
}
|
}
|
||||||
@@ -124,14 +124,14 @@ public class LazyJavaClassMemberScope(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun JavaMethod.doesOverrideRenamedBuiltins(): Boolean {
|
private fun SimpleFunctionDescriptor.doesOverrideRenamedBuiltins(): Boolean {
|
||||||
return BuiltinMethodsWithDifferentJvmName.getBuiltinFunctionNamesByJvmName(name).any {
|
return BuiltinMethodsWithDifferentJvmName.getBuiltinFunctionNamesByJvmName(name).any {
|
||||||
builtinName ->
|
builtinName ->
|
||||||
val builtinSpecialFromSuperTypes =
|
val builtinSpecialFromSuperTypes =
|
||||||
getFunctionsFromSupertypes(builtinName).filter { it.doesOverrideBuiltinWithDifferentJvmName() }
|
getFunctionsFromSupertypes(builtinName).filter { it.doesOverrideBuiltinWithDifferentJvmName() }
|
||||||
if (builtinSpecialFromSuperTypes.isEmpty()) return@any false
|
if (builtinSpecialFromSuperTypes.isEmpty()) return@any false
|
||||||
|
|
||||||
val methodDescriptor = resolveMethodToFunctionDescriptorWithName(this, builtinName)
|
val methodDescriptor = this.createRenamedCopy(builtinName)
|
||||||
|
|
||||||
builtinSpecialFromSuperTypes.any { isOverridableRenamedDescriptor(it, methodDescriptor) }
|
builtinSpecialFromSuperTypes.any { isOverridableRenamedDescriptor(it, methodDescriptor) }
|
||||||
}
|
}
|
||||||
@@ -221,7 +221,7 @@ public class LazyJavaClassMemberScope(
|
|||||||
|
|
||||||
val nameInJava = getJvmMethodNameIfSpecial(overriddenBuiltin)!!
|
val nameInJava = getJvmMethodNameIfSpecial(overriddenBuiltin)!!
|
||||||
for (method in memberIndex().findMethodsByName(Name.identifier(nameInJava))) {
|
for (method in memberIndex().findMethodsByName(Name.identifier(nameInJava))) {
|
||||||
val renamedCopy = resolveMethodToFunctionDescriptorWithName(method, name)
|
val renamedCopy = resolveMethodToFunctionDescriptor(method).createRenamedCopy(name)
|
||||||
|
|
||||||
if (isOverridableRenamedDescriptor(overriddenBuiltin, renamedCopy)) {
|
if (isOverridableRenamedDescriptor(overriddenBuiltin, renamedCopy)) {
|
||||||
result.add(renamedCopy)
|
result.add(renamedCopy)
|
||||||
@@ -389,21 +389,21 @@ public class LazyJavaClassMemberScope(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun firstOverriddenBuiltinFunctionWithErasedValueParameters(
|
private fun firstOverriddenBuiltinFunctionWithErasedValueParameters(
|
||||||
javaMethodDescriptor: JavaMethodDescriptor
|
simpleFunctionDescriptor: SimpleFunctionDescriptor
|
||||||
): FunctionDescriptor? {
|
): FunctionDescriptor? {
|
||||||
val candidatesToOverride =
|
val candidatesToOverride =
|
||||||
getFunctionsFromSupertypes(javaMethodDescriptor.name).map {
|
getFunctionsFromSupertypes(simpleFunctionDescriptor.name).map {
|
||||||
BuiltinMethodsWithSpecialGenericSignature.getOverriddenBuiltinFunctionWithErasedValueParametersInJava(it)
|
BuiltinMethodsWithSpecialGenericSignature.getOverriddenBuiltinFunctionWithErasedValueParametersInJava(it)
|
||||||
}.filterNotNull()
|
}.filterNotNull()
|
||||||
|
|
||||||
if (candidatesToOverride.isEmpty()) return null
|
if (candidatesToOverride.isEmpty()) return null
|
||||||
return candidatesToOverride.firstNotNullResult overrides@{
|
return candidatesToOverride.firstNotNullResult overrides@{
|
||||||
candidate ->
|
candidate ->
|
||||||
candidate.check { javaMethodDescriptor.doesOverrideBuiltinFunctionWithErasedValueParameters(candidate) }
|
candidate.check { simpleFunctionDescriptor.doesOverrideBuiltinFunctionWithErasedValueParameters(candidate) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun JavaMethodDescriptor.doesOverrideBuiltinFunctionWithErasedValueParameters(
|
private fun SimpleFunctionDescriptor.doesOverrideBuiltinFunctionWithErasedValueParameters(
|
||||||
builtinWithErasedParameters: FunctionDescriptor
|
builtinWithErasedParameters: FunctionDescriptor
|
||||||
): Boolean {
|
): Boolean {
|
||||||
if (this.valueParameters.size() != builtinWithErasedParameters.valueParameters.size()) return false
|
if (this.valueParameters.size() != builtinWithErasedParameters.valueParameters.size()) return false
|
||||||
|
|||||||
+1
-5
@@ -110,13 +110,9 @@ public abstract class LazyJavaScope(
|
|||||||
valueParameters: ResolvedValueParameters): MethodSignatureData
|
valueParameters: ResolvedValueParameters): MethodSignatureData
|
||||||
|
|
||||||
open fun resolveMethodToFunctionDescriptor(method: JavaMethod): JavaMethodDescriptor {
|
open fun resolveMethodToFunctionDescriptor(method: JavaMethod): JavaMethodDescriptor {
|
||||||
return resolveMethodToFunctionDescriptorWithName(method, method.name)
|
|
||||||
}
|
|
||||||
|
|
||||||
protected fun resolveMethodToFunctionDescriptorWithName(method: JavaMethod, name: Name): JavaMethodDescriptor {
|
|
||||||
val annotations = c.resolveAnnotations(method)
|
val annotations = c.resolveAnnotations(method)
|
||||||
val functionDescriptorImpl = JavaMethodDescriptor.createJavaMethod(
|
val functionDescriptorImpl = JavaMethodDescriptor.createJavaMethod(
|
||||||
containingDeclaration, annotations, name, c.components.sourceElementFactory.source(method)
|
containingDeclaration, annotations, method.name, c.components.sourceElementFactory.source(method)
|
||||||
)
|
)
|
||||||
|
|
||||||
val c = c.child(functionDescriptorImpl, method)
|
val c = c.child(functionDescriptorImpl, method)
|
||||||
|
|||||||
Reference in New Issue
Block a user