use of com.jetbrains.python.psi.PyBinaryExpression in project intellij-community by JetBrains.
the class ChainedComparisonsQuickFix method applyFix.
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PyBinaryExpression expression = as(descriptor.getPsiElement(), PyBinaryExpression.class);
if (expression != null && expression.isWritable()) {
final PyBinaryExpression rightExpression = as(expression.getRightExpression(), PyBinaryExpression.class);
final PyBinaryExpression leftExpression = as(expression.getLeftExpression(), PyBinaryExpression.class);
if (rightExpression != null && leftExpression != null && isLogicalAndExpression(expression)) {
applyFix(goDownIfNeeded(leftExpression), rightExpression, project);
}
}
}
use of com.jetbrains.python.psi.PyBinaryExpression 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;
}
use of com.jetbrains.python.psi.PyBinaryExpression in project intellij-community by JetBrains.
the class PyFlipComparisonIntention method doInvoke.
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) {
if (FLIPPED_OPERATORS.containsKey(binaryExpression.getOperator())) {
PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
binaryExpression.replace(elementGenerator.createBinaryExpression(FLIPPED_OPERATORS.get(binaryExpression.getOperator()), binaryExpression.getRightExpression(), binaryExpression.getLeftExpression()));
return;
}
binaryExpression = PsiTreeUtil.getParentOfType(binaryExpression, PyBinaryExpression.class);
}
}
Aggregations