use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList in project intellij-community by JetBrains.
the class IndexedExpressionConversionPredicate method satisfiedBy.
@Override
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof GrIndexProperty))
return false;
if (ErrorUtil.containsError(element))
return false;
final GrIndexProperty arrayIndexExpression = (GrIndexProperty) element;
final PsiElement lastChild = arrayIndexExpression.getLastChild();
if (!(lastChild instanceof GrArgumentList))
return false;
final GrArgumentList argList = (GrArgumentList) lastChild;
final GrExpression[] arguments = argList.getExpressionArguments();
if (arguments.length != 1)
return false;
final PsiElement parent = element.getParent();
if (!(parent instanceof GrAssignmentExpression)) {
return true;
}
final GrAssignmentExpression assignmentExpression = (GrAssignmentExpression) parent;
final GrExpression rvalue = assignmentExpression.getRValue();
if (rvalue == null)
return false;
if (rvalue.equals(element))
return true;
final IElementType operator = assignmentExpression.getOperationTokenType();
return GroovyTokenTypes.mASSIGN.equals(operator);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList in project intellij-community by JetBrains.
the class IndexingMethodConversionIntention method processIntention.
@Override
public void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
final GrMethodCallExpression callExpression = (GrMethodCallExpression) element;
final GrArgumentList argList = callExpression.getArgumentList();
final GrExpression[] arguments = argList.getExpressionArguments();
GrReferenceExpression methodExpression = (GrReferenceExpression) callExpression.getInvokedExpression();
final IElementType referenceType = methodExpression.getDotTokenType();
final String methodName = methodExpression.getReferenceName();
final GrExpression qualifier = methodExpression.getQualifierExpression();
if ("getAt".equals(methodName) || "get".equals(methodName)) {
PsiImplUtil.replaceExpression(qualifier.getText() + '[' + arguments[0].getText() + ']', callExpression);
} else {
PsiImplUtil.replaceExpression(qualifier.getText() + '[' + arguments[0].getText() + "]=" + arguments[1].getText(), callExpression);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList in project intellij-community by JetBrains.
the class RemoveParenthesesFromMethodCallIntention method processIntention.
@Override
protected void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
final GrMethodCallExpression expression = (GrMethodCallExpression) element;
final StringBuilder newStatementText = new StringBuilder();
newStatementText.append(expression.getInvokedExpression().getText()).append(' ');
final GrArgumentList argumentList = expression.getArgumentList();
final PsiElement leftParen = argumentList.getLeftParen();
final PsiElement rightParen = argumentList.getRightParen();
if (leftParen != null)
leftParen.delete();
if (rightParen != null)
rightParen.delete();
newStatementText.append(argumentList.getText());
final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(element.getProject());
final GrStatement newStatement = factory.createStatementFromText(newStatementText.toString());
expression.replaceWithStatement(newStatement);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList in project intellij-community by JetBrains.
the class RemoveParenthesesFromMethodPredicate method satisfiedBy.
@Override
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof GrMethodCallExpression))
return false;
if (!PsiUtil.isExpressionStatement(element))
return false;
final GrMethodCallExpression expression = (GrMethodCallExpression) element;
if (PsiImplUtil.hasClosureArguments(expression))
return false;
final StringBuilder newStatementText = new StringBuilder();
newStatementText.append(expression.getInvokedExpression().getText()).append(' ');
GrArgumentList argumentList = expression.getArgumentList();
final GroovyPsiElement[] allArguments = argumentList.getAllArguments();
argumentList = (GrArgumentList) argumentList.copy();
final PsiElement leftParen = argumentList.getLeftParen();
final PsiElement rightParen = argumentList.getRightParen();
if (leftParen != null)
leftParen.delete();
if (rightParen != null)
rightParen.delete();
newStatementText.append(argumentList.getText());
final GrStatement newStatement;
try {
newStatement = GroovyPsiElementFactory.getInstance(element.getProject()).createStatementFromText(newStatementText.toString());
} catch (IncorrectOperationException e) {
return false;
}
if (newStatement instanceof GrApplicationStatement) {
final GrCommandArgumentList newArgList = ((GrApplicationStatement) newStatement).getArgumentList();
if (newArgList.getAllArguments().length == allArguments.length) {
return true;
}
}
return false;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList in project intellij-community by JetBrains.
the class ApplicationStatementUtil method convertAppInternal.
private static GrMethodCallExpression convertAppInternal(GroovyPsiElementFactory factory, GrApplicationStatement app) {
final GrCommandArgumentList list = app.getArgumentList();
final GrMethodCallExpression prototype = (GrMethodCallExpression) factory.createExpressionFromText("foo()");
prototype.getInvokedExpression().replace(app.getInvokedExpression());
final GrArgumentList pList = prototype.getArgumentList();
final PsiElement anchor = pList.getRightParen();
for (GroovyPsiElement arg : list.getAllArguments()) {
pList.addBefore(arg, anchor);
}
return prototype;
}
Aggregations