From d9d898d2d6c1617dbf9610dc57d36331d6e895b9 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 29 Nov 2013 14:03:08 +0100 Subject: [PATCH] EA-52459 (assert: JavaParserUtil.parseFragment) --- .../generate/tostring/GenerateToStringWorker.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/plugins/generate-tostring/src/org/jetbrains/generate/tostring/GenerateToStringWorker.java b/plugins/generate-tostring/src/org/jetbrains/generate/tostring/GenerateToStringWorker.java index 76f7233c1317..5a85d72f8dcd 100644 --- a/plugins/generate-tostring/src/org/jetbrains/generate/tostring/GenerateToStringWorker.java +++ b/plugins/generate-tostring/src/org/jetbrains/generate/tostring/GenerateToStringWorker.java @@ -19,6 +19,7 @@ */ package org.jetbrains.generate.tostring; +import com.intellij.codeInsight.hint.HintManager; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.diagnostic.Logger; @@ -159,8 +160,18 @@ public class GenerateToStringWorker { // create psi newMethod named toString() final JVMElementFactory topLevelFactory = JVMElementFactories.getFactory(clazz.getLanguage(), clazz.getProject()); - PsiMethod newMethod = topLevelFactory.createMethodFromText(template.getMethodSignature() + " { " + body + " }", clazz); - CodeStyleManager.getInstance(clazz.getProject()).reformat(newMethod); + if (topLevelFactory == null) { + return null; + } + PsiMethod newMethod; + try { + newMethod = topLevelFactory.createMethodFromText(template.getMethodSignature() + " { " + body + " }", clazz); + CodeStyleManager.getInstance(clazz.getProject()).reformat(newMethod); + } catch (IncorrectOperationException ignore) { + HintManager.getInstance().showErrorHint(editor, "'toString()' method could not be created from template '" + + template.getFileName() + '\''); + return null; + } // insertNewMethod conflict resolution policy (add/replace, duplicate, cancel) PsiMethod existingMethod = clazz.findMethodBySignature(newMethod, false);