From 0d51a2ec43115df71ae7bb8b30df691f974f22fd Mon Sep 17 00:00:00 2001 From: Igor Yakovlev Date: Wed, 5 Jun 2019 13:55:39 +0300 Subject: [PATCH] Optimize for void return type for functions with no return type + small refacroring --- .../classes/ultraLightMembersCreator.kt | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightMembersCreator.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightMembersCreator.kt index ee6783faaab..25b329c05ce 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightMembersCreator.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightMembersCreator.kt @@ -171,11 +171,7 @@ internal class UltraLightMembersCreator( val returnType: PsiType? by lazyPub { when { isConstructor -> null - isSuspendFunction -> support.moduleDescriptor - .builtIns - .nullableAnyType - .asPsiType(support, TypeMappingMode.DEFAULT, wrapper) - else -> methodReturnType(ktFunction, wrapper) + else -> methodReturnType(ktFunction, wrapper, isSuspendFunction) } } @@ -188,7 +184,20 @@ internal class UltraLightMembersCreator( 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 = ktDeclaration.resolve()?.getterIfProperty() as? FunctionDescriptor ?: return PsiType.NULL @@ -359,7 +368,7 @@ internal class UltraLightMembersCreator( val getterName = computeMethodName(ktGetter ?: declaration, JvmAbi.getterName(propertyName), MethodType.GETTER) val getterPrototype = lightMethod(getterName, ktGetter ?: declaration, onlyJvmStatic || forceStatic) 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 } addReceiverParameter(declaration, getterWrapper) result.add(getterWrapper)