Search in sources :

Example 61 with GrArgumentList

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

the class GrArgumentListImpl method replaceWithArgumentList.

@Override
public GrArgumentList replaceWithArgumentList(GrArgumentList newArgList) throws IncorrectOperationException {
    if (this.getParent() == null || this.getParent().getNode() == null) {
        throw new IncorrectOperationException();
    }
    ASTNode parentNode = this.getParent().getNode();
    ASTNode newNode = newArgList.getNode();
    assert parentNode != null;
    parentNode.replaceChild(this.getNode(), newNode);
    if (!(newNode.getPsi() instanceof GrArgumentList)) {
        throw new IncorrectOperationException();
    }
    return ((GrArgumentList) newNode.getPsi());
}
Also used : GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) ASTNode(com.intellij.lang.ASTNode) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

Example 62 with GrArgumentList

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

the class GrCallImpl method addNamedArgument.

@Override
public GrNamedArgument addNamedArgument(final GrNamedArgument namedArgument) throws IncorrectOperationException {
    GrArgumentList list = getArgumentList();
    assert list != null;
    if (list.getText().trim().isEmpty()) {
        final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(getProject());
        final GrArgumentList newList = factory.createExpressionArgumentList();
        list = (GrArgumentList) list.replace(newList);
    }
    return list.addNamedArgument(namedArgument);
}
Also used : GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)

Example 63 with GrArgumentList

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

the class GrNewExpressionImpl method addNamedArgument.

@Override
public GrNamedArgument addNamedArgument(final GrNamedArgument namedArgument) throws IncorrectOperationException {
    final GrArgumentList list = getArgumentList();
    if (list == null) {
        //so it is not anonymous class declaration
        final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(getProject());
        final GrArgumentList newList = factory.createExpressionArgumentList();
        PsiElement last = getLastChild();
        assert last != null;
        while (last.getPrevSibling() instanceof PsiWhiteSpace || last.getPrevSibling() instanceof PsiErrorElement) {
            last = last.getPrevSibling();
            assert last != null;
        }
        ASTNode astNode = last.getNode();
        assert astNode != null;
        getNode().addChild(newList.getNode(), astNode);
    }
    return super.addNamedArgument(namedArgument);
}
Also used : GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) ASTNode(com.intellij.lang.ASTNode)

Example 64 with GrArgumentList

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

the class GrEnumConstantImpl method getOrCreateInitializingClass.

@NotNull
@Override
public PsiEnumConstantInitializer getOrCreateInitializingClass() {
    final GrEnumConstantInitializer initializingClass = getInitializingClass();
    if (initializingClass != null)
        return initializingClass;
    final GrEnumConstantInitializer initializer = GroovyPsiElementFactory.getInstance(getProject()).createEnumConstantFromText("foo{}").getInitializingClass();
    LOG.assertTrue(initializer != null);
    final GrArgumentList argumentList = getArgumentList();
    if (argumentList != null) {
        return (PsiEnumConstantInitializer) addAfter(initializer, argumentList);
    } else {
        return (PsiEnumConstantInitializer) addAfter(initializer, getNameIdentifierGroovy());
    }
}
Also used : GrEnumConstantInitializer(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrEnumConstantInitializer) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) NotNull(org.jetbrains.annotations.NotNull)

Example 65 with GrArgumentList

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

the class MakeClosureCallImplicitIntention method processIntention.

@Override
public void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
    final GrMethodCallExpression expression = (GrMethodCallExpression) element;
    final GrReferenceExpression invokedExpression = (GrReferenceExpression) expression.getInvokedExpression();
    final GrExpression qualifier = invokedExpression.getQualifierExpression();
    final GrArgumentList argList = expression.getArgumentList();
    final GrClosableBlock[] closureArgs = expression.getClosureArguments();
    final StringBuilder newExpression = new StringBuilder();
    newExpression.append(qualifier.getText());
    newExpression.append(argList.getText());
    for (GrClosableBlock closureArg : closureArgs) {
        newExpression.append(closureArg.getText());
    }
    PsiImplUtil.replaceExpression(newExpression.toString(), expression);
}
Also used : GrMethodCallExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression) 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) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

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