类com.intellij.psi.formatter.common.AbstractBlock源码实例Demo

下面列出了怎么用com.intellij.psi.formatter.common.AbstractBlock的API类实例代码及写法,或者点击链接到github查看源代码。

@NotNull
private List<Block> buildBlocks() {
    List<Block> list = this.getOriginal().getSubBlocks();
    if (list.isEmpty()) {

        return AbstractBlock.EMPTY;
    } else {
        ArrayList<Block> result = new ArrayList<>(list.size());
        Iterator var3 = list.iterator();

        while(var3.hasNext()) {
            Block block = (Block)var3.next();
            if (block.getTextRange().intersects(this.myRange)) {
                result.add(new InjectedLanguageBlockWrapper(block, this.myOffset, this.myRange, null, this.getLanguage()));
            }
        }

        return result;
    }
}
 
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;
}
 
protected AbstractBlock createDummyBlock(final ASTNode node) {
  return new AbstractBlock(node, Wrap.createWrap(WrapType.NONE, false), Alignment.createAlignment()) {
    @Override
    protected List<Block> buildChildren() {
      return Collections.emptyList();
    }

    @Override
    public Spacing getSpacing(final Block child1, @Nonnull final Block child2) {
      return Spacing.getReadOnlySpacing();
    }

    @Override
    public boolean isLeaf() {
      return true;
    }
  };
}
 
源代码4 项目: intellij-csv-validator   文件: CsvFormatHelper.java
public static boolean isQuotedField(@Nullable CsvBlock block) {
    if (block != null && block.getNode().getElementType() == CsvTypes.FIELD) {
        List<Block> subBlocks = block.buildChildren();
        if (subBlocks.size() > 0) {
            AbstractBlock abstractBlock = (AbstractBlock) subBlocks.get(0);
            return abstractBlock.getNode().getElementType() == CsvTypes.QUOTE;
        }
    }
    return false;
}
 
@Override
@Nonnull
public FormattingModel createModel(final PsiElement element, final CodeStyleSettings settings) {
  if (element instanceof PsiFile) {
    final FileViewProvider viewProvider = ((PsiFile)element).getViewProvider();
    if (viewProvider instanceof TemplateLanguageFileViewProvider) {
      final Language language = ((TemplateLanguageFileViewProvider)viewProvider).getTemplateDataLanguage();
      FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forLanguage(language);
      if (builder != null) {
        return builder.createModel(viewProvider.getPsi(language), settings);
      }
    }
  }

  final PsiFile file = element.getContainingFile();
  return new DocumentBasedFormattingModel(new AbstractBlock(element.getNode(), Wrap.createWrap(WrapType.NONE, false), Alignment.createAlignment()) {
    @Override
    protected List<Block> buildChildren() {
      return Collections.emptyList();
    }

    @Override
    public Spacing getSpacing(final Block child1, @Nonnull final Block child2) {
      return Spacing.getReadOnlySpacing();
    }

    @Override
    public boolean isLeaf() {
      return true;
    }
  }, element.getProject(), settings, file.getFileType(), file);
}
 
@Override
@Nonnull
public List<Block> getSubBlocks() {
  return AbstractBlock.EMPTY;
}
 
 类所在包
 类方法
 同包方法