From 17778fcfaf4975b0bb81805c4dd9a4043e5424eb Mon Sep 17 00:00:00 2001 From: Jiaxiang Chen Date: Thu, 19 Nov 2020 16:10:19 -0800 Subject: [PATCH] Optimize exception messages to contain helpful debug information --- api/src/main/kotlin/com/google/devtools/ksp/utils.kt | 6 ++++-- .../google/devtools/ksp/visitor/KSValidateVisitor.kt | 3 ++- .../ksp/processing/impl/CodeGeneratorImpl.kt | 2 +- .../devtools/ksp/processing/impl/ResolverImpl.kt | 12 +++++------- .../symbol/impl/binary/KSAnnotationDescriptorImpl.kt | 3 ++- .../impl/binary/KSClassDeclarationDescriptorImpl.kt | 3 ++- .../binary/KSFunctionDeclarationDescriptorImpl.kt | 4 +++- .../impl/binary/KSPropertySetterDescriptorImpl.kt | 3 ++- .../impl/binary/KSTypeParameterDescriptorImpl.kt | 3 ++- .../impl/binary/KSTypeReferenceDescriptorImpl.kt | 5 +++-- .../ksp/symbol/impl/java/KSTypeReferenceJavaImpl.kt | 5 +++-- .../symbol/impl/kotlin/KSFunctionDeclarationImpl.kt | 3 ++- .../ksp/symbol/impl/kotlin/KSPropertySetterImpl.kt | 2 +- .../ksp/symbol/impl/kotlin/KSTypeParameterImpl.kt | 3 ++- .../ksp/symbol/impl/kotlin/KSTypeReferenceImpl.kt | 3 ++- .../impl/synthetic/KSPropertySetterSyntheticImpl.kt | 3 ++- .../com/google/devtools/ksp/symbol/impl/utils.kt | 7 ++++--- 17 files changed, 42 insertions(+), 28 deletions(-) diff --git a/api/src/main/kotlin/com/google/devtools/ksp/utils.kt b/api/src/main/kotlin/com/google/devtools/ksp/utils.kt index 2aaf52b6e8..3b61618007 100644 --- a/api/src/main/kotlin/com/google/devtools/ksp/utils.kt +++ b/api/src/main/kotlin/com/google/devtools/ksp/utils.kt @@ -132,7 +132,7 @@ fun KSClassDeclaration.getAllSuperTypes(): Sequence { is KSClassDeclaration -> sequenceOf(resolvedDeclaration) is KSTypeAlias -> sequenceOf(resolvedDeclaration.findActualType()) is KSTypeParameter -> resolvedDeclaration.getTypesUpperBound() - else -> throw IllegalStateException() + else -> throw IllegalStateException("unhandled type parameter bound, $ExceptionMessage") } } @@ -148,7 +148,7 @@ fun KSClassDeclaration.getAllSuperTypes(): Sequence { is KSClassDeclaration -> it.getAllSuperTypes() is KSTypeAlias -> it.findActualType().getAllSuperTypes() is KSTypeParameter -> it.getTypesUpperBound().flatMap { it.getAllSuperTypes() } - else -> throw IllegalStateException() + else -> throw IllegalStateException("unhandled super type kind, $ExceptionMessage") } } ) @@ -243,3 +243,5 @@ fun KSDeclaration.isVisibleFrom(other: KSDeclaration): Boolean { } } + +const val ExceptionMessage = "please file a bug at https://github.com/google/ksp/issues/new" diff --git a/api/src/main/kotlin/com/google/devtools/ksp/visitor/KSValidateVisitor.kt b/api/src/main/kotlin/com/google/devtools/ksp/visitor/KSValidateVisitor.kt index aef46c9a07..d28ccb4f81 100644 --- a/api/src/main/kotlin/com/google/devtools/ksp/visitor/KSValidateVisitor.kt +++ b/api/src/main/kotlin/com/google/devtools/ksp/visitor/KSValidateVisitor.kt @@ -1,5 +1,6 @@ package com.google.devtools.ksp.visitor +import com.google.devtools.ksp.ExceptionMessage import com.google.devtools.ksp.symbol.* class KSValidateVisitor(private val predicate: (KSNode, KSNode) -> Boolean) : KSDefaultVisitor() { @@ -16,7 +17,7 @@ class KSValidateVisitor(private val predicate: (KSNode, KSNode) -> Boolean) : KS } override fun defaultHandler(node: KSNode, data: Unit): Boolean { - throw IllegalStateException("unhandled validation condition, please file a bug at https://github.com/google/ksp/issues/new") + throw IllegalStateException("unhandled validation condition, $ExceptionMessage") } override fun visitTypeReference(typeReference: KSTypeReference, data: Unit): Boolean { diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/processing/impl/CodeGeneratorImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/processing/impl/CodeGeneratorImpl.kt index 792a1affb4..50797d2654 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/processing/impl/CodeGeneratorImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/processing/impl/CodeGeneratorImpl.kt @@ -46,7 +46,7 @@ class CodeGeneratorImpl( val file = File(path) val parentFile = file.parentFile if (!parentFile.exists() && !parentFile.mkdirs()) { - throw IllegalStateException() + throw IllegalStateException("failed to make parent directories.") } file.writeText("") fileMap[path] = file diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/processing/impl/ResolverImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/processing/impl/ResolverImpl.kt index cabf0dac10..8dd9545621 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/processing/impl/ResolverImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/processing/impl/ResolverImpl.kt @@ -18,10 +18,7 @@ package com.google.devtools.ksp.processing.impl -import com.google.devtools.ksp.KspExperimental -import com.google.devtools.ksp.closestClassDeclaration -import com.google.devtools.ksp.isOpen -import com.google.devtools.ksp.isVisibleFrom +import com.google.devtools.ksp.* import com.intellij.openapi.project.Project import com.intellij.psi.* import com.intellij.psi.impl.source.PsiClassReferenceType @@ -442,7 +439,7 @@ class ResolverImpl( return getKSTypeCached(resolveJavaType(type.psi), type.element.typeArguments, type.annotations) } } - else -> throw IllegalStateException() + else -> throw IllegalStateException("Unable to resolve type for $type, $ExceptionMessage") } } @@ -454,13 +451,14 @@ class ResolverImpl( is KtClassOrObject -> KSClassDeclarationImpl.getCached(psi) is PsiClass -> KSClassDeclarationJavaImpl.getCached(psi) is KtTypeAlias -> KSTypeAliasImpl.getCached(psi) - else -> throw IllegalStateException() + else -> throw IllegalStateException("Unexpected psi type: ${psi.javaClass}, $ExceptionMessage") } } else { when (descriptor) { is ClassDescriptor -> KSClassDeclarationDescriptorImpl.getCached(descriptor) is TypeParameterDescriptor -> KSTypeParameterDescriptorImpl.getCached(descriptor) - else -> throw IllegalStateException() + null -> throw IllegalStateException("Failed to resolve descriptor for $kotlinType") + else -> throw IllegalStateException("Unexpected descriptor type: ${descriptor.javaClass}, $ExceptionMessage") } } } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSAnnotationDescriptorImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSAnnotationDescriptorImpl.kt index b48c74524b..5e26b3a057 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSAnnotationDescriptorImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSAnnotationDescriptorImpl.kt @@ -18,6 +18,7 @@ package com.google.devtools.ksp.symbol.impl.binary +import com.google.devtools.ksp.ExceptionMessage import com.intellij.psi.JavaPsiFacade import com.intellij.psi.PsiAnnotationMethod import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor @@ -122,6 +123,6 @@ fun ValueParameterDescriptor.getDefaultValue(): Any? { } is KtParameter -> ResolverImpl.instance.evaluateConstant(psi.defaultValue, this.type)?.value is PsiAnnotationMethod -> JavaPsiFacade.getInstance(psi.project).constantEvaluationHelper.computeConstantExpression((psi).defaultValue) - else -> throw IllegalStateException() + else -> throw IllegalStateException("Unexpected psi ${psi.javaClass}, $ExceptionMessage") } } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSClassDeclarationDescriptorImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSClassDeclarationDescriptorImpl.kt index 24b9ea98d8..6ab85f8293 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSClassDeclarationDescriptorImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSClassDeclarationDescriptorImpl.kt @@ -18,6 +18,7 @@ package com.google.devtools.ksp.symbol.impl.binary +import com.google.devtools.ksp.ExceptionMessage import org.jetbrains.kotlin.descriptors.* import com.google.devtools.ksp.symbol.* import com.google.devtools.ksp.symbol.impl.KSObjectCache @@ -91,7 +92,7 @@ class KSClassDeclarationDescriptorImpl private constructor(val descriptor: Class is PropertyDescriptor -> KSPropertyDeclarationDescriptorImpl.getCached(it) is FunctionDescriptor -> KSFunctionDeclarationDescriptorImpl.getCached(it) is ClassDescriptor -> getCached(it) - else -> throw IllegalStateException() + else -> throw IllegalStateException("Unexpected descriptor type ${it.javaClass}, $ExceptionMessage") } } } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSFunctionDeclarationDescriptorImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSFunctionDeclarationDescriptorImpl.kt index e285add65c..d08bf633a6 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSFunctionDeclarationDescriptorImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSFunctionDeclarationDescriptorImpl.kt @@ -18,6 +18,7 @@ package com.google.devtools.ksp.symbol.impl.binary +import com.google.devtools.ksp.ExceptionMessage import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor import com.google.devtools.ksp.isOpen @@ -31,6 +32,7 @@ import com.google.devtools.ksp.symbol.impl.toKSFunctionDeclaration import com.google.devtools.ksp.symbol.impl.toKSModifiers import org.jetbrains.kotlin.load.java.isFromJava import org.jetbrains.kotlin.resolve.OverridingUtil +import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe class KSFunctionDeclarationDescriptorImpl private constructor(val descriptor: FunctionDescriptor) : KSFunctionDeclaration, KSDeclarationDescriptorImpl(descriptor), @@ -64,7 +66,7 @@ class KSFunctionDeclarationDescriptorImpl private constructor(val descriptor: Fu descriptor.dispatchReceiverParameter == null -> if (descriptor.isFromJava) FunctionKind.STATIC else FunctionKind.TOP_LEVEL !descriptor.name.isSpecial && !descriptor.name.asString().isEmpty() -> FunctionKind.MEMBER descriptor is AnonymousFunctionDescriptor -> FunctionKind.ANONYMOUS - else -> throw IllegalStateException() + else -> throw IllegalStateException("Unable to resolve FunctionKind for ${descriptor.fqNameSafe}, $ExceptionMessage") } } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSPropertySetterDescriptorImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSPropertySetterDescriptorImpl.kt index f85ed1839c..2db6fe9d13 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSPropertySetterDescriptorImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSPropertySetterDescriptorImpl.kt @@ -29,7 +29,8 @@ class KSPropertySetterDescriptorImpl private constructor(descriptor: PropertySet } override val parameter: KSValueParameter by lazy { - descriptor.valueParameters.singleOrNull()?.let { KSValueParameterDescriptorImpl.getCached(it) } ?: throw IllegalStateException() + descriptor.valueParameters.singleOrNull()?.let { KSValueParameterDescriptorImpl.getCached(it) } + ?: throw IllegalStateException("Failed to resolve property type") } override fun accept(visitor: KSVisitor, data: D): R { diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSTypeParameterDescriptorImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSTypeParameterDescriptorImpl.kt index bbf02425ac..4297e73f6f 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSTypeParameterDescriptorImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSTypeParameterDescriptorImpl.kt @@ -18,6 +18,7 @@ package com.google.devtools.ksp.symbol.impl.binary +import com.google.devtools.ksp.ExceptionMessage import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.PropertyDescriptor @@ -47,7 +48,7 @@ class KSTypeParameterDescriptorImpl private constructor(val descriptor: TypePara is ClassDescriptor -> KSClassDeclarationDescriptorImpl.getCached(parent) is FunctionDescriptor -> KSFunctionDeclarationDescriptorImpl.getCached(parent) is PropertyDescriptor -> KSPropertyDeclarationDescriptorImpl.getCached(parent) - else -> throw IllegalStateException() + else -> throw IllegalStateException("Unexpected containing declaration for ${descriptor.fqNameSafe}, $ExceptionMessage") } } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSTypeReferenceDescriptorImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSTypeReferenceDescriptorImpl.kt index 8b8a2c67e2..cb4a84c448 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSTypeReferenceDescriptorImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSTypeReferenceDescriptorImpl.kt @@ -18,6 +18,7 @@ package com.google.devtools.ksp.symbol.impl.binary +import com.google.devtools.ksp.ExceptionMessage import org.jetbrains.kotlin.builtins.isSuspendFunctionTypeOrSubtype import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor @@ -44,10 +45,10 @@ class KSTypeReferenceDescriptorImpl private constructor(val kotlinType: KotlinTy when (upperBound) { is FlexibleType -> KSClassifierReferenceDescriptorImpl.getCached(upperBound.upperBound) is SimpleType -> KSClassifierReferenceDescriptorImpl.getCached(upperBound) - else -> throw IllegalStateException() + else -> throw IllegalStateException("Unexpected upperbound type ${upperBound.javaClass}, $ExceptionMessage") } } - else -> throw IllegalStateException() + else -> throw IllegalStateException("Unexpected type: ${kotlinType.constructor.declarationDescriptor?.javaClass}, $ExceptionMessage") } } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSTypeReferenceJavaImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSTypeReferenceJavaImpl.kt index 94366c622b..073967e348 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSTypeReferenceJavaImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSTypeReferenceJavaImpl.kt @@ -18,6 +18,7 @@ package com.google.devtools.ksp.symbol.impl.java +import com.google.devtools.ksp.ExceptionMessage import com.intellij.psi.* import com.intellij.psi.impl.source.PsiClassReferenceType import com.google.devtools.ksp.processing.impl.ResolverImpl @@ -62,7 +63,7 @@ class KSTypeReferenceJavaImpl private constructor(val psi: PsiType) : KSTypeRefe "char" -> ResolverImpl.instance.module.builtIns.charType "boolean" -> ResolverImpl.instance.module.builtIns.booleanType "void" -> ResolverImpl.instance.module.builtIns.unitType - else -> throw IllegalStateException() + else -> throw IllegalStateException("Unexpected primitive type ${this.name}, $ExceptionMessage") } } @@ -88,7 +89,7 @@ class KSTypeReferenceJavaImpl private constructor(val psi: PsiType) : KSTypeRefe } } null -> KSClassifierReferenceDescriptorImpl.getCached((ResolverImpl.instance.builtIns.anyType as KSTypeImpl).kotlinType.makeNullable()) - else -> throw IllegalStateException() + else -> throw IllegalStateException("Unexpected psi type for ${type.javaClass}, $ExceptionMessage") } } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSFunctionDeclarationImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSFunctionDeclarationImpl.kt index a0f413acac..736da550cf 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSFunctionDeclarationImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSFunctionDeclarationImpl.kt @@ -18,6 +18,7 @@ package com.google.devtools.ksp.symbol.impl.kotlin +import com.google.devtools.ksp.ExceptionMessage import org.jetbrains.kotlin.descriptors.FunctionDescriptor import com.google.devtools.ksp.isOpen import com.google.devtools.ksp.isVisibleFrom @@ -65,7 +66,7 @@ class KSFunctionDeclarationImpl private constructor(val ktFunction: KtFunction) when (ktFunction) { is KtNamedFunction, is KtPrimaryConstructor, is KtSecondaryConstructor -> FunctionKind.MEMBER is KtFunctionLiteral -> if (ktFunction.node.findChildByType(KtTokens.FUN_KEYWORD) != null) FunctionKind.ANONYMOUS else FunctionKind.LAMBDA - else -> throw IllegalStateException() + else -> throw IllegalStateException("Unexpected psi type ${ktFunction.javaClass}, $ExceptionMessage") } } } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertySetterImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertySetterImpl.kt index c313b8f503..ab00501873 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertySetterImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertySetterImpl.kt @@ -30,7 +30,7 @@ class KSPropertySetterImpl private constructor(ktPropertySetter: KtPropertyAcces override val parameter: KSValueParameter by lazy { ktPropertySetter.parameterList?.parameters?.singleOrNull()?.let { KSValueParameterImpl.getCached(it) } - ?: throw IllegalStateException() + ?: throw IllegalStateException("Failed to resolve property type") } override fun accept(visitor: KSVisitor, data: D): R { diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSTypeParameterImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSTypeParameterImpl.kt index e064e1cbcc..980ea1264a 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSTypeParameterImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSTypeParameterImpl.kt @@ -18,6 +18,7 @@ package com.google.devtools.ksp.symbol.impl.kotlin +import com.google.devtools.ksp.ExceptionMessage import com.google.devtools.ksp.symbol.* import com.google.devtools.ksp.symbol.impl.KSObjectCache import com.google.devtools.ksp.symbol.impl.toKSModifiers @@ -71,7 +72,7 @@ class KSTypeParameterImpl private constructor(val ktTypeParameter: KtTypeParamet is KtClassOrObject -> KSClassDeclarationImpl.getCached(owner) is KtFunction -> KSFunctionDeclarationImpl.getCached(owner) is KtProperty -> KSPropertyDeclarationImpl.getCached(owner) - else -> throw IllegalStateException() + else -> throw IllegalStateException("Unexpected containing declaration type ${owner.javaClass}, $ExceptionMessage") } } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSTypeReferenceImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSTypeReferenceImpl.kt index 74909da82f..3bba9e68f2 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSTypeReferenceImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSTypeReferenceImpl.kt @@ -18,6 +18,7 @@ package com.google.devtools.ksp.symbol.impl.kotlin +import com.google.devtools.ksp.ExceptionMessage import com.google.devtools.ksp.processing.impl.ResolverImpl import com.google.devtools.ksp.symbol.* import com.google.devtools.ksp.symbol.impl.KSObjectCache @@ -53,7 +54,7 @@ class KSTypeReferenceImpl private constructor(val ktTypeReference: KtTypeReferen is KtFunctionType -> KSCallableReferenceImpl.getCached(typeElement) is KtUserType -> KSClassifierReferenceImpl.getCached(typeElement) is KtDynamicType -> KSDynamicReferenceImpl.getCached(Unit) - else -> throw IllegalStateException() + else -> throw IllegalStateException("Unexpected type element ${typeElement?.javaClass}, $ExceptionMessage") } } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSPropertySetterSyntheticImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSPropertySetterSyntheticImpl.kt index 34dfaed5c2..c88977b97b 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSPropertySetterSyntheticImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSPropertySetterSyntheticImpl.kt @@ -39,7 +39,8 @@ class KSPropertySetterSyntheticImpl(val ksPropertyDeclaration: KSPropertyDeclara } override val parameter: KSValueParameter by lazy { - descriptor.valueParameters.singleOrNull()?.let { KSValueParameterDescriptorImpl.getCached(it) } ?: throw IllegalStateException() + descriptor.valueParameters.singleOrNull()?.let { KSValueParameterDescriptorImpl.getCached(it) } + ?: throw IllegalStateException("Failed to resolve property type") } override fun accept(visitor: KSVisitor, data: D): R { 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 602b00cfa1..ac06d11b83 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 @@ -18,6 +18,7 @@ package com.google.devtools.ksp.symbol.impl +import com.google.devtools.ksp.ExceptionMessage import com.intellij.lang.jvm.JvmModifier import com.intellij.psi.* import org.jetbrains.kotlin.descriptors.* @@ -209,7 +210,7 @@ fun KtClassOrObject.getClassType(): ClassKind { this.isAnnotation() -> ClassKind.ANNOTATION_CLASS else -> ClassKind.CLASS } - else -> throw IllegalStateException() + else -> throw IllegalStateException("Unexpected psi type ${this.javaClass}, $ExceptionMessage") } } @@ -228,7 +229,7 @@ fun org.jetbrains.kotlin.types.Variance.toKSVariance(): Variance { org.jetbrains.kotlin.types.Variance.IN_VARIANCE -> Variance.CONTRAVARIANT org.jetbrains.kotlin.types.Variance.OUT_VARIANCE -> Variance.COVARIANT org.jetbrains.kotlin.types.Variance.INVARIANT -> Variance.INVARIANT - else -> throw IllegalStateException() + else -> throw IllegalStateException("Unexpected variance value $this, $ExceptionMessage") } } @@ -246,7 +247,7 @@ internal fun KotlinType.replaceTypeArguments(newArguments: List) val type = when (ksTypeArgument) { is KSTypeArgumentKtImpl, is KSTypeArgumentJavaImpl, is KSTypeArgumentLiteImpl -> ksTypeArgument.type!! is KSTypeArgumentDescriptorImpl -> return@mapIndexed ksTypeArgument.descriptor - else -> throw IllegalStateException() + else -> throw IllegalStateException("Unexpected psi for type argument: ${ksTypeArgument.javaClass}, $ExceptionMessage") }.toKotlinType() TypeProjectionImpl(variance, type)