Search in sources :

Example 1 with PsiNameValuePair

use of com.intellij.psi.PsiNameValuePair in project intellij-community by JetBrains.

the class AnnotationInitializerBlocksBuilder method buildBlocks.

public List<Block> buildBlocks() {
    final Wrap wrap = Wrap.createWrap(getWrapType(myJavaSettings.ANNOTATION_PARAMETER_WRAP), false);
    final Alignment alignment = myJavaSettings.ALIGN_MULTILINE_ANNOTATION_PARAMETERS ? Alignment.createAlignment() : null;
    ChildrenBlocksBuilder.Config config = new ChildrenBlocksBuilder.Config().setDefaultIndent(Indent.getContinuationWithoutFirstIndent()).setIndent(JavaTokenType.RPARENTH, Indent.getNoneIndent()).setIndent(JavaTokenType.LPARENTH, Indent.getNoneIndent()).setDefaultWrap(wrap).setNoWrap(JavaTokenType.COMMA).setNoWrap(JavaTokenType.RPARENTH).setNoWrap(JavaTokenType.LPARENTH).setDefaultAlignment(alignment).setNoAlignment(JavaTokenType.COMMA).setNoAlignment(JavaTokenType.LPARENTH).setNoAlignmentIf(JavaTokenType.RPARENTH, node -> {
        PsiElement prev = PsiTreeUtil.skipSiblingsBackward(node.getPsi(), PsiWhiteSpace.class);
        if (prev == null)
            return false;
        return prev instanceof PsiNameValuePair && !PsiTreeUtil.hasErrorElements(prev);
    });
    return config.createBuilder().buildNodeChildBlocks(myNode, myFactory);
}
Also used : Alignment(com.intellij.formatting.Alignment) Wrap(com.intellij.formatting.Wrap) PsiNameValuePair(com.intellij.psi.PsiNameValuePair) PsiElement(com.intellij.psi.PsiElement)

Example 2 with PsiNameValuePair

use of com.intellij.psi.PsiNameValuePair in project intellij-community by JetBrains.

the class GrAnnotationArgumentListImpl method addInternal.

@Override
public ASTNode addInternal(ASTNode first, ASTNode last, ASTNode anchor, Boolean before) {
    if (first.getElementType() == GroovyElementTypes.ANNOTATION_MEMBER_VALUE_PAIR && last.getElementType() == GroovyElementTypes.ANNOTATION_MEMBER_VALUE_PAIR) {
        ASTNode lparenth = getNode().getFirstChildNode();
        ASTNode rparenth = getNode().getLastChildNode();
        if (lparenth == null) {
            getNode().addLeaf(GroovyTokenTypes.mLPAREN, "(", null);
        }
        if (rparenth == null) {
            getNode().addLeaf(GroovyTokenTypes.mRPAREN, ")", null);
        }
        final PsiNameValuePair[] nodes = getAttributes();
        if (nodes.length == 1) {
            final PsiNameValuePair pair = nodes[0];
            if (pair.getName() == null) {
                final String text = pair.getValue().getText();
                try {
                    final PsiAnnotation annotation = GroovyPsiElementFactory.getInstance(getProject()).createAnnotationFromText("@AAA(value = " + text + ")");
                    getNode().replaceChild(pair.getNode(), annotation.getParameterList().getAttributes()[0].getNode());
                } catch (IncorrectOperationException e) {
                    LOG.error(e);
                }
            }
        }
        if (anchor == null && before != null) {
            anchor = before.booleanValue() ? getNode().getLastChildNode() : getNode().getFirstChildNode();
        }
    }
    return super.addInternal(first, last, anchor, before);
}
Also used : PsiNameValuePair(com.intellij.psi.PsiNameValuePair) ASTNode(com.intellij.lang.ASTNode) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PsiAnnotation(com.intellij.psi.PsiAnnotation)

Aggregations

PsiNameValuePair (com.intellij.psi.PsiNameValuePair)2 Alignment (com.intellij.formatting.Alignment)1 Wrap (com.intellij.formatting.Wrap)1 ASTNode (com.intellij.lang.ASTNode)1 PsiAnnotation (com.intellij.psi.PsiAnnotation)1 PsiElement (com.intellij.psi.PsiElement)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1