Search in sources :

Example 16 with PsiExpression

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

the class NegateComparisonIntention method processIntention.

public void processIntention(PsiElement element) throws IncorrectOperationException {
    final PsiBinaryExpression expression = (PsiBinaryExpression) element;
    final PsiExpression lhs = expression.getLOperand();
    final PsiExpression rhs = expression.getROperand();
    final String negatedOperator = ComparisonUtils.getNegatedComparison(expression.getOperationTokenType());
    final String lhsText = lhs.getText();
    assert rhs != null;
    final String rhsText = rhs.getText();
    replaceExpressionWithNegatedExpressionString(lhsText + negatedOperator + rhsText, expression);
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) PsiBinaryExpression(com.intellij.psi.PsiBinaryExpression)

Example 17 with PsiExpression

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

the class ComparisonPredicate method satisfiedBy.

public boolean satisfiedBy(PsiElement element) {
    if (!(element instanceof PsiBinaryExpression)) {
        return false;
    }
    final PsiBinaryExpression expression = (PsiBinaryExpression) element;
    final PsiExpression rhs = expression.getROperand();
    if (rhs == null) {
        return false;
    }
    if (!ComparisonUtils.isComparison((PsiExpression) element)) {
        return false;
    }
    return !ErrorUtil.containsError(element);
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) PsiBinaryExpression(com.intellij.psi.PsiBinaryExpression)

Example 18 with PsiExpression

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

the class FlipComparisonIntention method processIntention.

public void processIntention(@NotNull PsiElement element) throws IncorrectOperationException {
    final PsiBinaryExpression expression = (PsiBinaryExpression) element;
    final PsiExpression lhs = expression.getLOperand();
    final PsiExpression rhs = expression.getROperand();
    final IElementType tokenType = expression.getOperationTokenType();
    assert rhs != null;
    final String expString = rhs.getText() + ComparisonUtils.getFlippedComparison(tokenType) + lhs.getText();
    PsiReplacementUtil.replaceExpression(expression, expString);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiExpression(com.intellij.psi.PsiExpression) PsiBinaryExpression(com.intellij.psi.PsiBinaryExpression)

Example 19 with PsiExpression

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

the class AbstractJavaInplaceIntroduceTest method invokeRefactoring.

protected AbstractInplaceIntroducer invokeRefactoring(MyIntroduceHandler introduceHandler) {
    final PsiExpression expression = getExpressionFromEditor();
    if (expression != null) {
        introduceHandler.invokeImpl(LightPlatformTestCase.getProject(), expression, getEditor());
    } else {
        final PsiLocalVariable localVariable = getLocalVariableFromEditor();
        introduceHandler.invokeImpl(LightPlatformTestCase.getProject(), localVariable, getEditor());
    }
    return introduceHandler.getInplaceIntroducer();
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) PsiLocalVariable(com.intellij.psi.PsiLocalVariable)

Example 20 with PsiExpression

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

the class IntroduceFieldWitSetUpInitializationTest method doTest.

private void doTest() throws Exception {
    configureByFile("/refactoring/introduceField/before" + getTestName(false) + ".java");
    final PsiLocalVariable local = PsiTreeUtil.getParentOfType(getFile().findElementAt(getEditor().getCaretModel().getOffset()), PsiLocalVariable.class);
    new LocalToFieldHandler(getProject(), false) {

        @Override
        protected BaseExpressionToFieldHandler.Settings showRefactoringDialog(final PsiClass aClass, final PsiLocalVariable local, final PsiExpression[] occurences, final boolean isStatic) {
            return new BaseExpressionToFieldHandler.Settings("i", null, occurences, true, false, false, BaseExpressionToFieldHandler.InitializationPlace.IN_SETUP_METHOD, PsiModifier.PRIVATE, local, local.getType(), true, (BaseExpressionToFieldHandler.TargetDestination) null, false, false);
        }
    }.convertLocalToField(local, myEditor);
    checkResultByFile("/refactoring/introduceField/after" + getTestName(false) + ".java");
}
Also used : LocalToFieldHandler(com.intellij.refactoring.introduceField.LocalToFieldHandler) PsiExpression(com.intellij.psi.PsiExpression) PsiClass(com.intellij.psi.PsiClass) PsiLocalVariable(com.intellij.psi.PsiLocalVariable) BaseExpressionToFieldHandler(com.intellij.refactoring.introduceField.BaseExpressionToFieldHandler)

Aggregations

PsiExpression (com.intellij.psi.PsiExpression)72 PsiElement (com.intellij.psi.PsiElement)28 PsiReferenceExpression (com.intellij.psi.PsiReferenceExpression)13 PsiMethodCallExpression (com.intellij.psi.PsiMethodCallExpression)11 Nullable (org.jetbrains.annotations.Nullable)9 PsiReference (com.intellij.psi.PsiReference)8 PsiType (com.intellij.psi.PsiType)8 NonNls (org.jetbrains.annotations.NonNls)8 PsiClass (com.intellij.psi.PsiClass)7 PsiAssignmentExpression (com.intellij.psi.PsiAssignmentExpression)6 PsiExpressionStatement (com.intellij.psi.PsiExpressionStatement)6 PsiLocalVariable (com.intellij.psi.PsiLocalVariable)6 PsiMethod (com.intellij.psi.PsiMethod)6 PsiNewExpression (com.intellij.psi.PsiNewExpression)6 PsiPolyadicExpression (com.intellij.psi.PsiPolyadicExpression)6 PsiStatement (com.intellij.psi.PsiStatement)6 Project (com.intellij.openapi.project.Project)5 PsiBinaryExpression (com.intellij.psi.PsiBinaryExpression)5 PsiDeclarationStatement (com.intellij.psi.PsiDeclarationStatement)5 PsiElementFactory (com.intellij.psi.PsiElementFactory)5