use of com.jetbrains.python.psi.PyElementType in project intellij-community by JetBrains.
the class ComparisonWithNoneQuickFix method applyFix.
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
PsiElement problemElement = descriptor.getPsiElement();
if (problemElement instanceof PyBinaryExpression) {
PyBinaryExpression binaryExpression = (PyBinaryExpression) problemElement;
PyElementType operator = binaryExpression.getOperator();
PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
String temp;
temp = (operator == PyTokenTypes.EQEQ) ? "is" : "is not";
PyExpression expression = elementGenerator.createBinaryExpression(temp, binaryExpression.getLeftExpression(), binaryExpression.getRightExpression());
binaryExpression.replace(expression);
}
}
use of com.jetbrains.python.psi.PyElementType in project intellij-community by JetBrains.
the class PyFlipComparisonIntention method isAvailable.
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
if (!(file instanceof PyFile)) {
return false;
}
PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
PyBinaryExpression binaryExpression = PsiTreeUtil.getParentOfType(element, PyBinaryExpression.class, false);
while (binaryExpression != null) {
PyElementType operator = binaryExpression.getOperator();
if (FLIPPED_OPERATORS.containsKey(operator)) {
String operatorText = binaryExpression.getPsiOperator().getText();
String flippedOperatorText = FLIPPED_OPERATORS.get(operator);
if (flippedOperatorText.equals(operatorText)) {
setText(PyBundle.message("INTN.flip.$0", operatorText));
} else {
setText(PyBundle.message("INTN.flip.$0.to.$1", operatorText, flippedOperatorText));
}
return true;
}
binaryExpression = PsiTreeUtil.getParentOfType(binaryExpression, PyBinaryExpression.class);
}
return false;
}
Aggregations