diff --git a/core/src/main/kotlin/cash/grammar/kotlindsl/utils/DependencyExtractor.kt b/core/src/main/kotlin/cash/grammar/kotlindsl/utils/DependencyExtractor.kt index ee76227..11b9f30 100644 --- a/core/src/main/kotlin/cash/grammar/kotlindsl/utils/DependencyExtractor.kt +++ b/core/src/main/kotlin/cash/grammar/kotlindsl/utils/DependencyExtractor.kt @@ -169,11 +169,7 @@ public class DependencyExtractor( val maybeProjectType = newLeaf.primaryExpression().text if (maybeProjectType == "project") { type = DependencyDeclaration.Type.PROJECT - identifier = quoted( - newLeaf.postfixUnarySuffix().single() - .callSuffix() - .valueArguments().valueArgument().single() - ).asSimpleIdentifier() + identifier = newLeaf.findIdentifier() } else { // e.g., `libs.kotlinGradleBom` ("libs" is the primaryExpression) identifier = newLeaf.text.asSimpleIdentifier() @@ -188,6 +184,10 @@ public class DependencyExtractor( identifier = leaf.text.asSimpleIdentifier() } + if (identifier == null && leaf is PostfixUnaryExpressionContext) { + identifier = leaf.findIdentifier() + } + val precedingComment = comments.getCommentsToLeft(declaration) val fullText = declaration.fullText(input) ?: error("Could not determine 'full text' of dependency declaration. Failed to parse expression:\n ${declaration.text}") @@ -248,6 +248,10 @@ public class DependencyExtractor( return Identifier(path = identifier, explicitPath = true) } } + + (singleArg.leafRule() as? SimpleIdentifierContext)?.Identifier()?.text.asSimpleIdentifier()?.let { + return it + } } // Unclear what this would be, bail diff --git a/core/src/test/kotlin/cash/grammar/kotlindsl/utils/DependencyExtractorTest.kt b/core/src/test/kotlin/cash/grammar/kotlindsl/utils/DependencyExtractorTest.kt index 36b0a8c..1e73e5f 100644 --- a/core/src/test/kotlin/cash/grammar/kotlindsl/utils/DependencyExtractorTest.kt +++ b/core/src/test/kotlin/cash/grammar/kotlindsl/utils/DependencyExtractorTest.kt @@ -62,6 +62,40 @@ internal class DependencyExtractorTest { capability = Capability.DEFAULT, type = Type.MODULE, ), + /* + * This case might look like this in a build script: + * ``` + * val gav = "g:a:v" + * dependencies { + * api(platform(gav)) + * } + * ``` + */ + TestCase( + displayName = "extracted string coordinates for a platform", + fullText = "api(platform(gav))", + configuration = "api", + identifier = "gav", + capability = Capability.PLATFORM, + type = Type.MODULE, + ), + /* + * This case might look like this in a build script: + * ``` + * val proj = ":project" + * dependencies { + * api(platform(project(proj))) + * } + * ``` + */ + TestCase( + displayName = "extracted string coordinates for a platform on a project", + fullText = "api(platform(project(proj)))", + configuration = "api", + identifier = "proj", + capability = Capability.PLATFORM, + type = Type.PROJECT, + ), TestCase( displayName = "version catalog accessor", fullText = "implementation(libs.gAV)",