File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed
src/main/kotlin/wu/seal/jsontokotlin/utils Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ class KotlinClassFileGenerator {
1919 ) {
2020 val fileNamesWithoutSuffix = currentDirExistsFileNamesWithoutKTSuffix(directory)
2121 var kotlinClassForGenerateFile = kotlinClass
22- while (fileNamesWithoutSuffix.contains(kotlinClass .name)) {
22+ while (fileNamesWithoutSuffix.contains(kotlinClassForGenerateFile .name)) {
2323 kotlinClassForGenerateFile =
2424 kotlinClassForGenerateFile.rename(newName = kotlinClassForGenerateFile.name + " X" )
2525 }
@@ -110,11 +110,21 @@ class KotlinClassFileGenerator {
110110 }
111111 append(classCodeContent)
112112 }
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
113125 executeCouldRollBackAction(project) {
114- val file =
115- psiFileFactory.createFileFromText(" ${fileName.trim(' `' )} .kt" , KotlinFileType (), kotlinFileContent)
126+ val file = psiFileFactory.createFileFromText(ktFileName, KotlinFileType (), kotlinFileContent)
116127 directory.add(file)
117128 }
118129 }
119-
120130}
You can’t perform that action at this time.
0 commit comments