Skip to content

Commit 108bd6a

Browse files
committed
Removing PyFlipComparisonIntention.getFamilyName. Refactoring.
1 parent a31467b commit 108bd6a

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

python-impl/src/main/java/com/jetbrains/python/impl/codeInsight/intentions/PyFlipComparisonIntention.java

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,22 @@
3030
import consulo.python.impl.localize.PyLocalize;
3131
import jakarta.annotation.Nonnull;
3232

33-
import java.util.HashMap;
3433
import java.util.Map;
3534

3635
/**
3736
* @author Alexey.Ivanov
3837
* @since 2010-03-26
3938
*/
4039
public class PyFlipComparisonIntention extends BaseIntentionAction {
41-
private static final Map<PyElementType, String> FLIPPED_OPERATORS = new HashMap<PyElementType, String>(7);
42-
43-
static {
44-
FLIPPED_OPERATORS.put(PyTokenTypes.EQEQ, "==");
45-
FLIPPED_OPERATORS.put(PyTokenTypes.NE, "!=");
46-
FLIPPED_OPERATORS.put(PyTokenTypes.NE_OLD, "<>");
47-
FLIPPED_OPERATORS.put(PyTokenTypes.GE, "<=");
48-
FLIPPED_OPERATORS.put(PyTokenTypes.LE, ">=");
49-
FLIPPED_OPERATORS.put(PyTokenTypes.GT, "<");
50-
FLIPPED_OPERATORS.put(PyTokenTypes.LT, ">");
51-
}
52-
53-
@Nonnull
54-
public String getFamilyName() {
55-
return PyLocalize.intnFlipComparison().get();
56-
}
40+
private static final Map<PyElementType, String> OUR_FLIPPED_OPERATORS = Map.of(
41+
PyTokenTypes.EQEQ, "==",
42+
PyTokenTypes.NE, "!=",
43+
PyTokenTypes.NE_OLD, "<>",
44+
PyTokenTypes.GE, "<=",
45+
PyTokenTypes.LE, ">=",
46+
PyTokenTypes.GT, "<",
47+
PyTokenTypes.LT, ">"
48+
);
5749

5850
public boolean isAvailable(@Nonnull Project project, Editor editor, PsiFile file) {
5951
if (!(file instanceof PyFile)) {
@@ -64,9 +56,9 @@ public boolean isAvailable(@Nonnull Project project, Editor editor, PsiFile file
6456
PyBinaryExpression binaryExpression = PsiTreeUtil.getParentOfType(element, PyBinaryExpression.class, false);
6557
while (binaryExpression != null) {
6658
PyElementType operator = binaryExpression.getOperator();
67-
if (FLIPPED_OPERATORS.containsKey(operator)) {
59+
if (OUR_FLIPPED_OPERATORS.containsKey(operator)) {
6860
String operatorText = binaryExpression.getPsiOperator().getText();
69-
String flippedOperatorText = FLIPPED_OPERATORS.get(operator);
61+
String flippedOperatorText = OUR_FLIPPED_OPERATORS.get(operator);
7062
if (flippedOperatorText.equals(operatorText)) {
7163
setText(PyLocalize.intnFlip$0(operatorText));
7264
}
@@ -84,10 +76,10 @@ public void invoke(@Nonnull Project project, Editor editor, PsiFile file) throws
8476
PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
8577
PyBinaryExpression binaryExpression = PsiTreeUtil.getParentOfType(element, PyBinaryExpression.class, false);
8678
while (binaryExpression != null) {
87-
if (FLIPPED_OPERATORS.containsKey(binaryExpression.getOperator())) {
79+
if (OUR_FLIPPED_OPERATORS.containsKey(binaryExpression.getOperator())) {
8880
PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
8981
binaryExpression.replace(elementGenerator.createBinaryExpression(
90-
FLIPPED_OPERATORS.get(binaryExpression.getOperator()),
82+
OUR_FLIPPED_OPERATORS.get(binaryExpression.getOperator()),
9183
binaryExpression.getRightExpression(),
9284
binaryExpression.getLeftExpression()
9385
));

0 commit comments

Comments
 (0)