refactor: extract duplicated string literals in KapperImpl#328
Conversation
Extract repeated string literals to companion object constants to satisfy SonarCloud rules S1192. Skipped S6518 (indexed accessor in coroutines) as MapperRegistry.get() is not an operator function.
📝 WalkthroughWalkthroughRefactoring effort that extracts two repeated string literals ( Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
core/src/main/kotlin/net/samyn/kapper/internal/KapperImpl.kt (1)
116-117: Optional follow-up: extract duplicated execution failure message too.
"Failed to execute statement: $sql"is still duplicated in two catch blocks. Consider a small helper or shared constant pattern for consistency with this refactor.Also applies to: 147-148
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@core/src/main/kotlin/net/samyn/kapper/internal/KapperImpl.kt` around lines 116 - 117, The two catch blocks in KapperImpl are duplicating the literal "Failed to execute statement: $sql"; extract that into a single reusable element (either a private helper method like buildExecuteFailMessage(sql: String): String or a private constant pattern plus String.format) and replace both occurrences so both catch blocks call the helper (and keep the existing logger.warn(message, e) usage); update any other identical occurrences (e.g., the ones around the existing logger.warn(it, e) calls) to use the same helper for consistency.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@core/src/main/kotlin/net/samyn/kapper/internal/KapperImpl.kt`:
- Around line 116-117: The two catch blocks in KapperImpl are duplicating the
literal "Failed to execute statement: $sql"; extract that into a single reusable
element (either a private helper method like buildExecuteFailMessage(sql:
String): String or a private constant pattern plus String.format) and replace
both occurrences so both catch blocks call the helper (and keep the existing
logger.warn(message, e) usage); update any other identical occurrences (e.g.,
the ones around the existing logger.warn(it, e) calls) to use the same helper
for consistency.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f1b2694e-0c61-4346-a8ec-681304233741
📒 Files selected for processing (1)
core/src/main/kotlin/net/samyn/kapper/internal/KapperImpl.kt
Unit Tests 62 files ±0 62 suites ±0 3m 12s ⏱️ +10s Results for commit f3e47bb. ± Comparison against base commit 1d8d836. This pull request removes 39 and adds 39 tests. Note that renamed tests count towards both. |
Code Coverage
Updated for commit f3e47bb |
|




Summary
KapperImplto companion object constants"SQL query cannot be empty or blank"and"Executing prepared statement: {}"were each duplicated 3 timesSonar issues addressed
"SQL query cannot be empty or blank"(3 occurrences)"Executing prepared statement: {}"(3 occurrences)Sonar issues skipped
MapperRegistry.get()is not anoperator fun, so indexed accessor syntax ([]) would not compileTest plan
./gradlew :kapper:testpassesSummary by CodeRabbit