Search in sources :

Example 16 with PsiJavaToken

use of com.intellij.psi.PsiJavaToken in project intellij-community by JetBrains.

the class FlipExpressionIntention method getTextForElement.

@Override
public String getTextForElement(PsiElement element) {
    final PsiPolyadicExpression expression = (PsiPolyadicExpression) element.getParent();
    final PsiExpression[] operands = expression.getOperands();
    final PsiJavaToken sign = expression.getTokenBeforeOperand(operands[1]);
    final String operatorText = sign == null ? "" : sign.getText();
    final IElementType tokenType = expression.getOperationTokenType();
    final boolean commutative = ParenthesesUtils.isCommutativeOperator(tokenType);
    if (commutative && !ExpressionUtils.isConcatenation(expression)) {
        return IntentionPowerPackBundle.message("flip.smth.intention.name", operatorText);
    } else {
        return IntentionPowerPackBundle.message("flip.smth.intention.name1", operatorText);
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiJavaToken(com.intellij.psi.PsiJavaToken) PsiExpression(com.intellij.psi.PsiExpression) PsiPolyadicExpression(com.intellij.psi.PsiPolyadicExpression)

Example 17 with PsiJavaToken

use of com.intellij.psi.PsiJavaToken in project intellij-community by JetBrains.

the class ReplaceOperatorAssignmentWithAssignmentIntention method getTextForElement.

@Override
protected String getTextForElement(PsiElement element) {
    final PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression) element;
    final PsiJavaToken sign = assignmentExpression.getOperationSign();
    final String operator = sign.getText();
    return IntentionPowerPackBundle.message("replace.operator.assignment.with.assignment.intention.name", operator);
}
Also used : PsiJavaToken(com.intellij.psi.PsiJavaToken) PsiAssignmentExpression(com.intellij.psi.PsiAssignmentExpression)

Example 18 with PsiJavaToken

use of com.intellij.psi.PsiJavaToken in project intellij-community by JetBrains.

the class SimplifyIfElseIntention method getElementPredicate.

@NotNull
public PsiElementPredicate getElementPredicate() {
    return new PsiElementPredicate() {

        public boolean satisfiedBy(PsiElement element) {
            if (!(element instanceof PsiJavaToken)) {
                return false;
            }
            final PsiJavaToken token = (PsiJavaToken) element;
            final PsiElement parent = token.getParent();
            if (!(parent instanceof PsiIfStatement)) {
                return false;
            }
            return TrivialIfInspection.isTrivial((PsiIfStatement) parent);
        }
    };
}
Also used : PsiJavaToken(com.intellij.psi.PsiJavaToken) PsiIfStatement(com.intellij.psi.PsiIfStatement) PsiElementPredicate(com.siyeh.ipp.base.PsiElementPredicate) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with PsiJavaToken

use of com.intellij.psi.PsiJavaToken in project intellij-community by JetBrains.

the class IfToSwitchPredicate method satisfiedBy.

@Override
public boolean satisfiedBy(PsiElement element) {
    if (!(element instanceof PsiJavaToken)) {
        return false;
    }
    final PsiJavaToken token = (PsiJavaToken) element;
    if (token.getTokenType() != JavaTokenType.IF_KEYWORD) {
        return false;
    }
    final PsiElement parent = element.getParent();
    if (!(parent instanceof PsiIfStatement)) {
        return false;
    }
    final PsiIfStatement statement = (PsiIfStatement) parent;
    if (ErrorUtil.containsError(statement)) {
        return false;
    }
    return SwitchUtils.getSwitchExpression(statement, 0, false, true) != null;
}
Also used : PsiJavaToken(com.intellij.psi.PsiJavaToken) PsiIfStatement(com.intellij.psi.PsiIfStatement) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiJavaToken (com.intellij.psi.PsiJavaToken)19 PsiElement (com.intellij.psi.PsiElement)12 PsiPolyadicExpression (com.intellij.psi.PsiPolyadicExpression)5 PsiExpression (com.intellij.psi.PsiExpression)4 PsiIfStatement (com.intellij.psi.PsiIfStatement)4 IElementType (com.intellij.psi.tree.IElementType)4 Document (com.intellij.openapi.editor.Document)2 TextRange (com.intellij.openapi.util.TextRange)2 PsiBinaryExpression (com.intellij.psi.PsiBinaryExpression)2 PsiForStatement (com.intellij.psi.PsiForStatement)2 PsiStatement (com.intellij.psi.PsiStatement)2 PsiWhileStatement (com.intellij.psi.PsiWhileStatement)2 PsiAssignmentExpression (com.intellij.psi.PsiAssignmentExpression)1 PsiBlockStatement (com.intellij.psi.PsiBlockStatement)1 PsiCodeBlock (com.intellij.psi.PsiCodeBlock)1 PsiDoWhileStatement (com.intellij.psi.PsiDoWhileStatement)1 PsiForeachStatement (com.intellij.psi.PsiForeachStatement)1 PsiSwitchStatement (com.intellij.psi.PsiSwitchStatement)1 PsiTypeCastExpression (com.intellij.psi.PsiTypeCastExpression)1 PsiElementPredicate (com.siyeh.ipp.base.PsiElementPredicate)1