Search in sources :

Example 56 with GrArgumentList

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList in project intellij-community by JetBrains.

the class GrEnumConstantInfo method inferArgTypes.

@Nullable
@Override
protected PsiType[] inferArgTypes() {
    GrEnumConstant call = getCall();
    GrArgumentList argList = call.getArgumentList();
    if (argList != null) {
        return PsiUtil.getArgumentTypes(argList);
    } else {
        return PsiType.EMPTY_ARRAY;
    }
}
Also used : GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) GrEnumConstant(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrEnumConstant) Nullable(org.jetbrains.annotations.Nullable)

Example 57 with GrArgumentList

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList in project intellij-community by JetBrains.

the class GrNewExpressionInfo method getElementToHighlight.

@NotNull
@Override
public PsiElement getElementToHighlight() {
    GrNewExpression call = getCall();
    GrArgumentList argList = call.getArgumentList();
    if (argList != null)
        return argList;
    GrCodeReferenceElement ref = call.getReferenceElement();
    if (ref != null)
        return ref;
    throw new IncorrectOperationException("reference of new expression should exist if it is a constructor call");
}
Also used : GrNewExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrNewExpression) GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) IncorrectOperationException(com.intellij.util.IncorrectOperationException) NotNull(org.jetbrains.annotations.NotNull)

Example 58 with GrArgumentList

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList in project intellij-community by JetBrains.

the class GroovyAnnotator method visitEnumConstant.

@Override
public void visitEnumConstant(@NotNull GrEnumConstant enumConstant) {
    super.visitEnumConstant(enumConstant);
    final GrArgumentList argumentList = enumConstant.getArgumentList();
    if (argumentList != null && PsiImplUtil.hasNamedArguments(argumentList) && !PsiImplUtil.hasExpressionArguments(argumentList)) {
        final PsiMethod constructor = enumConstant.resolveConstructor();
        if (constructor != null) {
            if (!PsiUtil.isConstructorHasRequiredParameters(constructor)) {
                myHolder.createErrorAnnotation(argumentList, GroovyBundle.message("the.usage.of.a.map.entry.expression.to.initialize.an.enum.is.currently.not.supported"));
            }
        }
    }
}
Also used : GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)

Example 59 with GrArgumentList

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList in project intellij-community by JetBrains.

the class GroovyAnnotator method visitTypeDefinitionBody.

@Override
public void visitTypeDefinitionBody(@NotNull GrTypeDefinitionBody typeDefinitionBody) {
    final PsiElement parent = typeDefinitionBody.getParent();
    if (!(parent instanceof GrAnonymousClassDefinition))
        return;
    final PsiElement prev = typeDefinitionBody.getPrevSibling();
    if (!PsiUtil.isLineFeed(prev))
        return;
    final PsiElement newExpression = parent.getParent();
    if (!(newExpression instanceof GrNewExpression))
        return;
    final GrStatementOwner statementOwner = PsiTreeUtil.getParentOfType(newExpression, GrStatementOwner.class);
    final GrParenthesizedExpression parenthesizedExpression = PsiTreeUtil.getParentOfType(newExpression, GrParenthesizedExpression.class);
    if (parenthesizedExpression != null && PsiTreeUtil.isAncestor(statementOwner, parenthesizedExpression, true))
        return;
    final GrArgumentList argumentList = PsiTreeUtil.getParentOfType(newExpression, GrArgumentList.class);
    if (argumentList != null && !(argumentList instanceof GrCommandArgumentList)) {
        if (PsiTreeUtil.isAncestor(statementOwner, argumentList, true))
            return;
    }
    myHolder.createErrorAnnotation(typeDefinitionBody, GroovyBundle.message("ambiguous.code.block"));
}
Also used : GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) GrStatementOwner(org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner)

Example 60 with GrArgumentList

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList in project intellij-community by JetBrains.

the class GrMethodCallExpressionImpl method replaceClosureArgument.

@Override
public GrExpression replaceClosureArgument(@NotNull GrClosableBlock closure, @NotNull GrExpression newExpr) throws IncorrectOperationException {
    if (newExpr instanceof GrClosableBlock) {
        return closure.replaceWithExpression(newExpr, true);
    }
    final GrClosableBlock[] closureArguments = getClosureArguments();
    final int i = ArrayUtil.find(closureArguments, closure);
    GrArgumentList argList = getArgumentList();
    if (argList.getText().isEmpty()) {
        argList = (GrArgumentList) argList.replace(GroovyPsiElementFactory.getInstance(getProject()).createArgumentList());
    }
    for (int j = 0; j < i; j++) {
        argList.add(closureArguments[j]);
        closureArguments[j].delete();
    }
    final GrExpression result = (GrExpression) argList.add(newExpr);
    closure.delete();
    return result;
}
Also used : GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)

Aggregations

GrArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)80 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)26 PsiElement (com.intellij.psi.PsiElement)21 Nullable (org.jetbrains.annotations.Nullable)20 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)18 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)15 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)14 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)14 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)14 GrMethodCallExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression)14 GrNamedArgument (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument)12 GrListOrMap (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap)9 GrCall (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall)8 GrMethodCall (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall)8 NotNull (org.jetbrains.annotations.NotNull)7 GrCommandArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCommandArgumentList)6 GrLiteral (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral)6 GrGdkMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod)6 GrCodeReferenceElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement)6 ASTNode (com.intellij.lang.ASTNode)5