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);
}
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);
}
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);
}
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();
}
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");
}
Aggregations