From cbd02fc37daeb4a9caac6f8368f8d18b2946ac67 Mon Sep 17 00:00:00 2001 From: stitch Date: Wed, 16 Mar 2022 03:22:58 +0900 Subject: [PATCH] add else to when (#869) * add else to when * remove the return in return null (cherry picked from commit 504e184b476e05d89990cce22f0671bb25ca006f) --- .../google/devtools/ksp/symbol/impl/utils.kt | 71 ++++++++++--------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/utils.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/utils.kt index 60ce0cba17..e737c4659b 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/utils.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/utils.kt @@ -235,41 +235,42 @@ internal fun ModuleClassResolver.resolveContainingClass(psiMethod: PsiMethod): C } internal fun getInstanceForCurrentRound(node: KSNode): KSNode? { - when (node.origin) { - Origin.KOTLIN_LIB, Origin.JAVA_LIB -> return null - } - return when (node) { - is KSClassDeclarationImpl -> KSClassDeclarationImpl.getCached(node.ktClassOrObject) - is KSFileImpl -> KSFileImpl.getCached(node.file) - is KSFunctionDeclarationImpl -> KSFunctionDeclarationImpl.getCached(node.ktFunction) - is KSPropertyDeclarationImpl -> KSPropertyDeclarationImpl.getCached(node.ktProperty) - is KSPropertyGetterImpl -> KSPropertyGetterImpl.getCached(node.ktPropertyAccessor) - is KSPropertySetterImpl -> KSPropertySetterImpl.getCached(node.ktPropertyAccessor) - is KSTypeAliasImpl -> KSTypeAliasImpl.getCached(node.ktTypeAlias) - is KSTypeArgumentLiteImpl -> KSTypeArgumentLiteImpl.getCached(node.type, node.variance) - is KSTypeArgumentKtImpl -> KSTypeArgumentKtImpl.getCached(node.ktTypeArgument) - is KSTypeParameterImpl -> KSTypeParameterImpl.getCached(node.ktTypeParameter) - is KSTypeReferenceImpl -> KSTypeReferenceImpl.getCached(node.ktTypeReference) - is KSValueParameterImpl -> KSValueParameterImpl.getCached(node.ktParameter) - is KSClassDeclarationJavaEnumEntryImpl -> KSClassDeclarationJavaEnumEntryImpl.getCached(node.psi) - is KSClassDeclarationJavaImpl -> KSClassDeclarationJavaImpl.getCached(node.psi) - is KSFileJavaImpl -> KSFileJavaImpl.getCached(node.psi) - is KSFunctionDeclarationJavaImpl -> KSFunctionDeclarationJavaImpl.getCached(node.psi) - is KSPropertyDeclarationJavaImpl -> KSPropertyDeclarationJavaImpl.getCached(node.psi) - is KSTypeArgumentJavaImpl -> KSTypeArgumentJavaImpl.getCached(node.psi, node.parent) - is KSTypeParameterJavaImpl -> KSTypeParameterJavaImpl.getCached(node.psi) - is KSTypeReferenceJavaImpl -> - KSTypeReferenceJavaImpl.getCached(node.psi, (node.parent as? KSAnnotated)?.getInstanceForCurrentRound()) - is KSValueParameterJavaImpl -> KSValueParameterJavaImpl.getCached(node.psi) - is KSPropertyGetterSyntheticImpl -> KSPropertyGetterSyntheticImpl.getCached(node.ksPropertyDeclaration) - is KSPropertySetterSyntheticImpl -> KSPropertySetterSyntheticImpl.getCached(node.ksPropertyDeclaration) - is KSValueParameterSyntheticImpl -> KSPropertySetterImpl.getCached(node.owner as KtPropertyAccessor).parameter - is KSAnnotationJavaImpl -> KSAnnotationJavaImpl.getCached(node.psi) - is KSAnnotationImpl -> KSAnnotationImpl.getCached(node.ktAnnotationEntry) - is KSClassifierReferenceJavaImpl -> KSClassifierReferenceJavaImpl.getCached(node.psi, node.parent) - is KSValueArgumentJavaImpl -> - KSValueArgumentJavaImpl.getCached(node.name, node.value, getInstanceForCurrentRound(node.parent!!)) - else -> null + return when (node.origin) { + Origin.KOTLIN_LIB, Origin.JAVA_LIB -> null + else -> when (node) { + is KSClassDeclarationImpl -> KSClassDeclarationImpl.getCached(node.ktClassOrObject) + is KSFileImpl -> KSFileImpl.getCached(node.file) + is KSFunctionDeclarationImpl -> KSFunctionDeclarationImpl.getCached(node.ktFunction) + is KSPropertyDeclarationImpl -> KSPropertyDeclarationImpl.getCached(node.ktProperty) + is KSPropertyGetterImpl -> KSPropertyGetterImpl.getCached(node.ktPropertyAccessor) + is KSPropertySetterImpl -> KSPropertySetterImpl.getCached(node.ktPropertyAccessor) + is KSTypeAliasImpl -> KSTypeAliasImpl.getCached(node.ktTypeAlias) + is KSTypeArgumentLiteImpl -> KSTypeArgumentLiteImpl.getCached(node.type, node.variance) + is KSTypeArgumentKtImpl -> KSTypeArgumentKtImpl.getCached(node.ktTypeArgument) + is KSTypeParameterImpl -> KSTypeParameterImpl.getCached(node.ktTypeParameter) + is KSTypeReferenceImpl -> KSTypeReferenceImpl.getCached(node.ktTypeReference) + is KSValueParameterImpl -> KSValueParameterImpl.getCached(node.ktParameter) + is KSClassDeclarationJavaEnumEntryImpl -> KSClassDeclarationJavaEnumEntryImpl.getCached(node.psi) + is KSClassDeclarationJavaImpl -> KSClassDeclarationJavaImpl.getCached(node.psi) + is KSFileJavaImpl -> KSFileJavaImpl.getCached(node.psi) + is KSFunctionDeclarationJavaImpl -> KSFunctionDeclarationJavaImpl.getCached(node.psi) + is KSPropertyDeclarationJavaImpl -> KSPropertyDeclarationJavaImpl.getCached(node.psi) + is KSTypeArgumentJavaImpl -> KSTypeArgumentJavaImpl.getCached(node.psi, node.parent) + is KSTypeParameterJavaImpl -> KSTypeParameterJavaImpl.getCached(node.psi) + is KSTypeReferenceJavaImpl -> + KSTypeReferenceJavaImpl.getCached(node.psi, (node.parent as? KSAnnotated)?.getInstanceForCurrentRound()) + is KSValueParameterJavaImpl -> KSValueParameterJavaImpl.getCached(node.psi) + is KSPropertyGetterSyntheticImpl -> KSPropertyGetterSyntheticImpl.getCached(node.ksPropertyDeclaration) + is KSPropertySetterSyntheticImpl -> KSPropertySetterSyntheticImpl.getCached(node.ksPropertyDeclaration) + is KSValueParameterSyntheticImpl -> + KSPropertySetterImpl.getCached(node.owner as KtPropertyAccessor).parameter + is KSAnnotationJavaImpl -> KSAnnotationJavaImpl.getCached(node.psi) + is KSAnnotationImpl -> KSAnnotationImpl.getCached(node.ktAnnotationEntry) + is KSClassifierReferenceJavaImpl -> KSClassifierReferenceJavaImpl.getCached(node.psi, node.parent) + is KSValueArgumentJavaImpl -> + KSValueArgumentJavaImpl.getCached(node.name, node.value, getInstanceForCurrentRound(node.parent!!)) + else -> null + } } }