Skip to content

Add CLASS_NAME support and fix Pebble template rendering for plugin templates#1144

Merged
Daniel-ADFA merged 2 commits intostagefrom
ADFA-3475
Apr 3, 2026
Merged

Add CLASS_NAME support and fix Pebble template rendering for plugin templates#1144
Daniel-ADFA merged 2 commits intostagefrom
ADFA-3475

Conversation

@Daniel-ADFA
Copy link
Copy Markdown
Contributor

  • Add CLASS_NAME token replacement in ZipRecipeExecutor for dynamic class naming in file paths and template content
  • Add KEY_CLASS_NAME constant to ZipTemplateConstants
  • Add defaultAppName field to TemplateJson for per-template project name defaults
Screen_recording_20260401_122423.mp4

…emplates

  - Add CLASS_NAME token replacement in ZipRecipeExecutor for dynamic class
    naming in file paths and template content
  - Add KEY_CLASS_NAME constant to ZipTemplateConstants
  - Add defaultAppName field to TemplateJson for per-template project name defaults
@Daniel-ADFA Daniel-ADFA requested a review from jomen-adfa April 1, 2026 11:28
@Daniel-ADFA Daniel-ADFA self-assigned this Apr 1, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 1, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 260ae579-9f41-42fe-80bf-7d724e1196f2

📥 Commits

Reviewing files that changed from the base of the PR and between 69601a0 and cd1cb46.

📒 Files selected for processing (2)
  • templates-impl/src/main/java/com/itsaky/androidide/templates/impl/zip/ZipRecipeExecutor.kt
  • templates-impl/src/main/java/com/itsaky/androidide/templates/impl/zip/ZipTemplateReader.kt
🚧 Files skipped from review as they are similar to previous changes (1)
  • templates-impl/src/main/java/com/itsaky/androidide/templates/impl/zip/ZipRecipeExecutor.kt

📝 Walkthrough

Release Notes - CLASS_NAME Support and Pebble Template Enhancements

  • Features

    • Add CLASS_NAME token replacement support for Pebble templates and ZIP entry paths to enable dynamic class naming.
    • Add KEY_CLASS_NAME constant ("CLASS_NAME") to template token definitions.
    • Add TemplateJson.optional defaultAppName field to allow per-template default project names.
    • Inject a sanitized className (derived from the project name) into Pebble template parameters so templates can reference CLASS_NAME.
    • Replace CLASS_NAME occurrences in ZIP/template-relative output paths with the computed sanitized className.
  • Implementation details

    • New constant: KEY_CLASS_NAME = "CLASS_NAME".
    • TemplateJson: new field defaultAppName: String? = null.
    • ZipRecipeExecutor computes className by stripping all non-alphanumeric characters (regex [^a-zA-Z0-9]) from the provided project name and adds it to the template identifiers used by Pebble.
    • ZipTemplateReader passes metaJson.defaultAppName as the template projectName parameter default when constructing the template.
  • Risks & best-practice considerations

    • ⚠️ Empty class name: If the project name contains only non-alphanumeric characters, sanitization may yield an empty string; no validation or fallback is added.
    • ⚠️ Invalid Java identifier: Sanitization only removes non-alphanumeric characters and does not ensure the result is a valid Java identifier (may start with a digit or be a reserved keyword).
    • ⚠️ Name collisions: Different project names can sanitize to the same className (e.g., "MyClass" and "My-Class"), risking collisions in generated files/paths.
    • ⚠️ Silent behavioral change: defaultAppName influences template defaults implicitly; lack of documentation or explicit notification could surprise users.
    • Recommendation: add validation for empty/invalid class names, enforce a safe fallback or prefix when starting with a digit, consider keyword checks, and document defaultAppName behavior.

Walkthrough

Added an optional defaultAppName metadata field and introduced sanitized class-name handling: templates now derive a className from the project name (sanitizing non-alphanumerics), expose it as a template variable, and replace CLASS_NAME placeholders in output paths.

Changes

Cohort / File(s) Summary
Template Metadata
templates-impl/.../zip/ZipJson.kt
Added optional defaultAppName: String? = null to template metadata.
Class-name handling & output path substitution
templates-impl/.../zip/ZipRecipeExecutor.kt, templates-impl/.../zip/ZipTemplateConstants.kt
Added KEY_CLASS_NAME constant and logic to derive a sanitized className (strip non-alphanumerics), inject it into template identifiers, and replace CLASS_NAME occurrences in template-relative output paths.
Reader integration for default project name
templates-impl/.../zip/ZipTemplateReader.kt
Passes projectName to baseZipProject, wiring metaJson.defaultAppName as the parameter default for projectName.

Sequence Diagram

sequenceDiagram
    participant Reader as ZipTemplateReader
    participant Meta as TemplateMeta (metaJson)
    participant Executor as ZipRecipeExecutor
    participant Pebble as Pebble Engine
    participant ZIP as ZIP Output

    Reader->>Meta: read metaJson (includes defaultAppName)
    Meta-->>Reader: return defaultAppName
    Reader->>Reader: build projectName parameter (default = defaultAppName)
    Reader->>Executor: execute recipe with data.name / projectName
    Executor->>Executor: sanitize projectName -> className (strip non-alnum)
    Executor->>Executor: assemble identifiers including KEY_CLASS_NAME
    Executor->>Pebble: render templates with identifiers
    Pebble-->>Executor: rendered files/content
    Executor->>Executor: replace CLASS_NAME in output paths with className
    Executor->>ZIP: write files to ZIP using sanitized paths
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • itsaky-adfa
  • jomen-adfa

Poem

🐰
A hop, a name, then scrub away,
Class names tidy for the day,
Defaults sprout from meta’s seed,
Paths align, the ZIPs proceed,
Hooray — templates sewn with glee! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main changes: adding CLASS_NAME support and fixing Pebble template rendering for plugin templates, which aligns with the changeset additions across multiple files.
Description check ✅ Passed The description clearly outlines all key changes: CLASS_NAME token replacement, KEY_CLASS_NAME constant, and defaultAppName field, directly matching the modifications in the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ADFA-3475

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@templates-impl/src/main/java/com/itsaky/androidide/templates/impl/zip/ZipRecipeExecutor.kt`:
- Line 37: projectNameParameter currently only has NONEMPTY and the
ZipRecipeExecutor's use of CLASS_NAME_PATTERN with replace(...) can produce
invalid Java identifiers (e.g., leading digits or empty strings); update the
code so either projectNameParameter includes the CLASS_NAME constraint or change
ZipRecipeExecutor sanitization: after applying CLASS_NAME_PATTERN removal, strip
any leading digits, ensure the result starts with a valid Java identifier start
(letter or underscore), and if it becomes empty fallback to a safe default
(e.g., "Project" + timestamp or a sanitized projectNameParameter), referencing
CLASS_NAME_PATTERN and the method in ZipRecipeExecutor that performs the replace
to locate where to implement these checks and fallback logic.

In
`@templates-impl/src/main/java/com/itsaky/androidide/templates/impl/zip/ZipTemplateReader.kt`:
- Around line 89-91: The code sets projectName = projectNameParameter {
metaJson.defaultAppName?.let { default = it } } and allows an empty/whitespace
defaultAppName to override the built-in default; change this to only assign
metaJson.defaultAppName when it is non-blank by trimming and checking
isNotBlank() (or equivalent) before setting default so that blank or whitespace
values do not replace the existing "My Application" fallback.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c2b6d9a7-efc3-4851-90d3-a55f3ad63fa6

📥 Commits

Reviewing files that changed from the base of the PR and between 90bfbcf and 69601a0.

📒 Files selected for processing (4)
  • templates-impl/src/main/java/com/itsaky/androidide/templates/impl/zip/ZipJson.kt
  • templates-impl/src/main/java/com/itsaky/androidide/templates/impl/zip/ZipRecipeExecutor.kt
  • templates-impl/src/main/java/com/itsaky/androidide/templates/impl/zip/ZipTemplateConstants.kt
  • templates-impl/src/main/java/com/itsaky/androidide/templates/impl/zip/ZipTemplateReader.kt

# Conflicts:
#	templates-impl/src/main/java/com/itsaky/androidide/templates/impl/zip/ZipRecipeExecutor.kt
@Daniel-ADFA Daniel-ADFA merged commit c85bf67 into stage Apr 3, 2026
2 checks passed
@Daniel-ADFA Daniel-ADFA deleted the ADFA-3475 branch April 3, 2026 17:49
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