use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression 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.expressions.path.GrMethodCallExpression 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.expressions.path.GrMethodCallExpression 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.expressions.path.GrMethodCallExpression in project intellij-community by JetBrains.
the class ConvertJavaStyleArrayIntention method getElementPredicate.
@NotNull
@Override
protected PsiElementPredicate getElementPredicate() {
return new PsiElementPredicate() {
@Override
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof GrMethodCallExpression))
return false;
final GrExpression expression = ((GrMethodCallExpression) element).getInvokedExpression();
if (!(expression instanceof GrNewExpression))
return false;
if (((GrNewExpression) expression).getArrayCount() == 0)
return false;
if (!((GrMethodCallExpression) element).getArgumentList().getText().trim().isEmpty())
return false;
final GrClosableBlock[] closureArguments = ((GrMethodCallExpression) element).getClosureArguments();
if (closureArguments.length != 1)
return false;
final GrClosableBlock block = closureArguments[0];
if (block.getLBrace() == null || block.getRBrace() == null)
return false;
return true;
}
};
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression in project intellij-community by JetBrains.
the class GroovyBlockGenerator method addNestedChildren.
private void addNestedChildren(final PsiElement elem, List<Block> list, @Nullable AlignmentProvider.Aligner aligner, final boolean topLevel, Wrap wrap) {
final List<ASTNode> children = visibleChildren(elem.getNode());
if (elem instanceof GrMethodCallExpression) {
GrExpression invokedExpression = ((GrMethodCallExpression) elem).getInvokedExpression();
if (invokedExpression instanceof GrQualifiedReference) {
final PsiElement nameElement = ((GrQualifiedReference) invokedExpression).getReferenceNameElement();
if (nameElement != null) {
List<ASTNode> grandChildren = visibleChildren(invokedExpression.getNode());
int i = 0;
while (i < grandChildren.size() && nameElement != grandChildren.get(i).getPsi()) i++;
if (i > 0) {
processNestedChildrenPrefix(list, aligner, false, grandChildren, i, wrap);
}
if (i < grandChildren.size()) {
LOG.assertTrue(nameElement == grandChildren.get(i).getPsi());
list.add(new MethodCallWithoutQualifierBlock(nameElement, wrap, topLevel, children, elem, myContext));
}
return;
}
}
}
processNestedChildrenPrefix(list, aligner, topLevel, children, children.size(), wrap);
}
Aggregations