Skip to content

Fix Factory generator - #129

Merged
matejsemancik merged 2 commits into
developfrom
fix/factory-generator
Nov 16, 2025
Merged

Fix Factory generator#129
matejsemancik merged 2 commits into
developfrom
fix/factory-generator

Conversation

@matejsemancik

@matejsemancik matejsemancik commented Sep 15, 2025

Copy link
Copy Markdown
Member

The factory generator now uniformly handles all injected parameters via the @InjectedParam annotation, removing special handling for AppComponentContext and Navigation. This simplifies the parameter injection logic. Also, the package name has been updated to app.futured.arkitekt.factorygenerator.processor.

Summary by CodeRabbit

  • Refactor

    • Simplified generated createComponent API: removed AppComponentContext and Navigation parameters; only @InjectedParam inputs are required. Update any call sites accordingly.
  • Chores

    • Updated processor and provider package/namespace to app.futured.arkitekt.factorygenerator.processor.
    • Adjusted service registration to the new provider path.

Impact: Consumers may need to update imports and regenerate code to align with the new createComponent signature.

…injection

The factory generator now uniformly handles all injected parameters via the `@InjectedParam` annotation, removing special handling for `AppComponentContext` and `Navigation`. This simplifies the parameter injection logic. Also, the package name has been updated to `app.futured.arkitekt.factorygenerator.processor`.
@coderabbitai

coderabbitai Bot commented Sep 15, 2025

Copy link
Copy Markdown

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Fix Factory generator" is short and directly related to the main change in the PR (updates to the factory generator to uniformly handle @InjectedParam and remove special-casing for AppComponentContext and Navigation), so it adequately summarizes the primary intent for a quick scan.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/factory-generator

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
shared/arkitekt-decompose/processor/src/jvmMain/kotlin/app/futured/arkitekt/factorygenerator/processor/PoetFactoryComponentGenerator.kt (1)

12-13: Bug: return type breaks for nested classes; use toClassName().

Building ClassName(package, listOf(baseName)) fails for Outer.Inner components. Use KotlinPoet KSP’s toClassName().

Apply this diff:

@@
-import com.squareup.kotlinpoet.ksp.toTypeName
+import com.squareup.kotlinpoet.ksp.toTypeName
+import com.squareup.kotlinpoet.ksp.toClassName
@@
-        val returnType = ClassName(
-            packageName = factoryComponentPackageName,
-            simpleNames = listOf(baseName),
-        )
+        val returnType = factoryComponent.toClassName()

Also applies to: 117-121

🧹 Nitpick comments (4)
shared/arkitekt-decompose/processor/src/jvmMain/kotlin/app/futured/arkitekt/factorygenerator/processor/PoetFactoryComponentGenerator.kt (3)

33-35: KDoc is stale after removing special-cases.

It still claims handling of AppComponentContext/Navigation/Arg. Please update to reflect the new uniform @InjectedParam-only behavior.

Apply this diff:

- * 4.  **Handles Special Types:** Detects and handles special types like `AppComponentContext`,
- *     `Navigation`, and `Arg` for specific component needs.
+ * 4.  No special‑casing of types: only constructor parameters annotated with `@InjectedParam` are considered.

77-80: Improve KSP incrementality: mark files as isolating and set origins.

This generator produces one file per annotated class; prefer aggregating = false with originating files set.

Apply this diff:

-        fileSpec.writeTo(codeGenerator, aggregating = true)
+        fileSpec.writeTo(
+            codeGenerator = codeGenerator,
+            aggregating = false,
+            originatingKSFiles = listOfNotNull(factoryComponent.containingFile),
+        )

142-148: Remove dead helpers.

findTypeByName and containsTypeName are unused after dropping special‑cases.

Apply this diff:

-    private fun List<KSValueParameter>.findTypeByName(name: String): TypeName? = this
-        .find { it.containsTypeName(name) }
-        ?.type?.toTypeName()
-
-    private fun KSValueParameter.containsTypeName(name: String): Boolean =
-        this.type.toTypeName().toString().contains(name)
shared/arkitekt-decompose/processor/src/jvmMain/kotlin/app/futured/arkitekt/factorygenerator/processor/ComponentFactoryProcessorProvider.kt (1)

8-10: Optional: pass logger/options to the processor if you plan diagnostics later.

Not required now, but wiring environment.logger and environment.options gives better error reporting.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 57789ce and 62f11dc.

📒 Files selected for processing (4)
  • shared/arkitekt-decompose/processor/src/jvmMain/kotlin/app/futured/arkitekt/factorygenerator/processor/ComponentFactoryProcessor.kt (1 hunks)
  • shared/arkitekt-decompose/processor/src/jvmMain/kotlin/app/futured/arkitekt/factorygenerator/processor/ComponentFactoryProcessorProvider.kt (1 hunks)
  • shared/arkitekt-decompose/processor/src/jvmMain/kotlin/app/futured/arkitekt/factorygenerator/processor/PoetFactoryComponentGenerator.kt (3 hunks)
  • shared/arkitekt-decompose/processor/src/jvmMain/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.kt

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.kt: Error handling: Use sealed NetworkError classes and model operations as results (Success/Failure)
Max 25 functions per class
Max 20 functions per file

Files:

  • shared/arkitekt-decompose/processor/src/jvmMain/kotlin/app/futured/arkitekt/factorygenerator/processor/ComponentFactoryProcessorProvider.kt
  • shared/arkitekt-decompose/processor/src/jvmMain/kotlin/app/futured/arkitekt/factorygenerator/processor/ComponentFactoryProcessor.kt
  • shared/arkitekt-decompose/processor/src/jvmMain/kotlin/app/futured/arkitekt/factorygenerator/processor/PoetFactoryComponentGenerator.kt
**/*.{kt,kts}

📄 CodeRabbit inference engine (CLAUDE.md)

Max line length: 140 characters

Files:

  • shared/arkitekt-decompose/processor/src/jvmMain/kotlin/app/futured/arkitekt/factorygenerator/processor/ComponentFactoryProcessorProvider.kt
  • shared/arkitekt-decompose/processor/src/jvmMain/kotlin/app/futured/arkitekt/factorygenerator/processor/ComponentFactoryProcessor.kt
  • shared/arkitekt-decompose/processor/src/jvmMain/kotlin/app/futured/arkitekt/factorygenerator/processor/PoetFactoryComponentGenerator.kt
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: check-android / Lint & Tests
  • GitHub Check: check-ios / Test
🔇 Additional comments (5)
shared/arkitekt-decompose/processor/src/jvmMain/kotlin/app/futured/arkitekt/factorygenerator/processor/ComponentFactoryProcessor.kt (1)

1-1: Package rename looks correct and consistent.

Matches the updated service loader path in resources.

shared/arkitekt-decompose/processor/src/jvmMain/kotlin/app/futured/arkitekt/factorygenerator/processor/PoetFactoryComponentGenerator.kt (2)

125-129: LGTM: parameters only from @InjectedParam.

The apply block cleanly limits the signature to injected params.


135-137: LGTM: explicit qualifier=null and parametersOf(...)

Works with zero or more params; trailing comma formatting is fine.

shared/arkitekt-decompose/processor/src/jvmMain/kotlin/app/futured/arkitekt/factorygenerator/processor/ComponentFactoryProcessorProvider.kt (1)

1-1: Package rename aligned with source files and service loader.

Looks consistent with the resources entry.

shared/arkitekt-decompose/processor/src/jvmMain/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider (1)

1-1: Service loader path updated correctly.

Matches the new package. Please run a sample build to confirm KSP discovery.

Comment on lines 106 to 109
val unInjectedConstructorParams = factoryComponent.primaryConstructor?.parameters
?.filter { it.annotations.any { it.shortName.asString() == INJECTED_PARAM_ANNOTATION } }
?: error("No @InjectedParam annotation found in $baseName's constructor")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Don’t hard‑fail when no constructor or no @InjectedParam; treat as zero params.

The current error(...) aborts codegen for components with no primary constructor or no injected params. Generating createComponent() with parametersOf() is fine.

Apply this diff:

-        val unInjectedConstructorParams = factoryComponent.primaryConstructor?.parameters
-            ?.filter { it.annotations.any { it.shortName.asString() == INJECTED_PARAM_ANNOTATION } }
-            ?: error("No @InjectedParam annotation found in $baseName's constructor")
+        val unInjectedConstructorParams = factoryComponent.primaryConstructor
+            ?.parameters
+            ?.filter { it.annotations.any { it.shortName.asString() == INJECTED_PARAM_ANNOTATION } }
+            .orEmpty()
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
val unInjectedConstructorParams = factoryComponent.primaryConstructor?.parameters
?.filter { it.annotations.any { it.shortName.asString() == INJECTED_PARAM_ANNOTATION } }
?: error("No @InjectedParam annotation found in $baseName's constructor")
val unInjectedConstructorParams = factoryComponent.primaryConstructor
?.parameters
?.filter { it.annotations.any { it.shortName.asString() == INJECTED_PARAM_ANNOTATION } }
.orEmpty()

@github-actions

Copy link
Copy Markdown
3 Warnings
⚠️ Feature or fix PR title should include JIRA-ID and short description.
⚠️ Feature or fix PR branch name should include JIRA-ID and short description.
⚠️ Please start subject with capital letter.
62f11dc

Generated by 🚫 Danger

@github-actions

Copy link
Copy Markdown
2 Warnings
⚠️ Feature or fix PR title should include JIRA-ID and short description.
⚠️ Feature or fix PR branch name should include JIRA-ID and short description.

Generated by 🚫 Danger

@matejsemancik
matejsemancik merged commit fa63641 into develop Nov 16, 2025
5 checks passed
@matejsemancik
matejsemancik deleted the fix/factory-generator branch November 16, 2025 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants