private SyntheticCodeBlock createCaseSectionBlock(
      final ArrayList<Block> localResult,
      final Alignment childAlignment,
      final Indent indent,
      final Wrap childWrap) {
    final SyntheticCodeBlock result =
        new SyntheticCodeBlock(
            localResult, childAlignment, getSettings(), myJavaSettings, indent, childWrap) {
          @Override
          @NotNull
          public ChildAttributes getChildAttributes(final int newChildIndex) {
            IElementType prevElementType = null;
            if (newChildIndex > 0) {
              final Block previousBlock = getSubBlocks().get(newChildIndex - 1);
              if (previousBlock instanceof AbstractBlock) {
                prevElementType = ((AbstractBlock) previousBlock).getNode().getElementType();
              }
            }

            if (prevElementType == JavaElementType.BLOCK_STATEMENT
                || prevElementType == JavaElementType.BREAK_STATEMENT
                || prevElementType == JavaElementType.RETURN_STATEMENT) {
              return new ChildAttributes(Indent.getNoneIndent(), null);
            } else {
              return super.getChildAttributes(newChildIndex);
            }
          }
        };
    result.setChildAttributes(new ChildAttributes(Indent.getNormalIndent(), null));
    result.setIsIncomplete(true);
    return result;
  }
Ejemplo n.º 2
0
  private RestBlock buildSubBlock(ASTNode child) {
    IElementType parentType = myNode.getElementType();
    IElementType childType = child.getElementType();
    IElementType grandparentType =
        myNode.getTreeParent() == null ? null : myNode.getTreeParent().getElementType();
    Wrap wrap = null;
    Indent childIndent = Indent.getNoneIndent();
    Alignment childAlignment = null;

    if (grandparentType == RestElementTypes.FIELD_LIST
        && parentType == RestElementTypes.LINE_TEXT
        && childType == RestTokenTypes.LINE) {
      childIndent = Indent.getNormalIndent();
    }
    return new RestBlock(this, child, childAlignment, childIndent, wrap);
  }
  @Nullable
  private ASTNode processCaseAndStatementAfter(
      final ArrayList<Block> result,
      ASTNode child,
      final Alignment childAlignment,
      final Wrap childWrap,
      final Indent indent) {
    final ArrayList<Block> localResult = new ArrayList<Block>();
    processChild(
        localResult, child, AlignmentStrategy.getNullStrategy(), null, Indent.getNoneIndent());
    child = child.getTreeNext();
    Indent childIndent = Indent.getNormalIndent();
    while (child != null) {
      if (child.getElementType() == JavaElementType.SWITCH_LABEL_STATEMENT || isRBrace(child)) {
        result.add(createCaseSectionBlock(localResult, childAlignment, indent, childWrap));
        return child.getTreePrev();
      }

      if (!FormatterUtil.containsWhiteSpacesOnly(child)) {

        if (child.getElementType() == JavaElementType.BLOCK_STATEMENT) {
          childIndent = Indent.getNoneIndent();
        }

        boolean breakOrReturn = isBreakOrReturn(child);
        processChild(localResult, child, AlignmentStrategy.getNullStrategy(), null, childIndent);
        if (breakOrReturn) {
          result.add(createCaseSectionBlock(localResult, childAlignment, indent, childWrap));
          return child;
        }
      }

      child = child.getTreeNext();
    }
    result.add(createCaseSectionBlock(localResult, childAlignment, indent, childWrap));
    return null;
  }