use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class MakeClosureCallExplicitIntention method processIntention.
@Override
public void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
final GrMethodCallExpression expression = (GrMethodCallExpression) element;
final GrExpression invokedExpression = expression.getInvokedExpression();
final GrArgumentList argList = expression.getArgumentList();
final GrClosableBlock[] closureArgs = expression.getClosureArguments();
final StringBuilder newExpression = new StringBuilder();
newExpression.append(invokedExpression.getText());
newExpression.append(".call");
newExpression.append(argList.getText());
for (GrClosableBlock closureArg : closureArgs) {
newExpression.append(closureArg.getText());
}
PsiImplUtil.replaceExpression(newExpression.toString(), expression);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class ExpandBooleanPredicate method isBooleanAssignment.
public static boolean isBooleanAssignment(GrStatement expression) {
if (!(expression instanceof GrAssignmentExpression)) {
return false;
}
final GrAssignmentExpression assignment = (GrAssignmentExpression) expression;
final GrExpression rhs = assignment.getRValue();
if (rhs == null) {
return false;
}
if (rhs instanceof GrLiteral) {
return false;
}
final PsiType assignmentType = rhs.getType();
if (assignmentType == null) {
return false;
}
return assignmentType.equals(PsiType.BOOLEAN) || assignmentType.equalsToText("java.lang.Boolean");
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class InvertIfIntention method stripParenthesis.
@NotNull
private static GrExpression stripParenthesis(GrExpression operand) {
while (operand instanceof GrParenthesizedExpression) {
GrExpression innerExpression = ((GrParenthesizedExpression) operand).getOperand();
if (innerExpression == null) {
break;
}
operand = innerExpression;
}
return operand;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class GrVariableJoinLinesHandler method tryJoinStatements.
@Override
public int tryJoinStatements(@NotNull GrStatement first, @NotNull GrStatement second) {
if (first instanceof GrVariableDeclaration && !((GrVariableDeclaration) first).isTuple() && second instanceof GrAssignmentExpression) {
final GrExpression lvalue = ((GrAssignmentExpression) second).getLValue();
final GrExpression rValue = ((GrAssignmentExpression) second).getRValue();
if (lvalue instanceof GrReferenceExpression && rValue != null) {
final PsiElement resolved = ((GrReferenceExpression) lvalue).resolve();
if (ArrayUtil.contains(resolved, ((GrVariableDeclaration) first).getVariables())) {
assert resolved instanceof GrVariable;
if (((GrVariable) resolved).getInitializerGroovy() == null) {
((GrVariable) resolved).setInitializerGroovy(rValue);
second.delete();
GrExpression newInitializer = ((GrVariable) resolved).getInitializerGroovy();
assert newInitializer != null;
return newInitializer.getTextRange().getEndOffset();
}
}
}
}
return CANNOT_JOIN;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class IntroduceVariableValidatorTest method processFile.
private String processFile(String fileText) throws IncorrectOperationException, InvalidDataException, IOException {
String result = "";
int startOffset = fileText.indexOf(TestUtils.BEGIN_MARKER);
if (startOffset < 0) {
startOffset = fileText.indexOf(ALL_MARKER);
replaceAllOccurences = true;
fileText = IntroduceVariableTest.removeAllMarker(fileText);
} else {
replaceAllOccurences = false;
fileText = TestUtils.removeBeginMarker(fileText);
}
int endOffset = fileText.indexOf(TestUtils.END_MARKER);
fileText = TestUtils.removeEndMarker(fileText);
myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, fileText);
Editor myEditor = myFixture.getEditor();
myEditor.getSelectionModel().setSelection(startOffset, endOffset);
GrExpression selectedExpr = PsiImplUtil.findElementInRange(myFixture.getFile(), startOffset, endOffset, GrExpression.class);
Assert.assertNotNull("Selected expression reference points to null", selectedExpr);
final PsiElement tempContainer = GrIntroduceHandlerBase.getEnclosingContainer(selectedExpr);
Assert.assertTrue(tempContainer instanceof GroovyPsiElement);
PsiElement[] occurences = GroovyRefactoringUtil.getExpressionOccurrences(PsiUtil.skipParentheses(selectedExpr, false), tempContainer);
String varName = "preved";
GroovyVariableValidator validator = new GroovyVariableValidator(new GrIntroduceContextImpl(getProject(), myEditor, selectedExpr, null, null, occurences, tempContainer));
result = validator.isOKTest(varName, replaceAllOccurences);
return result;
}
Aggregations