File tree 1 file changed +14
-4
lines changed
src/main/kotlin/wu/seal/jsontokotlin/utils 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ class KotlinClassFileGenerator {
19
19
) {
20
20
val fileNamesWithoutSuffix = currentDirExistsFileNamesWithoutKTSuffix(directory)
21
21
var kotlinClassForGenerateFile = kotlinClass
22
- while (fileNamesWithoutSuffix.contains(kotlinClass .name)) {
22
+ while (fileNamesWithoutSuffix.contains(kotlinClassForGenerateFile .name)) {
23
23
kotlinClassForGenerateFile =
24
24
kotlinClassForGenerateFile.rename(newName = kotlinClassForGenerateFile.name + " X" )
25
25
}
@@ -110,11 +110,21 @@ class KotlinClassFileGenerator {
110
110
}
111
111
append(classCodeContent)
112
112
}
113
+
114
+ var finalFileName = fileName.trim(' `' )
115
+ var ktFileName = " $finalFileName .kt"
116
+
117
+ // Check if file already exists and rename it by adding 'X' suffix if needed
118
+ val fileNamesWithoutSuffix = currentDirExistsFileNamesWithoutKTSuffix(directory)
119
+ while (fileNamesWithoutSuffix.contains(finalFileName)) {
120
+ finalFileName + = " X"
121
+ ktFileName = " $finalFileName .kt"
122
+ }
123
+
124
+ // Create the file with the potentially modified name
113
125
executeCouldRollBackAction(project) {
114
- val file =
115
- psiFileFactory.createFileFromText(" ${fileName.trim(' `' )} .kt" , KotlinFileType (), kotlinFileContent)
126
+ val file = psiFileFactory.createFileFromText(ktFileName, KotlinFileType (), kotlinFileContent)
116
127
directory.add(file)
117
128
}
118
129
}
119
-
120
130
}
You can’t perform that action at this time.
0 commit comments