Skip to content

ADFA-2573: Add language option to create new class#867

Merged
Daniel-ADFA merged 2 commits intostagefrom
ADFA-2573
Jan 22, 2026
Merged

ADFA-2573: Add language option to create new class#867
Daniel-ADFA merged 2 commits intostagefrom
ADFA-2573

Conversation

@Daniel-ADFA
Copy link
Contributor

@Daniel-ADFA Daniel-ADFA commented Jan 22, 2026

Screen.Recording.2026-01-22.at.12.30.50.mov

@Daniel-ADFA
Copy link
Contributor Author

Daniel-ADFA commented Jan 22, 2026

closes #838

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 22, 2026

📝 Walkthrough

Release Notes: Language Option for Create New Class (ADFA-2573)

Features

  • Multi-language support: Added ability to create new classes, interfaces, enums, and activities in both Java and Kotlin
  • Language selection UI: New toggle button group in the file creation dialog allowing users to select between Java and Kotlin
  • Kotlin code generation: Implemented Kotlin-specific generation for classes, interfaces, enums, and activities (with proper AppCompatActivity or Activity extension)
  • Dynamic file extension handling: Automatically applies correct file extensions (.java or .kt) based on selected language
  • Unified file creation API: Consolidated createJavaX methods into language-aware createX methods across ProjectWriter and ClassBuilder

Changes Made

  • NewFileAction.kt: Refactored doCreateJavaFile()doCreateSourceFile() with language detection from UI toggle
  • ClassBuilder.kt:
    • New public SourceLanguage enum (JAVA, KOTLIN)
    • Updated createClass(), createInterface(), createEnum(), createActivity() with language parameter (defaults to JAVA)
    • Added Kotlin-specific generation helpers for activities and file structure
  • ProjectWriter.java: Updated method signatures to support language-aware creation (removed createJavaX naming convention)
  • UI: Added MaterialButtonToggleGroup with Java/Kotlin language buttons in create file dialog
  • Resources: Added string resources for language labels and dialog titles

⚠️ Risks & Best Practice Violations

  1. Breaking API Change: Method renaming from createJavaClass()createClass() removes language-specific naming and may break existing callers. Default parameter value (JAVA) helps, but refactoring across the codebase is required.

  2. Incomplete backward compatibility: Old methods like createJavaClass(), createJavaInterface(), createJavaEnum() were removed entirely. Consider keeping deprecated wrapper methods for external consumers or third-party integrations.

  3. Kotlin generation maturity: New Kotlin code generation paths use a minimal StringBuilder-based builder rather than leveraging a mature Kotlin code generation library (like KotlinPoet). Verify generated Kotlin code quality and completeness against best practices.

  4. Required UI selection: Language toggle is marked as required in the layout, which changes the user interaction model. Ensure existing workflows and scripts that programmatically create files still function correctly.

  5. Method signature complexity: ProjectWriter methods now require explicit SourceLanguage parameter with no default value in the public API (Java interface), potentially requiring updates across all call sites.

  6. Testing coverage: Ensure new Kotlin generation paths are thoroughly tested for various scenarios (AppCompat activities, non-AppCompat activities, package structures, imports).

Walkthrough

This PR extends the file creation workflow to support Kotlin in addition to Java. A new SourceLanguage enum is introduced to govern code generation, UI toggles enable language selection, and Kotlin-specific code generators are implemented across the builder and action layers.

Changes

Cohort / File(s) Summary
Language Support Infrastructure
app/src/main/java/com/itsaky/androidide/utils/ClassBuilder.kt, app/src/main/java/com/itsaky/androidide/utils/ProjectWriter.java
Added public SourceLanguage enum (JAVA, KOTLIN). Refactored createClass, createInterface, createEnum, createActivity methods to accept language parameter. Implemented Kotlin code generation paths with dedicated builders for activities and classes; Java paths remain via JavaPoet.
File Creation Action & UI
app/src/main/java/com/itsaky/androidide/actions/filetree/NewFileAction.kt, app/src/main/res/layout/layout_create_file_java.xml
Renamed doCreateJavaFile to doCreateSourceFile. Added MaterialButtonToggleGroup with lang_java/lang_kotlin toggles for user language selection. Dynamic file extension logic (.kt vs .java) and layout naming based on selected language.
String Resources
resources/src/main/res/values/strings.xml
Added three new string resources: lang_java, lang_kotlin, new_kotlin_class.

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Suggested Reviewers

  • itsaky-adfa
  • jatezzz
  • jomen-adfa

Poem

A rabbit's quill now writes in two,
Java and Kotlin, both shine through! 🐰✨
With toggles bright and builders wise,
Source files bloom before your eyes.
Hop along—the languages unite,
In harmony, the code burns bright! 🔥

🚥 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 PR title accurately and concisely describes the main change: adding a language option to the class creation feature, which is reflected throughout the changeset.
Description check ✅ Passed The PR description contains a video link that appears to demonstrate the language selection feature, which relates to the changeset's implementation of language options for class creation.

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

✨ Finishing touches
  • 📝 Generate docstrings

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
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: 1

Caution

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

⚠️ Outside diff range comments (2)
app/src/main/java/com/itsaky/androidide/utils/ProjectWriter.java (1)

34-34: Regex pattern may not match Kotlin directories correctly.

The regex "/.*/src/.*/java|kt" likely doesn't work as intended. The | operator has low precedence, so this matches either /.*/src/.*/java OR just kt anywhere. To match both java and kt directories, use a non-capturing group.

🐛 Proposed fix
- private static final String SOURCE_PATH_REGEX = "/.*/src/.*/java|kt";
+ private static final String SOURCE_PATH_REGEX = "/.*/src/.*/(?:java|kt)";
app/src/main/java/com/itsaky/androidide/actions/filetree/NewFileAction.kt (1)

306-328: Layout path calculation may not work for Kotlin source sets.

Line 313 replaces "java/$packagePath" with "res/layout/", but Kotlin files may be in a "kotlin/" source directory. If the project uses separate src/main/kotlin/ directories, the layout file won't be created in the correct location.

🐛 Proposed fix to handle both source directories
  private fun createAutoLayout(
    context: Context,
    directory: File,
    fileName: String,
    packagePath: String,
    isKotlin: Boolean = false
  ) {
-   val dir = directory.toString().replace("java/$packagePath", "res/layout/")
+   val dir = directory.toString()
+     .replace("java/$packagePath", "res/layout/")
+     .replace("kotlin/$packagePath", "res/layout/")
    val sourceExtension = if (isKotlin) ".kt" else ".java"
    val layoutName = ProjectWriter.createLayoutName(fileName.replace(sourceExtension, ".xml"))
🤖 Fix all issues with AI agents
In `@resources/src/main/res/values/strings.xml`:
- Around line 214-216: The string resource "new_kotlin_class" is defined but
unused; either remove the <string name="new_kotlin_class"> entry from
strings.xml, or replace any hard-coded "New Kotlin class" UI text with a
reference to `@string/new_kotlin_class` (e.g., in the file-creation
layout/activity that parallels layout_create_file_java.xml or the code that sets
button/text labels). Search for UI elements that create new Kotlin files and
update them to use the "new_kotlin_class" resource, or delete the resource if no
UI needs it.
🧹 Nitpick comments (2)
app/src/main/res/layout/layout_create_file_java.xml (1)

60-66: Consider updating the type_class icon dynamically based on language selection.

The type_class button uses ic_language_java icon regardless of whether Java or Kotlin is selected in the language toggle above. For better UX consistency, consider updating this icon programmatically when the language selection changes.

app/src/main/java/com/itsaky/androidide/utils/ClassBuilder.kt (1)

137-143: Consider using buildKotlinFile in createKotlinActivity for consistency.

The buildKotlinFile helper handles package declaration, but createKotlinActivity (lines 119-135) duplicates this logic. Consider refactoring createKotlinActivity to use buildKotlinFile for consistency.

♻️ Suggested refactor
  private fun createKotlinActivity(packageName: String, className: String, appCompatActivity: Boolean): String {
    val superClass = if (appCompatActivity) "AppCompatActivity" else "Activity"
    val import = if (appCompatActivity) "androidx.appcompat.app.AppCompatActivity" else "android.app.Activity"
-   return buildString {
-     if (packageName.isNotEmpty()) appendLine("package $packageName")
-     appendLine()
+   return buildKotlinFile(packageName) {
      appendLine("import android.os.Bundle")
      appendLine("import $import")
      appendLine()
      appendLine("class $className : $superClass() {")
      appendLine()
      appendLine("${indentationString}override fun onCreate(savedInstanceState: Bundle?) {")
      appendLine("${indentationString}${indentationString}super.onCreate(savedInstanceState)")
      appendLine("$indentationString}")
      appendLine("}")
    }
  }

@Daniel-ADFA Daniel-ADFA merged commit 8829435 into stage Jan 22, 2026
2 checks passed
@Daniel-ADFA Daniel-ADFA deleted the ADFA-2573 branch January 22, 2026 13:54
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