@@ -122,6 +122,7 @@ class SqlAnnotationConverter(
122122 annotation : PsiAnnotation ,
123123 value : Boolean ,
124124 ) {
125+ var existsAnnotation = annotation
125126 val useSqlFileOptionAnnotationList =
126127 listOf (
127128 DomaAnnotationType .Insert ,
@@ -132,6 +133,7 @@ class SqlAnnotationConverter(
132133 DomaAnnotationType .BatchDelete ,
133134 )
134135
136+ val documentManager = PsiDocumentManager .getInstance(project)
135137 if (useSqlFileOptionAnnotationList.contains(psiDaoMethod.daoType)) {
136138 val existingAttribute =
137139 annotation.parameterList.attributes
@@ -153,17 +155,26 @@ class SqlAnnotationConverter(
153155 annotation.parameterList.add(newAttribute)
154156 }
155157 } else {
156- // Remove sqlFile parameter when value is false
157158 existingAttribute?.delete()
159+ // If no attributes remain, recreate annotation without parentheses
160+ if (annotation.parameterList.attributes.isEmpty()) {
161+ val annotationName = annotation.qualifiedName
162+ val newAnnotationText = " @$annotationName "
163+ val newAnnotation = elementFactory.createAnnotationFromText(newAnnotationText, annotation)
164+ val modifierList = method.modifierList
165+ modifierList.addBefore(newAnnotation, annotation)
166+ annotation.delete()
167+ existsAnnotation = newAnnotation
168+ }
158169 }
159170 }
160171
161172 val psiFile = annotation.containingFile
162- val document = PsiDocumentManager .getInstance(project) .getDocument(psiFile)
173+ val document = documentManager .getDocument(psiFile)
163174 if (document != null ) {
164- PsiDocumentManager .getInstance(project) .doPostponedOperationsAndUnblockDocument(document)
175+ documentManager .doPostponedOperationsAndUnblockDocument(document)
165176 }
166- JavaCodeStyleManager .getInstance(project).shortenClassReferences(annotation )
177+ JavaCodeStyleManager .getInstance(project).shortenClassReferences(existsAnnotation )
167178 }
168179
169180 private fun addSqlAnnotation (sqlContent : String ) {
@@ -187,9 +198,10 @@ class SqlAnnotationConverter(
187198 modifierList.add(sqlAnnotation)
188199 }
189200 val psiFile = method.containingFile
190- val document = PsiDocumentManager .getInstance(project).getDocument(psiFile)
201+ val documentManager = PsiDocumentManager .getInstance(project)
202+ val document = documentManager.getDocument(psiFile)
191203 if (document != null ) {
192- PsiDocumentManager .getInstance(project) .doPostponedOperationsAndUnblockDocument(document)
204+ documentManager .doPostponedOperationsAndUnblockDocument(document)
193205 }
194206 // Add import if needed
195207 val containingFile = method.containingFile
@@ -213,18 +225,18 @@ class SqlAnnotationConverter(
213225 )
214226 importList?.add(importStatement)
215227 val psiFile = method.containingFile
216- val document = PsiDocumentManager .getInstance(project) .getDocument(psiFile)
228+ val document = documentManager .getDocument(psiFile)
217229 if (document != null ) {
218- PsiDocumentManager .getInstance(project) .doPostponedOperationsAndUnblockDocument(document)
230+ documentManager .doPostponedOperationsAndUnblockDocument(document)
219231 }
220232 }
221233 }
222234
223235 // Jump to method
224236 val newDaoFile = method.containingFile
225- val newDocument = PsiDocumentManager .getInstance(project) .getDocument(newDaoFile)
237+ val newDocument = documentManager .getDocument(newDaoFile)
226238 if (newDocument != null ) {
227- PsiDocumentManager .getInstance(project) .doPostponedOperationsAndUnblockDocument(newDocument)
239+ documentManager .doPostponedOperationsAndUnblockDocument(newDocument)
228240 }
229241 jumpToDaoMethod(project, psiDaoMethod.sqlFile?.name ? : return , newDaoFile.virtualFile)
230242 }
0 commit comments