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);
}
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);
}
Aggregations