Search in sources :

Example 1 with GrBinaryExpression

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression in project intellij-community by JetBrains.

the class ConjunctionPredicate method satisfiedBy.

@Override
public boolean satisfiedBy(PsiElement element) {
    if (!(element instanceof GrBinaryExpression)) {
        return false;
    }
    final GrBinaryExpression expression = (GrBinaryExpression) element;
    final IElementType tokenType = expression.getOperationTokenType();
    if (tokenType == null)
        return false;
    if (!tokenType.equals(GroovyTokenTypes.mLAND) && !tokenType.equals(GroovyTokenTypes.mLOR)) {
        return false;
    }
    return !ErrorUtil.containsError(element);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) GrBinaryExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression)

Example 2 with GrBinaryExpression

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression in project intellij-community by JetBrains.

the class DemorgansLawIntention method isConjunctionExpression.

private static boolean isConjunctionExpression(PsiElement exp, IElementType conjunctionType) {
    if (!(exp instanceof GrBinaryExpression))
        return false;
    final GrBinaryExpression binExp = (GrBinaryExpression) exp;
    final IElementType tokenType = binExp.getOperationTokenType();
    return conjunctionType.equals(tokenType);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) GrBinaryExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression)

Example 3 with GrBinaryExpression

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression in project intellij-community by JetBrains.

the class DemorgansLawIntention method processIntention.

@Override
public void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
    GrBinaryExpression exp = (GrBinaryExpression) element;
    final IElementType tokenType = exp.getOperationTokenType();
    PsiElement parent = exp.getParent();
    while (isConjunctionExpression(parent, tokenType)) {
        exp = (GrBinaryExpression) parent;
        assert exp != null;
        parent = exp.getParent();
    }
    final String newExpression = convertConjunctionExpression(exp, tokenType);
    replaceExpressionWithNegatedExpressionString(newExpression, exp);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) GrBinaryExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression) PsiElement(com.intellij.psi.PsiElement)

Example 4 with GrBinaryExpression

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression in project intellij-community by JetBrains.

the class DemorgansLawIntention method getTextForElement.

@Override
protected String getTextForElement(PsiElement element) {
    final GrBinaryExpression binaryExpression = (GrBinaryExpression) element;
    final IElementType tokenType = binaryExpression.getOperationTokenType();
    if (GroovyTokenTypes.mLAND.equals(tokenType)) {
        return GroovyIntentionsBundle.message("demorgans.intention.name1");
    } else {
        return GroovyIntentionsBundle.message("demorgans.intention.name2");
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) GrBinaryExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression)

Example 5 with GrBinaryExpression

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression in project intellij-community by JetBrains.

the class FlipConjunctionIntention method getTextForElement.

@Override
protected String getTextForElement(PsiElement element) {
    final GrBinaryExpression binaryExpression = (GrBinaryExpression) element;
    final IElementType tokenType = binaryExpression.getOperationTokenType();
    final String conjunction = getConjunction(tokenType);
    return GroovyIntentionsBundle.message("flip.smth.intention.name", conjunction);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) GrBinaryExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression)

Aggregations

GrBinaryExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression)26 IElementType (com.intellij.psi.tree.IElementType)15 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)14 NotNull (org.jetbrains.annotations.NotNull)3 PsiElement (com.intellij.psi.PsiElement)2 GrListOrMap (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap)2 GrStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)2 GrAssignmentExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression)2 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)2 ASTNode (com.intellij.lang.ASTNode)1 PsiType (com.intellij.psi.PsiType)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 Nullable (org.jetbrains.annotations.Nullable)1 GrDocComment (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment)1 GrDocTag (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocTag)1 GroovyFileBase (org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase)1 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)1 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)1 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)1 GrAnnotationArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationArgumentList)1