diff options
Diffstat (limited to 'python/src/com/jetbrains/python/codeInsight/editorActions/smartEnter/fixers/PyStringLiteralFixer.java')
-rw-r--r-- | python/src/com/jetbrains/python/codeInsight/editorActions/smartEnter/fixers/PyStringLiteralFixer.java | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/python/src/com/jetbrains/python/codeInsight/editorActions/smartEnter/fixers/PyStringLiteralFixer.java b/python/src/com/jetbrains/python/codeInsight/editorActions/smartEnter/fixers/PyStringLiteralFixer.java index 906aecd9c757..3e9925a86131 100644 --- a/python/src/com/jetbrains/python/codeInsight/editorActions/smartEnter/fixers/PyStringLiteralFixer.java +++ b/python/src/com/jetbrains/python/codeInsight/editorActions/smartEnter/fixers/PyStringLiteralFixer.java @@ -17,10 +17,10 @@ package com.jetbrains.python.codeInsight.editorActions.smartEnter.fixers; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.psi.PsiElement; import com.intellij.util.IncorrectOperationException; import com.jetbrains.python.codeInsight.editorActions.smartEnter.PySmartEnterProcessor; import com.jetbrains.python.psi.PyStringLiteralExpression; +import org.jetbrains.annotations.NotNull; /** * Created by IntelliJ IDEA. @@ -28,31 +28,35 @@ import com.jetbrains.python.psi.PyStringLiteralExpression; * Date: 15.04.2010 * Time: 17:17:14 */ -public class PyStringLiteralFixer implements PyFixer { - public void apply(Editor editor, PySmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException { - if (psiElement instanceof PyStringLiteralExpression) { - final String text = psiElement.getText(); - if (StringUtil.startsWith(text, "\"\"\"")) { - final int suffixLength = StringUtil.commonSuffixLength(text, "\"\"\""); - if (suffixLength != 3) { - editor.getDocument().insertString(psiElement.getTextRange().getEndOffset(), "\"\"\"".substring(suffixLength)); - } +public class PyStringLiteralFixer extends PyFixer<PyStringLiteralExpression> { + public PyStringLiteralFixer() { + super(PyStringLiteralExpression.class); + } + + @Override + public void doApply(@NotNull Editor editor, @NotNull PySmartEnterProcessor processor, @NotNull PyStringLiteralExpression psiElement) + throws IncorrectOperationException { + final String text = psiElement.getText(); + if (StringUtil.startsWith(text, "\"\"\"")) { + final int suffixLength = StringUtil.commonSuffixLength(text, "\"\"\""); + if (suffixLength != 3) { + editor.getDocument().insertString(psiElement.getTextRange().getEndOffset(), "\"\"\"".substring(suffixLength)); } - else if (StringUtil.startsWith(text, "\'\'\'")) { - final int suffixLength = StringUtil.commonSuffixLength(text, "\'\'\'"); - if (suffixLength != 3) { - editor.getDocument().insertString(psiElement.getTextRange().getEndOffset(), "\'\'\'".substring(suffixLength)); - } + } + else if (StringUtil.startsWith(text, "\'\'\'")) { + final int suffixLength = StringUtil.commonSuffixLength(text, "\'\'\'"); + if (suffixLength != 3) { + editor.getDocument().insertString(psiElement.getTextRange().getEndOffset(), "\'\'\'".substring(suffixLength)); } - else if (StringUtil.startsWith(text, "\"")) { - if (!StringUtil.endsWith(text, "\"")) { - editor.getDocument().insertString(psiElement.getTextRange().getEndOffset(), "\""); - } + } + else if (StringUtil.startsWith(text, "\"")) { + if (!StringUtil.endsWith(text, "\"")) { + editor.getDocument().insertString(psiElement.getTextRange().getEndOffset(), "\""); } - else if (StringUtil.startsWith(text, "\'")) { - if (!StringUtil.endsWith(text, "\'")) { - editor.getDocument().insertString(psiElement.getTextRange().getEndOffset(), "\'"); - } + } + else if (StringUtil.startsWith(text, "\'")) { + if (!StringUtil.endsWith(text, "\'")) { + editor.getDocument().insertString(psiElement.getTextRange().getEndOffset(), "\'"); } } } |