Optimize for void return type for functions with no return type
+ small refacroring
This commit is contained in:
+16
-7
@@ -171,11 +171,7 @@ internal class UltraLightMembersCreator(
|
|||||||
val returnType: PsiType? by lazyPub {
|
val returnType: PsiType? by lazyPub {
|
||||||
when {
|
when {
|
||||||
isConstructor -> null
|
isConstructor -> null
|
||||||
isSuspendFunction -> support.moduleDescriptor
|
else -> methodReturnType(ktFunction, wrapper, isSuspendFunction)
|
||||||
.builtIns
|
|
||||||
.nullableAnyType
|
|
||||||
.asPsiType(support, TypeMappingMode.DEFAULT, wrapper)
|
|
||||||
else -> methodReturnType(ktFunction, wrapper)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,7 +184,20 @@ internal class UltraLightMembersCreator(
|
|||||||
method.delegate.addParameter(KtUltraLightReceiverParameter(callable, support, method))
|
method.delegate.addParameter(KtUltraLightReceiverParameter(callable, support, method))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun methodReturnType(ktDeclaration: KtDeclaration, wrapper: KtUltraLightMethod): PsiType {
|
private fun methodReturnType(ktDeclaration: KtDeclaration, wrapper: KtUltraLightMethod, isSuspendFunction: Boolean): PsiType {
|
||||||
|
|
||||||
|
if (isSuspendFunction) {
|
||||||
|
return support.moduleDescriptor
|
||||||
|
.builtIns
|
||||||
|
.nullableAnyType
|
||||||
|
.asPsiType(support, TypeMappingMode.DEFAULT, wrapper)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ktDeclaration is KtNamedFunction &&
|
||||||
|
ktDeclaration.hasBlockBody() &&
|
||||||
|
!ktDeclaration.hasDeclaredReturnType()
|
||||||
|
) return PsiType.VOID
|
||||||
|
|
||||||
val desc =
|
val desc =
|
||||||
ktDeclaration.resolve()?.getterIfProperty() as? FunctionDescriptor
|
ktDeclaration.resolve()?.getterIfProperty() as? FunctionDescriptor
|
||||||
?: return PsiType.NULL
|
?: return PsiType.NULL
|
||||||
@@ -359,7 +368,7 @@ internal class UltraLightMembersCreator(
|
|||||||
val getterName = computeMethodName(ktGetter ?: declaration, JvmAbi.getterName(propertyName), MethodType.GETTER)
|
val getterName = computeMethodName(ktGetter ?: declaration, JvmAbi.getterName(propertyName), MethodType.GETTER)
|
||||||
val getterPrototype = lightMethod(getterName, ktGetter ?: declaration, onlyJvmStatic || forceStatic)
|
val getterPrototype = lightMethod(getterName, ktGetter ?: declaration, onlyJvmStatic || forceStatic)
|
||||||
val getterWrapper = KtUltraLightMethodForSourceDeclaration(getterPrototype, declaration, support, containingClass)
|
val getterWrapper = KtUltraLightMethodForSourceDeclaration(getterPrototype, declaration, support, containingClass)
|
||||||
val getterType: PsiType by lazyPub { methodReturnType(declaration, getterWrapper) }
|
val getterType: PsiType by lazyPub { methodReturnType(declaration, getterWrapper, isSuspendFunction = false) }
|
||||||
getterPrototype.setMethodReturnType { getterType }
|
getterPrototype.setMethodReturnType { getterType }
|
||||||
addReceiverParameter(declaration, getterWrapper)
|
addReceiverParameter(declaration, getterWrapper)
|
||||||
result.add(getterWrapper)
|
result.add(getterWrapper)
|
||||||
|
|||||||
Reference in New Issue
Block a user