Skip to content

Commit

Permalink
fix: handle dependency declarations on properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
autonomousapps committed Nov 1, 2024
1 parent 43ae7f3 commit e1a3d83
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import cash.grammar.kotlindsl.utils.Context.leafRule
import cash.grammar.kotlindsl.utils.Context.literalText
import com.squareup.cash.grammar.KotlinParser.NamedBlockContext
import com.squareup.cash.grammar.KotlinParser.PostfixUnaryExpressionContext
import com.squareup.cash.grammar.KotlinParser.SimpleIdentifierContext
import org.antlr.v4.runtime.CharStream
import org.antlr.v4.runtime.CommonTokenStream
import org.antlr.v4.runtime.ParserRuleContext
Expand Down Expand Up @@ -182,6 +183,9 @@ public class DependencyExtractor(
// We're looking at something like `libs.kotlinGradleBom`
identifier = leaf.text.asSimpleIdentifier()
}
} else if (leaf is SimpleIdentifierContext) {
// For expressions like `api(gav)` where `val gav = "..."`
identifier = leaf.text.asSimpleIdentifier()
}

val precedingComment = comments.getCommentsToLeft(declaration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ internal class DependencyExtractorTest {
}

private companion object {
// TODO(tsr): test for Capability.PLATFORM
@JvmStatic fun declarations(): List<TestCase> = listOf(
TestCase(
displayName = "raw string coordinates",
Expand All @@ -46,6 +45,23 @@ 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(gav)
* }
* ```
*/
TestCase(
displayName = "extracted string coordinates",
fullText = "api(gav)",
configuration = "api",
identifier = "gav",
capability = Capability.DEFAULT,
type = Type.MODULE,
),
TestCase(
displayName = "version catalog accessor",
fullText = "implementation(libs.gAV)",
Expand Down

0 comments on commit e1a3d83

Please sign in to comment.