use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression in project intellij-community by JetBrains.
the class NewGantScriptAction method doCreate.
@Override
@NotNull
protected PsiElement[] doCreate(String newName, PsiDirectory directory) throws Exception {
PsiFile file = createGantScriptFromTemplate(directory, newName, GroovyTemplates.GANT_SCRIPT);
PsiElement lastChild = file.getLastChild();
PsiElement child = null;
if (lastChild instanceof GrMethodCallExpression) {
child = lastChild;
}
if (child == null && file.getChildren().length > 0) {
child = file.getLastChild();
}
return child != null ? new PsiElement[] { file, child } : new PsiElement[] { file };
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression in project intellij-community by JetBrains.
the class OldReferencesResolver method canRemoveQualifier.
private static boolean canRemoveQualifier(GrReferenceExpression refExpr) {
try {
GrExpression qualifier = refExpr.getQualifier();
if (!(qualifier instanceof GrReferenceExpression))
return false;
PsiElement qualifierRefElement = ((GrReferenceExpression) qualifier).resolve();
if (!(qualifierRefElement instanceof PsiClass))
return false;
PsiElement refElement = refExpr.resolve();
if (refElement == null)
return false;
final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(refExpr.getProject());
if (refExpr.getParent() instanceof GrMethodCallExpression) {
GrMethodCallExpression methodCall = (GrMethodCallExpression) refExpr.getParent();
GrMethodCallExpression newMethodCall = (GrMethodCallExpression) factory.createExpressionFromText(refExpr.getReferenceName() + "()", refExpr);
newMethodCall.getArgumentList().replace(methodCall.getArgumentList());
PsiElement newRefElement = ((GrReferenceExpression) newMethodCall.getInvokedExpression()).resolve();
return refElement.equals(newRefElement);
} else {
GrReferenceExpression newRefExpr = (GrReferenceExpression) factory.createExpressionFromText(refExpr.getReferenceName(), refExpr);
PsiElement newRefElement = newRefExpr.resolve();
return refElement.equals(newRefElement);
}
} catch (IncorrectOperationException e) {
return false;
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression 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;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression in project intellij-community by JetBrains.
the class SurrounderByClosure method doSurroundElements.
@Override
protected GroovyPsiElement doSurroundElements(PsiElement[] elements, PsiElement context) throws IncorrectOperationException {
for (PsiElement element : elements) {
if (element instanceof GroovyPsiElement) {
((GroovyPsiElement) element).accept(new MyMemoizingVisitor());
}
}
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(elements[0].getProject());
final GrMethodCallExpression call = (GrMethodCallExpression) factory.createExpressionFromText("{ -> \n}.call()", context);
final GrClosableBlock closure = (GrClosableBlock) ((GrReferenceExpression) call.getInvokedExpression()).getQualifierExpression();
addStatements(closure, elements);
return call;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression in project intellij-community by JetBrains.
the class WithExprSurrounder method surroundExpression.
@Override
protected TextRange surroundExpression(@NotNull GrExpression expression, PsiElement context) {
GrMethodCallExpression call = (GrMethodCallExpression) GroovyPsiElementFactory.getInstance(expression.getProject()).createStatementFromText("with(a){4\n}", context);
replaceToOldExpression(call.getExpressionArguments()[0], expression);
call = expression.replaceWithStatement(call);
GrClosableBlock block = call.getClosureArguments()[0];
GrStatement statementInBody = block.getStatements()[0];
int offset = statementInBody.getTextRange().getStartOffset();
statementInBody.getParent().getNode().removeChild(statementInBody.getNode());
return new TextRange(offset, offset);
}
Aggregations