File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed
java/src/main/kotlin/cc/unitmesh/idea/context Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -60,12 +60,17 @@ open class JavaCodeModifier : CodeModifier {
60
60
61
61
val newTestMethod = ReadAction .compute<PsiMethod , Throwable > {
62
62
val psiElementFactory = PsiElementFactory .getInstance(project)
63
- val methodCode = psiElementFactory.createMethodFromText(code, rootElement)
64
- if (rootElement.findMethodsByName(methodCode.name, false ).isNotEmpty()) {
65
- log.error(" Method already exists in the class: ${methodCode.name} " )
63
+ try {
64
+ val methodCode = psiElementFactory.createMethodFromText(code, rootElement)
65
+ if (rootElement.findMethodsByName(methodCode.name, false ).isNotEmpty()) {
66
+ log.error(" Method already exists in the class: ${methodCode.name} " )
67
+ }
68
+
69
+ methodCode
70
+ } catch (e: Throwable ) {
71
+ log.error(" Failed to create method from text: $code " , e)
72
+ return @compute null
66
73
}
67
-
68
- methodCode
69
74
}
70
75
71
76
WriteCommandAction .runWriteCommandAction(project) {
You can’t perform that action at this time.
0 commit comments