use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression in project intellij-community by JetBrains.
the class GroovySimpleManyStatementsSurrounder method doSurroundElements.
@Override
protected final GroovyPsiElement doSurroundElements(PsiElement[] elements, PsiElement context) throws IncorrectOperationException {
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(elements[0].getProject());
GrMethodCallExpression withCall = (GrMethodCallExpression) factory.createExpressionFromText(getReplacementTokens(), context);
addStatements(withCall.getClosureArguments()[0], elements);
return withCall;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression in project intellij-community by JetBrains.
the class ConvertJavaStyleArrayIntention method processIntention.
@Override
protected void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
final GrClosableBlock block = ((GrMethodCallExpression) element).getClosureArguments()[0];
final String text = block.getText();
int start = block.getLBrace().getStartOffsetInParent() + 1;
int finish = block.getRBrace().getStartOffsetInParent();
String newText = "[" + text.substring(start, finish) + "]";
final GrExpression newExpr = GroovyPsiElementFactory.getInstance(element.getProject()).createExpressionFromText(newText);
((GrMethodCallExpression) element).replaceWithStatement(newExpr);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression in project intellij-community by JetBrains.
the class IndexingMethodConversionPredicate method satisfiedBy.
@Override
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof GrMethodCallExpression)) {
return false;
}
if (ErrorUtil.containsError(element)) {
return false;
}
final GrMethodCallExpression callExpression = (GrMethodCallExpression) element;
final GrArgumentList argList = callExpression.getArgumentList();
final GrExpression[] arguments = argList.getExpressionArguments();
final GrExpression invokedExpression = callExpression.getInvokedExpression();
if (!(invokedExpression instanceof GrReferenceExpression)) {
return false;
}
final GrReferenceExpression referenceExpression = (GrReferenceExpression) invokedExpression;
final GrExpression qualifier = referenceExpression.getQualifierExpression();
if (qualifier == null) {
return false;
}
final IElementType referenceType = referenceExpression.getDotTokenType();
if (!GroovyTokenTypes.mDOT.equals(referenceType)) {
return false;
}
final String methodName = referenceExpression.getReferenceName();
if ("getAt".equals(methodName)) {
return arguments.length == 1;
}
if ("get".equals(methodName)) {
final PsiType qualifierType = qualifier.getType();
if (!isMap(qualifierType)) {
return false;
}
return arguments.length == 1;
} else if ("setAt".equals(methodName)) {
return arguments.length == 2;
} else if ("put".equals(methodName)) {
final PsiType qualifierType = qualifier.getType();
if (!isMap(qualifierType)) {
return false;
}
return arguments.length == 2;
}
return false;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression in project intellij-community by JetBrains.
the class ExtractUtil method createResultStatement.
@NotNull
private static GrStatement[] createResultStatement(ExtractInfoHelper helper) {
VariableInfo[] outputVars = helper.getOutputVariableInfos();
PsiType type = helper.getOutputType();
GrStatement[] statements = helper.getStatements();
GrMethodCallExpression callExpression = createMethodCall(helper);
if ((outputVars.length == 0 || PsiType.VOID.equals(type)) && !helper.hasReturnValue())
return new GrStatement[] { callExpression };
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(helper.getProject());
if (helper.hasReturnValue()) {
return new GrStatement[] { factory.createStatementFromText("return " + callExpression.getText()) };
}
LOG.assertTrue(outputVars.length > 0);
final List<VariableInfo> mustAdd = mustAddVariableDeclaration(statements, outputVars);
if (mustAdd.isEmpty()) {
return new GrStatement[] { createAssignment(outputVars, callExpression, helper.getProject()) };
} else if (mustAdd.size() == outputVars.length && outputVars.length == 1) {
return new GrVariableDeclaration[] { factory.createVariableDeclaration(ArrayUtil.EMPTY_STRING_ARRAY, callExpression, outputVars[0].getType(), outputVars[0].getName()) };
} else if (varsAreEqual(mustAdd, outputVars)) {
return createTupleDeclaration(outputVars, callExpression, helper.getProject());
} else {
final List<GrStatement> result = generateVarDeclarations(mustAdd, helper.getProject(), null);
result.add(createAssignment(outputVars, callExpression, helper.getProject()));
return result.toArray(new GrStatement[result.size()]);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression in project intellij-community by JetBrains.
the class GantUtils method getScriptTargets.
public static GrArgumentLabel[] getScriptTargets(GroovyFile file) {
ArrayList<GrArgumentLabel> labels = new ArrayList<>();
for (PsiElement child : file.getChildren()) {
if (child instanceof GrMethodCallExpression) {
GrMethodCallExpression call = (GrMethodCallExpression) child;
GrNamedArgument[] arguments = call.getNamedArguments();
if (arguments.length == 1) {
GrArgumentLabel label = arguments[0].getLabel();
if (label != null && isPlainIdentifier(label)) {
labels.add(label);
}
}
}
}
return labels.toArray(new GrArgumentLabel[labels.size()]);
}
Aggregations