mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-20541 Introduce PyBaseIntentionAction that checks if current file is read-only
All PyCharm's intentions now extend this super class. Because it inherits from BaseIntentionAction it also allowed to remove some boilreplate related to specifying that intention should run in the write action and bookkeeping of intention's text.
This commit is contained in:
+3
-3
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.jetbrains.python.codeInsight.intentions;
|
||||
|
||||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -51,7 +50,7 @@ import static com.jetbrains.python.psi.PyUtil.sure;
|
||||
* <br/>
|
||||
* Author: Alexey.Ivanov, dcheryasov
|
||||
*/
|
||||
public class ConvertFormatOperatorToMethodIntention extends BaseIntentionAction {
|
||||
public class ConvertFormatOperatorToMethodIntention extends PyBaseIntentionAction {
|
||||
|
||||
private static final Pattern FORMAT_PATTERN =
|
||||
Pattern.compile("%(?:\\((\\w+)\\))?([-#0+ ]*)((?:\\*|\\d+)?(?:\\.(?:\\*|\\d+))?)?[hlL]?([diouxXeEfFgGcrs%])");
|
||||
@@ -255,7 +254,8 @@ public class ConvertFormatOperatorToMethodIntention extends BaseIntentionAction
|
||||
return false;
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
@Override
|
||||
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
final PsiElement elementAt = file.findElementAt(editor.getCaretModel().getOffset());
|
||||
final PyBinaryExpression element = PsiTreeUtil.getParentOfType(elementAt, PyBinaryExpression.class, false);
|
||||
if (element == null) return;
|
||||
|
||||
+2
-2
@@ -48,7 +48,7 @@ import java.util.function.BiPredicate;
|
||||
* doSomething(foo)
|
||||
*
|
||||
*/
|
||||
public class ConvertVariadicParamIntention extends BaseIntentionAction {
|
||||
public class ConvertVariadicParamIntention extends PyBaseIntentionAction {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
@@ -106,7 +106,7 @@ public class ConvertVariadicParamIntention extends BaseIntentionAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
final PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
|
||||
final PyFunction function = PsiTreeUtil.getParentOfType(element, PyFunction.class);
|
||||
|
||||
|
||||
+4
-15
@@ -16,7 +16,6 @@
|
||||
package com.jetbrains.python.codeInsight.intentions;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
@@ -52,9 +51,7 @@ import static com.jetbrains.python.psi.PyUtil.sure;
|
||||
* Date: Sep 26, 2009 9:12:28 AM
|
||||
* </small>
|
||||
*/
|
||||
public class ImportFromToImportIntention implements IntentionAction {
|
||||
private String myText;
|
||||
|
||||
public class ImportFromToImportIntention extends PyBaseIntentionAction {
|
||||
/**
|
||||
* This class exists to extract bunches of info we can't store in our stateless instance.
|
||||
* Instead, we store it per thread.
|
||||
@@ -92,11 +89,6 @@ public class ImportFromToImportIntention implements IntentionAction {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getText() {
|
||||
return myText;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiElement getElementFromEditor(Editor editor, PsiFile file) {
|
||||
PsiElement element = null;
|
||||
@@ -176,7 +168,7 @@ public class ImportFromToImportIntention implements IntentionAction {
|
||||
info.myModuleName = PyPsiUtils.toPath(info.myModuleReference);
|
||||
}
|
||||
if (info.myModuleReference != null && info.myModuleName != null && info.myFromImportStatement != null) {
|
||||
myText = info.getText();
|
||||
setText(info.getText());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -194,7 +186,8 @@ public class ImportFromToImportIntention implements IntentionAction {
|
||||
target_node.addChild(sure(generator.createFromText(LanguageLevel.getDefault(), PyReferenceExpression.class, qualifier, new int[]{0,0}).getNode()), target_node.getFirstChildNode());
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
@Override
|
||||
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
InfoHolder info = InfoHolder.collect(getElementFromEditor(editor, file));
|
||||
try {
|
||||
String qualifier; // we don't always qualify with module name
|
||||
@@ -299,9 +292,5 @@ public class ImportFromToImportIntention implements IntentionAction {
|
||||
PyUtil.showBalloon(project, PyBundle.message("QFIX.action.failed"), MessageType.WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean startInWriteAction() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-15
@@ -16,7 +16,6 @@
|
||||
package com.jetbrains.python.codeInsight.intentions;
|
||||
|
||||
import com.intellij.codeInsight.FileModificationService;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.MessageType;
|
||||
@@ -49,7 +48,7 @@ import static com.jetbrains.python.psi.PyUtil.sure;
|
||||
* <small>User: dcheryasov
|
||||
* Date: Sep 22, 2009 1:42:52 AM</small>
|
||||
*/
|
||||
public class ImportToImportFromIntention implements IntentionAction {
|
||||
public class ImportToImportFromIntention extends PyBaseIntentionAction {
|
||||
|
||||
private static class IntentionState {
|
||||
private String myModuleName = null;
|
||||
@@ -221,13 +220,6 @@ public class ImportToImportFromIntention implements IntentionAction {
|
||||
}
|
||||
}
|
||||
|
||||
private String myText;
|
||||
|
||||
@NotNull
|
||||
public String getText() {
|
||||
return myText;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INTN.Family.convert.import.unqualify");
|
||||
@@ -253,18 +245,15 @@ public class ImportToImportFromIntention implements IntentionAction {
|
||||
|
||||
final IntentionState state = new IntentionState(editor, file);
|
||||
if (state.isAvailable()) {
|
||||
myText = state.getText();
|
||||
setText(state.getText());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
@Override
|
||||
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
final IntentionState state = new IntentionState(editor, file);
|
||||
state.invoke();
|
||||
}
|
||||
|
||||
public boolean startInWriteAction() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-16
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.jetbrains.python.codeInsight.intentions;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.injection.InjectedLanguageManager;
|
||||
import com.intellij.openapi.application.Application;
|
||||
@@ -55,7 +54,7 @@ import static com.jetbrains.python.psi.PyUtil.sure;
|
||||
* User: dcheryasov
|
||||
* Date: Oct 9, 2009 6:07:19 PM
|
||||
*/
|
||||
public class ImportToggleAliasIntention implements IntentionAction {
|
||||
public class ImportToggleAliasIntention extends PyBaseIntentionAction {
|
||||
private static class IntentionState {
|
||||
private PyImportElement myImportElement;
|
||||
private PyFromImportStatement myFromImportStatement;
|
||||
@@ -109,14 +108,6 @@ public class ImportToggleAliasIntention implements IntentionAction {
|
||||
}
|
||||
}
|
||||
|
||||
private String myLastText;
|
||||
|
||||
|
||||
@NotNull
|
||||
public String getText() {
|
||||
return myLastText;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INTN.Family.toggle.import.alias");
|
||||
@@ -128,11 +119,12 @@ public class ImportToggleAliasIntention implements IntentionAction {
|
||||
}
|
||||
|
||||
IntentionState state = IntentionState.fromContext(editor, file);
|
||||
myLastText = state.getText();
|
||||
setText(state.getText());
|
||||
return state.isAvailable();
|
||||
}
|
||||
|
||||
public void invoke(@NotNull final Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
@Override
|
||||
public void doInvoke(@NotNull final Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
// sanity check: isAvailable must have set it.
|
||||
final IntentionState state = IntentionState.fromContext(editor, file);
|
||||
//
|
||||
@@ -258,8 +250,4 @@ public class ImportToggleAliasIntention implements IntentionAction {
|
||||
PyUtil.showBalloon(project, PyBundle.message("QFIX.action.failed"), MessageType.WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean startInWriteAction() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-15
@@ -18,7 +18,6 @@ package com.jetbrains.python.codeInsight.intentions;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.codeInsight.CodeInsightUtilCore;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInsight.template.*;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
@@ -45,12 +44,10 @@ import static com.jetbrains.python.codeInsight.intentions.TypeIntention.resolves
|
||||
/**
|
||||
* @author traff
|
||||
*/
|
||||
public class PyAnnotateTypesIntention implements IntentionAction {
|
||||
private String myText = PyBundle.message("INTN.annotate.types");
|
||||
|
||||
@NotNull
|
||||
public String getText() {
|
||||
return myText;
|
||||
public class PyAnnotateTypesIntention extends PyBaseIntentionAction {
|
||||
|
||||
public PyAnnotateTypesIntention() {
|
||||
setText(PyBundle.message("INTN.annotate.types"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -78,7 +75,8 @@ public class PyAnnotateTypesIntention implements IntentionAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
@Override
|
||||
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
final PsiElement elementAt = PyUtil.findNonWhitespaceAtOffset(file, editor.getCaretModel().getOffset());
|
||||
final PyCallable callable = getCallable(elementAt);
|
||||
|
||||
@@ -229,13 +227,7 @@ public class PyAnnotateTypesIntention implements IntentionAction {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected void updateText() {
|
||||
myText = PyBundle.message("INTN.annotate.types");
|
||||
setText(PyBundle.message("INTN.annotate.types"));
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.jetbrains.python.codeInsight.intentions;
|
||||
|
||||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
@@ -36,7 +35,7 @@ import static com.jetbrains.python.psi.PyUtil.as;
|
||||
/**
|
||||
* @author Mikhail Golubev
|
||||
*/
|
||||
public abstract class PyBaseConvertCollectionLiteralIntention extends BaseIntentionAction {
|
||||
public abstract class PyBaseConvertCollectionLiteralIntention extends PyBaseIntentionAction {
|
||||
private final Class<? extends PySequenceExpression> myTargetCollectionClass;
|
||||
private final String myTargetCollectionName;
|
||||
private final String myRightBrace;
|
||||
@@ -87,7 +86,7 @@ public abstract class PyBaseConvertCollectionLiteralIntention extends BaseIntent
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
final PySequenceExpression literal = findCollectionLiteralUnderCaret(editor, file);
|
||||
assert literal != null;
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.jetbrains.python.codeInsight.intentions;
|
||||
|
||||
|
||||
import com.intellij.codeInsight.FileModificationService;
|
||||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class PyBaseIntentionAction extends BaseIntentionAction {
|
||||
|
||||
@Override
|
||||
public final void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;
|
||||
doInvoke(project, editor, file);
|
||||
}
|
||||
|
||||
public abstract void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException;
|
||||
}
|
||||
+2
-3
@@ -18,7 +18,6 @@ package com.jetbrains.python.codeInsight.intentions;
|
||||
import com.intellij.codeInsight.CodeInsightUtilCore;
|
||||
import com.intellij.codeInsight.controlflow.ControlFlow;
|
||||
import com.intellij.codeInsight.controlflow.Instruction;
|
||||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.template.*;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
@@ -42,7 +41,7 @@ import java.util.List;
|
||||
* User: catherine
|
||||
* Intention to convert lambda to function
|
||||
*/
|
||||
public class PyConvertLambdaToFunctionIntention extends BaseIntentionAction {
|
||||
public class PyConvertLambdaToFunctionIntention extends PyBaseIntentionAction {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
@@ -72,7 +71,7 @@ public class PyConvertLambdaToFunctionIntention extends BaseIntentionAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
PyLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PyLambdaExpression.class);
|
||||
if (lambdaExpression != null) {
|
||||
String name = "function";
|
||||
|
||||
+2
-3
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.jetbrains.python.codeInsight.intentions;
|
||||
|
||||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -34,7 +33,7 @@ import java.util.List;
|
||||
/**
|
||||
* User: ktisha
|
||||
*/
|
||||
public class PyConvertMethodToPropertyIntention extends BaseIntentionAction {
|
||||
public class PyConvertMethodToPropertyIntention extends PyBaseIntentionAction {
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INTN.convert.method.to.property");
|
||||
@@ -77,7 +76,7 @@ public class PyConvertMethodToPropertyIntention extends BaseIntentionAction {
|
||||
return available[0];
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
final PsiElement element = PyUtil.findNonWhitespaceAtOffset(file, editor.getCaretModel().getOffset());
|
||||
PyFunction problemFunction = PsiTreeUtil.getParentOfType(element, PyFunction.class);
|
||||
if (problemFunction == null) return;
|
||||
|
||||
+2
-3
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.jetbrains.python.codeInsight.intentions;
|
||||
|
||||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -34,7 +33,7 @@ import java.util.List;
|
||||
/**
|
||||
* User: ktisha
|
||||
*/
|
||||
public class PyConvertStaticMethodToFunctionIntention extends BaseIntentionAction {
|
||||
public class PyConvertStaticMethodToFunctionIntention extends PyBaseIntentionAction {
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INTN.convert.static.method.to.function");
|
||||
@@ -62,7 +61,7 @@ public class PyConvertStaticMethodToFunctionIntention extends BaseIntentionActio
|
||||
return false;
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
final PsiElement element = PyUtil.findNonWhitespaceAtOffset(file, editor.getCaretModel().getOffset());
|
||||
PyFunction problemFunction = PsiTreeUtil.getParentOfType(element, PyFunction.class);
|
||||
if (problemFunction == null) return;
|
||||
|
||||
+2
-5
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package com.jetbrains.python.codeInsight.intentions;
|
||||
|
||||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
@@ -24,7 +22,6 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
@@ -47,7 +44,7 @@ import java.util.List;
|
||||
* "but \"this\" includes far too much" "\n"
|
||||
* "whitespace at the start")
|
||||
*/
|
||||
public class PyConvertTripleQuotedStringIntention extends BaseIntentionAction {
|
||||
public class PyConvertTripleQuotedStringIntention extends PyBaseIntentionAction {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
@@ -81,7 +78,7 @@ public class PyConvertTripleQuotedStringIntention extends BaseIntentionAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) throws IncorrectOperationException {
|
||||
public void doInvoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) throws IncorrectOperationException {
|
||||
final PyStringLiteralExpression pyString = PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()),
|
||||
PyStringLiteralExpression.class);
|
||||
final PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.jetbrains.python.codeInsight.intentions;
|
||||
|
||||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -31,7 +30,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class PyDemorganIntention extends BaseIntentionAction {
|
||||
public class PyDemorganIntention extends PyBaseIntentionAction {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
@@ -62,7 +61,7 @@ public class PyDemorganIntention extends BaseIntentionAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
final PyBinaryExpression expression = PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()),
|
||||
PyBinaryExpression.class);
|
||||
assert expression != null;
|
||||
|
||||
+2
-3
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.jetbrains.python.codeInsight.intentions;
|
||||
|
||||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
@@ -36,7 +35,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
* dict(foo) -> no transformation
|
||||
* dict(**foo) -> no transformation
|
||||
*/
|
||||
public class PyDictConstructorToLiteralFormIntention extends BaseIntentionAction {
|
||||
public class PyDictConstructorToLiteralFormIntention extends PyBaseIntentionAction {
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INTN.convert.dict.constructor.to.dict.literal");
|
||||
@@ -69,7 +68,7 @@ public class PyDictConstructorToLiteralFormIntention extends BaseIntentionAction
|
||||
return false;
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
PyCallExpression expression =
|
||||
PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PyCallExpression.class);
|
||||
PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
|
||||
|
||||
+2
-3
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.jetbrains.python.codeInsight.intentions;
|
||||
|
||||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
@@ -36,7 +35,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
* {'a': 3, 'b': 5} -> dict(a=3, b=5)
|
||||
* {a: 3, b: 5} -> no transformation
|
||||
*/
|
||||
public class PyDictLiteralFormToConstructorIntention extends BaseIntentionAction {
|
||||
public class PyDictLiteralFormToConstructorIntention extends PyBaseIntentionAction {
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INTN.convert.dict.literal.to.dict.constructor");
|
||||
@@ -73,7 +72,7 @@ public class PyDictLiteralFormToConstructorIntention extends BaseIntentionAction
|
||||
return false;
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
PyDictLiteralExpression dictExpression =
|
||||
PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PyDictLiteralExpression.class);
|
||||
PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
|
||||
|
||||
+2
-3
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.jetbrains.python.codeInsight.intentions;
|
||||
|
||||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -39,7 +38,7 @@ import java.util.Map;
|
||||
* Date: 26.03.2010
|
||||
* Time: 22:01:27
|
||||
*/
|
||||
public class PyFlipComparisonIntention extends BaseIntentionAction {
|
||||
public class PyFlipComparisonIntention extends PyBaseIntentionAction {
|
||||
private static final Map<PyElementType, String> FLIPPED_OPERATORS = new HashMap<>(7);
|
||||
|
||||
static {
|
||||
@@ -82,7 +81,7 @@ public class PyFlipComparisonIntention extends BaseIntentionAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
|
||||
PyBinaryExpression binaryExpression = PsiTreeUtil.getParentOfType(element, PyBinaryExpression.class, false);
|
||||
while (binaryExpression != null) {
|
||||
|
||||
+2
-8
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package com.jetbrains.python.codeInsight.intentions;
|
||||
|
||||
import com.intellij.codeInsight.FileModificationService;
|
||||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -36,7 +34,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
* Intention to add documentation string for function
|
||||
* (with checked format)
|
||||
*/
|
||||
public class PyGenerateDocstringIntention extends BaseIntentionAction {
|
||||
public class PyGenerateDocstringIntention extends PyBaseIntentionAction {
|
||||
private String myText;
|
||||
|
||||
@NotNull
|
||||
@@ -81,11 +79,7 @@ public class PyGenerateDocstringIntention extends BaseIntentionAction {
|
||||
}
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
if (!FileModificationService.getInstance().preparePsiElementForWrite(file)) {
|
||||
return;
|
||||
}
|
||||
|
||||
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
PsiElement elementAt = PyUtil.findNonWhitespaceAtOffset(file, editor.getCaretModel().getOffset());
|
||||
PyFunction function = PsiTreeUtil.getParentOfType(elementAt, PyFunction.class);
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.jetbrains.python.codeInsight.intentions;
|
||||
|
||||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiComment;
|
||||
@@ -42,7 +41,7 @@ import java.util.List;
|
||||
* if a and b:
|
||||
* #stuff here
|
||||
*/
|
||||
public class PyJoinIfIntention extends BaseIntentionAction {
|
||||
public class PyJoinIfIntention extends PyBaseIntentionAction {
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INTN.join.if");
|
||||
@@ -79,7 +78,7 @@ public class PyJoinIfIntention extends BaseIntentionAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
PyIfStatement expression =
|
||||
PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PyIfStatement.class);
|
||||
PyIfStatement ifStatement = getIfStatement(expression);
|
||||
|
||||
+2
-3
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.jetbrains.python.codeInsight.intentions;
|
||||
|
||||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -36,7 +35,7 @@ import java.util.Map;
|
||||
* Date: 12.03.2010
|
||||
* Time: 17:58:56
|
||||
*/
|
||||
public class PyNegateComparisonIntention extends BaseIntentionAction {
|
||||
public class PyNegateComparisonIntention extends PyBaseIntentionAction {
|
||||
private static final Map<PyElementType, String> comparisonStrings = new HashMap<>(7);
|
||||
private static final Map<PyElementType, PyElementType> invertedComparasions = new HashMap<>(7);
|
||||
|
||||
@@ -82,7 +81,7 @@ public class PyNegateComparisonIntention extends BaseIntentionAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
|
||||
PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
|
||||
PyBinaryExpression binaryExpression = PsiTreeUtil.getParentOfType(element, PyBinaryExpression.class, false);
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.jetbrains.python.codeInsight.intentions;
|
||||
|
||||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
@@ -33,7 +32,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
* User: catherine
|
||||
* Intention to convert between single-quoted and double-quoted strings
|
||||
*/
|
||||
public class PyQuotedStringIntention extends BaseIntentionAction {
|
||||
public class PyQuotedStringIntention extends PyBaseIntentionAction {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
@@ -73,7 +72,7 @@ public class PyQuotedStringIntention extends BaseIntentionAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
PyStringLiteralExpression string = PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PyStringLiteralExpression.class);
|
||||
PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
|
||||
if (string != null) {
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.jetbrains.python.codeInsight.intentions;
|
||||
|
||||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -35,7 +34,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
* Date: 10.03.2010
|
||||
* Time: 18:52:52
|
||||
*/
|
||||
public class PySplitIfIntention extends BaseIntentionAction {
|
||||
public class PySplitIfIntention extends PyBaseIntentionAction {
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INTN.split.if");
|
||||
@@ -82,7 +81,7 @@ public class PySplitIfIntention extends BaseIntentionAction {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
PsiElement elementAtOffset = file.findElementAt(editor.getCaretModel().getOffset());
|
||||
// PY-745
|
||||
final IElementType elementType = elementAtOffset.getNode().getElementType();
|
||||
|
||||
+2
-3
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.jetbrains.python.codeInsight.intentions;
|
||||
|
||||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
@@ -42,7 +41,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author Alexey.Ivanov
|
||||
*/
|
||||
public class PyStringConcatenationToFormatIntention extends BaseIntentionAction {
|
||||
public class PyStringConcatenationToFormatIntention extends PyBaseIntentionAction {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
@@ -123,7 +122,7 @@ public class PyStringConcatenationToFormatIntention extends BaseIntentionAction
|
||||
return res;
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
PsiElement element = PsiTreeUtil.getTopmostParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PyBinaryExpression.class);
|
||||
|
||||
if (element == null) return;
|
||||
|
||||
+2
-3
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.jetbrains.python.codeInsight.intentions;
|
||||
|
||||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
@@ -39,7 +38,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
* else:
|
||||
* x = b
|
||||
*/
|
||||
public class PyTransformConditionalExpressionIntention extends BaseIntentionAction {
|
||||
public class PyTransformConditionalExpressionIntention extends PyBaseIntentionAction {
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INTN.transform.into.if.else.statement");
|
||||
@@ -63,7 +62,7 @@ public class PyTransformConditionalExpressionIntention extends BaseIntentionActi
|
||||
return false;
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
final PyAssignmentStatement assignmentStatement =
|
||||
PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PyAssignmentStatement.class);
|
||||
assert assignmentStatement != null;
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.jetbrains.python.codeInsight.intentions;
|
||||
|
||||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -30,7 +29,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
/**
|
||||
* @author vlan
|
||||
*/
|
||||
public class PyYieldFromIntention extends BaseIntentionAction {
|
||||
public class PyYieldFromIntention extends PyBaseIntentionAction {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
@@ -62,7 +61,7 @@ public class PyYieldFromIntention extends BaseIntentionAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
final PyForStatement forLoop = findForStatementAtCaret(editor, file);
|
||||
if (forLoop != null) {
|
||||
final PyExpression source = forLoop.getForPart().getSource();
|
||||
|
||||
+3
-7
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.jetbrains.python.codeInsight.intentions;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -32,7 +31,7 @@ import java.util.List;
|
||||
/**
|
||||
* User: catherine
|
||||
*/
|
||||
public class ReplaceListComprehensionWithForIntention implements IntentionAction {
|
||||
public class ReplaceListComprehensionWithForIntention extends PyBaseIntentionAction {
|
||||
@NotNull
|
||||
public String getText() {
|
||||
return PyBundle.message("INTN.replace.list.comprehensions.with.for");
|
||||
@@ -61,7 +60,8 @@ public class ReplaceListComprehensionWithForIntention implements IntentionAction
|
||||
return false;
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
@Override
|
||||
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
PyListCompExpression expression = PsiTreeUtil.getTopmostParentOfType(
|
||||
file.findElementAt(editor.getCaretModel().getOffset()), PyListCompExpression.class);
|
||||
if (expression == null) {
|
||||
@@ -120,8 +120,4 @@ public class ReplaceListComprehensionWithForIntention implements IntentionAction
|
||||
return elementGenerator.createFromText(LanguageLevel.forElement(expression), PyForStatement.class,
|
||||
stringBuilder.toString());
|
||||
}
|
||||
|
||||
public boolean startInWriteAction() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -53,7 +53,8 @@ public class SpecifyTypeInDocstringIntention extends TypeIntention {
|
||||
return PyBundle.message("INTN.specify.type");
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
@Override
|
||||
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
final PsiElement elementAt = PyUtil.findNonWhitespaceAtOffset(file, editor.getCaretModel().getOffset());
|
||||
final PyExpression problemElement = getProblemElement(elementAt);
|
||||
final PsiReference reference = problemElement == null ? null : problemElement.getReference();
|
||||
|
||||
+2
-1
@@ -64,7 +64,8 @@ public class SpecifyTypeInPy3AnnotationsIntention extends TypeIntention {
|
||||
return super.isAvailable(project, editor, file);
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
@Override
|
||||
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
final PsiElement elementAt = PyUtil.findNonWhitespaceAtOffset(file, editor.getCaretModel().getOffset());
|
||||
final PyExpression problemElement = getProblemElement(elementAt);
|
||||
final PsiReference reference = problemElement == null ? null : problemElement.getReference();
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package com.jetbrains.python.codeInsight.intentions;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightUtilCore;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInsight.template.*;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
@@ -39,10 +38,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
*
|
||||
* Helps to specify type by assertion
|
||||
*/
|
||||
public class TypeAssertionIntention implements IntentionAction {
|
||||
|
||||
public TypeAssertionIntention() {
|
||||
}
|
||||
public class TypeAssertionIntention extends PyBaseIntentionAction {
|
||||
|
||||
@NotNull
|
||||
public String getText() {
|
||||
@@ -79,7 +75,8 @@ public class TypeAssertionIntention implements IntentionAction {
|
||||
return type == null;
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
@Override
|
||||
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
PsiElement elementAt = PyUtil.findNonWhitespaceAtOffset(file, editor.getCaretModel().getOffset());
|
||||
PyExpression problemElement = PsiTreeUtil.getParentOfType(elementAt, PyReferenceExpression.class);
|
||||
if (problemElement != null) {
|
||||
@@ -142,8 +139,4 @@ public class TypeAssertionIntention implements IntentionAction {
|
||||
TemplateManager.getInstance(project).startTemplate(editor, template);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean startInWriteAction() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,6 @@
|
||||
package com.jetbrains.python.codeInsight.intentions;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -39,7 +38,7 @@ import static com.jetbrains.python.psi.PyUtil.as;
|
||||
*
|
||||
* Common part for type specifying intentions
|
||||
*/
|
||||
public abstract class TypeIntention implements IntentionAction {
|
||||
public abstract class TypeIntention extends PyBaseIntentionAction {
|
||||
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
if (!(file instanceof PyFile) || file instanceof PyDocstringFile) return false;
|
||||
@@ -196,8 +195,4 @@ public abstract class TypeIntention implements IntentionAction {
|
||||
protected static PyResolveContext getResolveContext(@NotNull PsiElement origin) {
|
||||
return PyResolveContext.defaultContext().withTypeEvalContext(TypeEvalContext.codeAnalysis(origin.getProject(), origin.getContainingFile()));
|
||||
}
|
||||
|
||||
public boolean startInWriteAction() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user