ADFA-2573: Add language option to create new class#867
Conversation
|
closes #838 |
📝 WalkthroughRelease Notes: Language Option for Create New Class (ADFA-2573)Features
Changes Made
|
| 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 | 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.
Comment @coderabbitai help to get the list of available commands and usage tips.
There was a problem hiding this comment.
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/.*/javaOR justktanywhere. To match bothjavaandktdirectories, 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 separatesrc/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 thetype_classicon dynamically based on language selection.The
type_classbutton usesic_language_javaicon 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 usingbuildKotlinFileincreateKotlinActivityfor consistency.The
buildKotlinFilehelper handles package declaration, butcreateKotlinActivity(lines 119-135) duplicates this logic. Consider refactoringcreateKotlinActivityto usebuildKotlinFilefor 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("}") } }
Screen.Recording.2026-01-22.at.12.30.50.mov