use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList 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.arguments.GrArgumentList in project intellij-community by JetBrains.
the class GroovyParameterInfoHandler method getCurrentParameterIndex.
private static int getCurrentParameterIndex(GroovyPsiElement place, int offset) {
if (place instanceof GrArgumentList) {
GrArgumentList list = (GrArgumentList) place;
int idx = (list.getNamedArguments().length > 0) ? 1 : 0;
for (PsiElement child = list.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child.getTextRange().contains(offset)) {
if (child instanceof GrNamedArgument)
return 0;
return idx;
}
if (child.getNode().getElementType() == GroovyTokenTypes.mCOMMA)
idx++;
if (isNamedArgWithPriorComma(child))
idx--;
}
}
return -1;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList in project intellij-community by JetBrains.
the class ExpressionGenerator method hasFieldInitialization.
private static boolean hasFieldInitialization(GrNewExpression newExpression) {
final GrArgumentList argumentList = newExpression.getArgumentList();
if (argumentList == null)
return false;
if (argumentList.getNamedArguments().length == 0)
return false;
final GrCodeReferenceElement refElement = newExpression.getReferenceElement();
if (refElement == null)
return false;
final GroovyResolveResult resolveResult = newExpression.advancedResolve();
final PsiElement constructor = resolveResult.getElement();
if (constructor instanceof PsiMethod) {
return ((PsiMethod) constructor).getParameterList().getParametersCount() == 0;
}
final PsiElement resolved = refElement.resolve();
return resolved instanceof PsiClass;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList in project intellij-community by JetBrains.
the class GroovyCompletionData method suggestPrimitiveTypes.
private static boolean suggestPrimitiveTypes(PsiElement context) {
if (isInfixOperatorPosition(context))
return false;
if (isAfterForParameter(context))
return false;
final PsiElement parent = context.getParent();
if (parent == null)
return false;
PsiElement previous = PsiImplUtil.realPrevious(parent.getPrevSibling());
if (parent instanceof GrReferenceElement && parent.getParent() instanceof GrArgumentList) {
PsiElement prevSibling = context.getPrevSibling();
if (prevSibling != null && prevSibling.getNode() != null) {
if (!TokenSets.DOTS.contains(prevSibling.getNode().getElementType())) {
return true;
}
} else if (!(previous != null && GroovyTokenTypes.mAT.equals(previous.getNode().getElementType()))) {
return true;
}
}
if (GroovyCompletionUtil.isTupleVarNameWithoutTypeDeclared(context))
return true;
if (previous != null && GroovyTokenTypes.mAT.equals(previous.getNode().getElementType())) {
return false;
}
if (GroovyCompletionUtil.asSimpleVariable(context) || GroovyCompletionUtil.asTypedMethod(context) || GroovyCompletionUtil.asVariableInBlock(context) || asVariableAfterModifiers(context)) {
return true;
}
if ((parent instanceof GrParameter && ((GrParameter) parent).getTypeElementGroovy() == null) || parent instanceof GrReferenceElement && !(parent.getParent() instanceof GrImportStatement) && !(parent.getParent() instanceof GrPackageDefinition) && !(parent.getParent() instanceof GrArgumentList)) {
PsiElement prevSibling = context.getPrevSibling();
if (parent instanceof GrReferenceElement && prevSibling != null && prevSibling.getNode() != null) {
ASTNode node = prevSibling.getNode();
return !TokenSets.DOTS.contains(node.getElementType());
} else {
return true;
}
}
if (PsiImplUtil.realPrevious(parent.getPrevSibling()) instanceof GrModifierList) {
return true;
}
if (PsiImplUtil.realPrevious(context.getPrevSibling()) instanceof GrModifierList) {
return true;
}
return parent instanceof GrExpression && parent.getParent() instanceof GroovyFile && GroovyCompletionUtil.isNewStatement(context, false);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList in project intellij-community by JetBrains.
the class ConvertParameterToMapEntryIntention method analyzeForNamedArguments.
/**
* @param owner Method or closure
* @param occurrences references to owner
* @return true if there we use owner's first parameter as map, false if we need to add ne one as fist map
*/
private static FIRST_PARAMETER_KIND analyzeForNamedArguments(final GrParametersOwner owner, final Collection<PsiElement> occurrences) {
boolean thereAreNamedArguments = false;
for (PsiElement occurrence : occurrences) {
if (occurrence instanceof GrReferenceExpression && occurrence.getParent() instanceof GrCall) {
final GrCall call = (GrCall) occurrence.getParent();
final GrArgumentList args = call.getArgumentList();
if (args != null && args.getNamedArguments().length > 0) {
thereAreNamedArguments = true;
}
}
if (thereAreNamedArguments)
break;
}
if (thereAreNamedArguments) {
if (firstOwnerParameterMustBeMap(owner)) {
return FIRST_PARAMETER_KIND.MUST_BE_MAP;
}
return FIRST_PARAMETER_KIND.ERROR;
}
return FIRST_PARAMETER_KIND.IS_NOT_MAP;
}
Aggregations