From 1d56bd7c59f2a742c0a4c4ff208cecb62d1c3d7a Mon Sep 17 00:00:00 2001 From: GeorgCantor Date: Mon, 23 Sep 2024 21:19:12 +0300 Subject: [PATCH] Update utils.kt --- .../main/kotlin/com/google/devtools/ksp/utils.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 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 42bd9fb9e9..c6e904e270 100644 --- a/api/src/main/kotlin/com/google/devtools/ksp/utils.kt +++ b/api/src/main/kotlin/com/google/devtools/ksp/utils.kt @@ -73,15 +73,18 @@ fun Resolver.getPropertyDeclarationByName(name: String, includeTopLevel: Boolean /** * Find the containing file of a KSNode. * @return KSFile if the given KSNode has a containing file. - * exmample of symbols without a containing file: symbols from class files, synthetic symbols created by user. + * example of symbols without a containing file: symbols from class files, synthetic symbols created by user. */ val KSNode.containingFile: KSFile? get() { - var parent = this.parent - while (parent != null && parent !is KSFile) { - parent = parent.parent + var current: KSNode? = this.parent + while (current != null) { + if (current is KSFile) { + return current + } + current = current.parent } - return parent as? KSFile? + return null } /**