Search in sources :

Example 41 with GrNamedArgument

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

the class GrListOrMapImpl method deleteChildInternal.

@Override
public void deleteChildInternal(@NotNull ASTNode child) {
    final PsiElement psi = child.getPsi();
    if (psi instanceof GrExpression || psi instanceof GrNamedArgument) {
        PsiElement prev = PsiUtil.getPrevNonSpace(psi);
        PsiElement next = PsiUtil.getNextNonSpace(psi);
        if (prev != null && prev.getNode() != null && prev.getNode().getElementType() == GroovyTokenTypes.mCOMMA) {
            super.deleteChildInternal(prev.getNode());
        } else if (next instanceof LeafPsiElement && next.getNode() != null && next.getNode().getElementType() == GroovyTokenTypes.mCOMMA) {
            super.deleteChildInternal(next.getNode());
        }
    }
    super.deleteChildInternal(child);
}
Also used : GrNamedArgument(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement)

Example 42 with GrNamedArgument

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

the class GrArgumentListImpl method addNamedArgument.

@Override
public GrNamedArgument addNamedArgument(final GrNamedArgument namedArgument) {
    final GrNamedArgument[] namedArguments = getNamedArguments();
    final GrExpression[] args = getExpressionArguments();
    PsiElement anchor = null;
    final int namedCount = namedArguments.length;
    final int exprCount = args.length;
    if (namedCount > 0) {
        anchor = namedArguments[namedCount - 1];
    } else if (exprCount > 0) {
        anchor = args[exprCount - 1];
    }
    if (anchor != null) {
        anchor = PsiUtil.getNextNonSpace(anchor);
    } else {
        anchor = getRightParen();
    }
    addBefore(namedArgument, anchor);
    return namedArgument;
}
Also used : GrNamedArgument(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) PsiElement(com.intellij.psi.PsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)

Example 43 with GrNamedArgument

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

the class GrArgumentListImpl method deleteChildInternal.

@Override
public void deleteChildInternal(@NotNull ASTNode child) {
    PsiElement element = child.getPsi();
    if (element instanceof GrExpression || element instanceof GrNamedArgument) {
        ASTNode prev = TreeUtil.skipElementsBack(child.getTreePrev(), TokenSets.WHITE_SPACES_OR_COMMENTS);
        if (prev != null && prev.getElementType() == GroovyTokenTypes.mCOMMA) {
            final ASTNode pprev = prev.getTreePrev();
            if (pprev != null && PsiImplUtil.isWhiteSpaceOrNls(pprev)) {
                super.deleteChildInternal(pprev);
            }
            super.deleteChildInternal(prev);
        } else {
            ASTNode next = TreeUtil.skipElements(child.getTreeNext(), TokenSets.WHITE_SPACES_OR_COMMENTS);
            if (next != null && next.getElementType() == GroovyTokenTypes.mCOMMA) {
                final ASTNode nnext = next.getTreeNext();
                if (nnext != null && PsiImplUtil.isWhiteSpaceOrNls(nnext)) {
                    super.deleteChildInternal(nnext);
                }
                super.deleteChildInternal(next);
            }
        }
    }
    super.deleteChildInternal(child);
}
Also used : GrNamedArgument(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument) ASTNode(com.intellij.lang.ASTNode) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) PsiElement(com.intellij.psi.PsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)

Example 44 with GrNamedArgument

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

the class MyPredicate method processIntention.

@Override
protected void processIntention(@NotNull PsiElement element, @NotNull final Project project, Editor editor) throws IncorrectOperationException {
    final GrListOrMap map = (GrListOrMap) element;
    final GrNamedArgument[] namedArguments = map.getNamedArguments();
    LOG.assertTrue(map.getInitializers().length == 0);
    final PsiFile file = map.getContainingFile();
    final String packageName = file instanceof GroovyFileBase ? ((GroovyFileBase) file).getPackageName() : "";
    final CreateClassDialog dialog = new CreateClassDialog(project, GroovyBundle.message("create.class.family.name"), "", packageName, GrCreateClassKind.CLASS, true, ModuleUtilCore.findModuleForPsiElement(element));
    dialog.show();
    if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE)
        return;
    boolean replaceReturnType = checkForReturnFromMethod(map);
    boolean variableDeclaration = checkForVariableDeclaration(map);
    final GrParameter methodParameter = checkForMethodParameter(map);
    final String qualifiedClassName = dialog.getClassName();
    final String selectedPackageName = StringUtil.getPackageName(qualifiedClassName);
    final String shortName = StringUtil.getShortName(qualifiedClassName);
    final GrTypeDefinition typeDefinition = createClass(project, namedArguments, selectedPackageName, shortName);
    final PsiClass generatedClass = CreateClassActionBase.createClassByType(dialog.getTargetDirectory(), typeDefinition.getName(), PsiManager.getInstance(project), map, GroovyTemplates.GROOVY_CLASS, true);
    final PsiClass replaced = (PsiClass) generatedClass.replace(typeDefinition);
    replaceMapWithClass(project, map, replaced, replaceReturnType, variableDeclaration, methodParameter);
}
Also used : GroovyFileBase(org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase) GrNamedArgument(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument) CreateClassDialog(com.intellij.codeInsight.intention.impl.CreateClassDialog) GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) GrListOrMap(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap) GrParameter(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)

Example 45 with GrNamedArgument

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

the class MyPredicate method satisfiedBy.

@Override
public boolean satisfiedBy(PsiElement element) {
    if (!(element instanceof GrListOrMap))
        return false;
    final GrListOrMap map = (GrListOrMap) element;
    final GrNamedArgument[] namedArguments = map.getNamedArguments();
    final GrExpression[] initializers = map.getInitializers();
    if (initializers.length != 0)
        return false;
    for (GrNamedArgument argument : namedArguments) {
        final GrArgumentLabel label = argument.getLabel();
        final GrExpression expression = argument.getExpression();
        if (label == null || expression == null)
            return false;
        if (label.getName() == null)
            return false;
    }
    return true;
}
Also used : GrNamedArgument(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument) GrArgumentLabel(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentLabel) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GrListOrMap(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap)

Aggregations

GrNamedArgument (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument)48 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)17 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)16 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)13 GrListOrMap (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap)12 PsiElement (com.intellij.psi.PsiElement)11 GrArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)11 Nullable (org.jetbrains.annotations.Nullable)10 GrArgumentLabel (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentLabel)8 NotNull (org.jetbrains.annotations.NotNull)5 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)5 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)5 GrString (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString)5 IncorrectOperationException (com.intellij.util.IncorrectOperationException)4 NamedArgumentDescriptor (org.jetbrains.plugins.groovy.extensions.NamedArgumentDescriptor)4 GrClosureSignature (org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature)4 GrCall (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall)4 ASTNode (com.intellij.lang.ASTNode)3 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)3 ArrayList (java.util.ArrayList)3