From 130000a44482715a446885354158ca5a2bc6316f Mon Sep 17 00:00:00 2001 From: Niklas Baudy Date: Wed, 10 Aug 2022 09:59:11 +0200 Subject: [PATCH 1/2] IDEA: UnusedQueryInspection - fix ArrayIndexOutOfBoundsException. --- .../intellij/inspections/UnusedQueryInspection.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sqldelight-idea-plugin/src/main/kotlin/app/cash/sqldelight/intellij/inspections/UnusedQueryInspection.kt b/sqldelight-idea-plugin/src/main/kotlin/app/cash/sqldelight/intellij/inspections/UnusedQueryInspection.kt index 5367a942881..2389a837999 100644 --- a/sqldelight-idea-plugin/src/main/kotlin/app/cash/sqldelight/intellij/inspections/UnusedQueryInspection.kt +++ b/sqldelight-idea-plugin/src/main/kotlin/app/cash/sqldelight/intellij/inspections/UnusedQueryInspection.kt @@ -38,7 +38,12 @@ internal class UnusedQueryInspection : LocalInspectionTool() { fileName, GlobalSearchScope.moduleScope(module), ).firstOrNull() as KtFile? ?: return PsiElementVisitor.EMPTY_VISITOR - val allMethods = generatedFile.classes[0].methods + val allMethods = generatedFile.classes.getOrNull(0)?.methods + + if (allMethods == null) { + return PsiElementVisitor.EMPTY_VISITOR + } + return object : SqlDelightVisitor() { override fun visitStmtIdentifier(o: SqlDelightStmtIdentifier) = ignoreInvalidElements { if (o !is StmtIdentifierMixin || o.identifier() == null) { From 9711c439d987a77dc42e238a3d2e673dfc09712b Mon Sep 17 00:00:00 2001 From: Niklas Baudy Date: Wed, 10 Aug 2022 10:37:23 +0200 Subject: [PATCH 2/2] Update sqldelight-idea-plugin/src/main/kotlin/app/cash/sqldelight/intellij/inspections/UnusedQueryInspection.kt Co-authored-by: Alexander Perfilyev --- .../sqldelight/intellij/inspections/UnusedQueryInspection.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqldelight-idea-plugin/src/main/kotlin/app/cash/sqldelight/intellij/inspections/UnusedQueryInspection.kt b/sqldelight-idea-plugin/src/main/kotlin/app/cash/sqldelight/intellij/inspections/UnusedQueryInspection.kt index 2389a837999..773a9c01646 100644 --- a/sqldelight-idea-plugin/src/main/kotlin/app/cash/sqldelight/intellij/inspections/UnusedQueryInspection.kt +++ b/sqldelight-idea-plugin/src/main/kotlin/app/cash/sqldelight/intellij/inspections/UnusedQueryInspection.kt @@ -38,7 +38,7 @@ internal class UnusedQueryInspection : LocalInspectionTool() { fileName, GlobalSearchScope.moduleScope(module), ).firstOrNull() as KtFile? ?: return PsiElementVisitor.EMPTY_VISITOR - val allMethods = generatedFile.classes.getOrNull(0)?.methods + val allMethods = generatedFile.classes.firstOrNull()?.methods if (allMethods == null) { return PsiElementVisitor.EMPTY_VISITOR