Java Code Examples for com.intellij.formatting.Indent#Type

The following examples show how to use com.intellij.formatting.Indent#Type . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FormatterBasedLineIndentInfoBuilder.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean hasNormalIndent(Block block) {
  final TextRange range = block.getTextRange();
  final int startOffset = range.getStartOffset();

  List<Indent.Type> allIndents = getIndentOnStartOffset(block, range, startOffset);

  if (hasOnlyNormalOrNoneIndents(allIndents)) {
    int normalIndents = ContainerUtil.filter(allIndents, new Condition<Indent.Type>() {
      @Override
      public boolean value(Indent.Type type) {
        return type == Indent.Type.NORMAL;
      }
    }).size();
    return normalIndents < 2;
  }

  return false;
}
 
Example 2
Source File: FormatterBasedLineIndentInfoBuilder.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean hasOnlyNormalOrNoneIndents(List<Indent.Type> indents) {
  Indent.Type outerMostIndent = indents.get(0);
  if (outerMostIndent != Indent.Type.NONE && outerMostIndent != Indent.Type.NORMAL) {
    return false;
  }

  List<Indent.Type> innerIndents = indents.subList(1, indents.size());
  for (Indent.Type indent : innerIndents) {
    if (indent != Indent.Type.NONE && indent != Indent.Type.NORMAL
        && indent != Indent.Type.CONTINUATION_WITHOUT_FIRST) {
      //continuation without first here because it is CONTINUATION only if it's owner is not the first child
      return false;
    }
  }

  return true;
}
 
Example 3
Source File: FormatterBasedLineIndentInfoBuilder.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static List<Indent.Type> getIndentOnStartOffset(Block block, TextRange range, int startOffset) {
  List<Indent.Type> indentsOnStartOffset = new ArrayList<Indent.Type>();

  while (block != null && range.getStartOffset() == startOffset) {
    Indent.Type type = block.getIndent() != null ? block.getIndent().getType() : Indent.Type.CONTINUATION_WITHOUT_FIRST;
    indentsOnStartOffset.add(type);

    if (block instanceof AbstractBlock) {
      ((AbstractBlock)block).setBuildIndentsOnly(true);
    }
    List<Block> subBlocks = block.getSubBlocks();
    block = subBlocks.isEmpty() ? null : subBlocks.get(0);
  }

  return indentsOnStartOffset;
}