From 56abb5d4aabc79bc1a9a3c0e271de232a01f8845 Mon Sep 17 00:00:00 2001 From: anna Date: Wed, 21 Mar 2012 17:54:52 +0100 Subject: [PATCH] EA-32874 - NPE: SaveAsTemplateAction$$.run (cherry picked from commit c432ab8) --- .../codeInsight/template/actions/SaveAsTemplateAction.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/actions/SaveAsTemplateAction.java b/platform/lang-impl/src/com/intellij/codeInsight/template/actions/SaveAsTemplateAction.java index 2f98eba152d3..fe03497854a1 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/actions/SaveAsTemplateAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/actions/SaveAsTemplateAction.java @@ -31,6 +31,7 @@ import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.command.CommandProcessor; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorFactory; @@ -48,6 +49,8 @@ import java.util.Set; public class SaveAsTemplateAction extends AnAction { + private static final Logger LOG = Logger.getInstance("#" + SaveAsTemplateAction.class.getName()); + public void actionPerformed(AnActionEvent e) { DataContext dataContext = e.getDataContext(); final Editor editor = PlatformDataKeys.EDITOR.getData(dataContext); @@ -89,7 +92,9 @@ public class SaveAsTemplateAction extends AnAction { if (!(reference instanceof PsiQualifiedReference) || ((PsiQualifiedReference) reference).getQualifier() == null) { String canonicalText = reference.getCanonicalText(); TextRange referenceRange = reference.getRangeInElement(); - TextRange range = element.getTextRange().cutOut(referenceRange).shiftRight(-offsetDelta); + final TextRange elementTextRange = element.getTextRange(); + LOG.assertTrue(elementTextRange != null, elementTextRange); + final TextRange range = elementTextRange.cutOut(referenceRange).shiftRight(-offsetDelta); final String oldText = document.getText(range); // workaround for Java references: canonicalText contains generics, and we need to cut them off because otherwise // they will be duplicated