use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression in project intellij-community by JetBrains.
the class FlipComparisonIntention method processIntention.
@Override
public void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
final GrBinaryExpression exp = (GrBinaryExpression) element;
final IElementType tokenType = exp.getOperationTokenType();
final GrExpression lhs = exp.getLeftOperand();
final String lhsText = lhs.getText();
final GrExpression rhs = exp.getRightOperand();
final String rhsText = rhs.getText();
final String flippedComparison = ComparisonUtils.getFlippedComparison(tokenType);
final String newExpression = rhsText + flippedComparison + lhsText;
PsiImplUtil.replaceExpression(newExpression, exp);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression in project intellij-community by JetBrains.
the class FlipComparisonIntention method getTextForElement.
@Override
protected String getTextForElement(PsiElement element) {
final GrBinaryExpression binaryExpression = (GrBinaryExpression) element;
final IElementType tokenType = binaryExpression.getOperationTokenType();
final String comparison = ComparisonUtils.getStringForComparison(tokenType);
final String flippedComparison = ComparisonUtils.getFlippedComparison(tokenType);
if (comparison.equals(flippedComparison)) {
return GroovyIntentionsBundle.message("flip.smth.intention.name", comparison);
}
return GroovyIntentionsBundle.message("flip.comparison.intention.name", comparison, flippedComparison);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression in project intellij-community by JetBrains.
the class FlipConjunctionIntention method processIntention.
@Override
public void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
final GrBinaryExpression exp = (GrBinaryExpression) element;
final IElementType tokenType = exp.getOperationTokenType();
final GrExpression lhs = exp.getLeftOperand();
final String lhsText = lhs.getText();
final GrExpression rhs = exp.getRightOperand();
final String rhsText = rhs.getText();
final String conjunction = getConjunction(tokenType);
final String newExpression = rhsText + conjunction + lhsText;
PsiImplUtil.replaceExpression(newExpression, exp);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression in project intellij-community by JetBrains.
the class NegateComparisonIntention method processIntention.
@Override
public void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
final GrBinaryExpression exp = (GrBinaryExpression) element;
final IElementType tokenType = exp.getOperationTokenType();
final GrExpression lhs = exp.getLeftOperand();
final String lhsText = lhs.getText();
final GrExpression rhs = exp.getRightOperand();
final String rhsText = rhs.getText();
final String negatedComparison = ComparisonUtils.getNegatedComparison(tokenType);
final String newExpression = lhsText + negatedComparison + rhsText;
replaceExpressionWithNegatedExpressionString(newExpression, exp);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression in project intellij-community by JetBrains.
the class InstanceOfInstruction method getInstanceof.
@Nullable
private Pair<GrExpression, PsiType> getInstanceof() {
final PsiElement element = getElement();
if (element instanceof GrInstanceOfExpression) {
GrExpression operand = ((GrInstanceOfExpression) element).getOperand();
final GrTypeElement typeElement = ((GrInstanceOfExpression) element).getTypeElement();
if (operand instanceof GrReferenceExpression && ((GrReferenceExpression) operand).getQualifier() == null && typeElement != null) {
return Pair.create(((GrInstanceOfExpression) element).getOperand(), typeElement.getType());
}
} else if (element instanceof GrBinaryExpression && ControlFlowBuilderUtil.isInstanceOfBinary((GrBinaryExpression) element)) {
GrExpression left = ((GrBinaryExpression) element).getLeftOperand();
GrExpression right = ((GrBinaryExpression) element).getRightOperand();
if (right == null)
return null;
GroovyResolveResult result = ((GrReferenceExpression) right).advancedResolve();
final PsiElement resolved = result.getElement();
if (resolved instanceof PsiClass) {
PsiClassType type = JavaPsiFacade.getElementFactory(element.getProject()).createType((PsiClass) resolved, result.getSubstitutor());
return new Pair<>(left, type);
}
}
return null;
}
Aggregations