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

项目:intellij-ce-playground    文件:SyntheticCodeBlock.java   
public String toString() {
  ASTNode treeNode = null;
  Block child = mySubBlocks.get(0);
  while (treeNode == null) {
    if (child instanceof AbstractBlock) {
      treeNode = ((AbstractBlock)child).getNode();
    }
    else if (child instanceof SyntheticCodeBlock) {
      child = ((SyntheticCodeBlock)child).mySubBlocks.get(0);
    }
    else {
      break;
    }
  }
  final TextRange textRange = getTextRange();
  if (treeNode != null) {
    PsiElement psi = treeNode.getPsi();
    if (psi != null) {
      PsiFile file = psi.getContainingFile();
      if (file != null) {
        return file.getText().subSequence(textRange.getStartOffset(), textRange.getEndOffset()) + " " + textRange;
      }
    }
  }
  return getClass().getName() + ": " + textRange;
}
项目:intellij-ce-playground    文件:FormatterBasedLineIndentInfoBuilder.java   
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;
}
项目:intellij-ce-playground    文件:TemplateLanguageFormattingModelBuilder.java   
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, @NotNull final Block child2) {
      return Spacing.getReadOnlySpacing();
    }

    @Override
    public boolean isLeaf() {
      return true;
    }
  };
}
项目:tools-idea    文件:SyntheticCodeBlock.java   
public String toString() {
  ASTNode treeNode = null;
  Block child = mySubBlocks.get(0);
  while (treeNode == null) {
    if (child instanceof AbstractBlock) {
      treeNode = ((AbstractBlock)child).getNode();
    }
    else if (child instanceof SyntheticCodeBlock) {
      child = ((SyntheticCodeBlock)child).mySubBlocks.get(0);
    }
    else {
      break;
    }
  }
  final TextRange textRange = getTextRange();
  if (treeNode != null) {
    PsiElement psi = treeNode.getPsi();
    if (psi != null) {
      PsiFile file = psi.getContainingFile();
      if (file != null) {
        return file.getText().subSequence(textRange.getStartOffset(), textRange.getEndOffset()) + " " + textRange;
      }
    }
  }
  return getClass().getName() + ": " + textRange;
}
项目:tools-idea    文件:TemplateLanguageFormattingModelBuilder.java   
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, @NotNull final Block child2) {
      return Spacing.getReadOnlySpacing();
    }

    @Override
    public boolean isLeaf() {
      return true;
    }
  };
}
项目:consulo    文件:FormatterBasedLineIndentInfoBuilder.java   
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;
}
项目:consulo    文件:TemplateLanguageFormattingModelBuilder.java   
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;
    }
  };
}
项目:consulo-java    文件:AbstractJavaBlock.java   
protected boolean isAfter(final int newChildIndex, @NotNull final IElementType[] elementTypes)
{
    if(newChildIndex == 0)
    {
        return false;
    }
    final Block previousBlock = getSubBlocks().get(newChildIndex - 1);
    if(!(previousBlock instanceof AbstractBlock))
    {
        return false;
    }
    final IElementType previousElementType = ((AbstractBlock) previousBlock).getNode().getElementType();
    for(IElementType elementType : elementTypes)
    {
        if(previousElementType == elementType)
        {
            return true;
        }
    }
    return false;
}
项目: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;
}
项目:intellij-ce-playground    文件:AbstractJavaBlock.java   
protected boolean isAfter(final int newChildIndex, @NotNull final IElementType[] elementTypes) {
  if (newChildIndex == 0) return false;
  final Block previousBlock = getSubBlocks().get(newChildIndex - 1);
  if (!(previousBlock instanceof AbstractBlock)) return false;
  final IElementType previousElementType = ((AbstractBlock)previousBlock).getNode().getElementType();
  for (IElementType elementType : elementTypes) {
    if (previousElementType == elementType) return true;
  }
  return false;
}
项目:intellij-ce-playground    文件:CodeBlockBlock.java   
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;
}
项目:intellij-ce-playground    文件:SimpleTemplateLanguageFormattingModelBuilder.java   
@Override
@NotNull
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, @NotNull final Block child2) {
      return Spacing.getReadOnlySpacing();
    }

    @Override
    public boolean isLeaf() {
      return true;
    }
  }, element.getProject(), settings, file.getFileType(), file);
}
项目:intellij-ce-playground    文件:AbstractSyntheticBlock.java   
private ASTNode getFirstNode(final List<Block> subBlocks) {
  LOG.assertTrue(!subBlocks.isEmpty());
  final Block firstBlock = subBlocks.get(0);
  if (firstBlock instanceof AbstractBlock) {
    return ((AbstractBlock)firstBlock).getNode();
  }
  else {
    return getFirstNode(firstBlock.getSubBlocks());
  }
}
项目:intellij-ce-playground    文件:AbstractSyntheticBlock.java   
private ASTNode getLastNode(final List<Block> subBlocks) {
  LOG.assertTrue(!subBlocks.isEmpty());
  final Block lastBlock = subBlocks.get(subBlocks.size() - 1);
  if (lastBlock instanceof AbstractBlock) {
    return ((AbstractBlock)lastBlock).getNode();
  }
  else {
    return getLastNode(lastBlock.getSubBlocks());
  }
}
项目:intellij-ce-playground    文件:XmlBlock.java   
@Override
public Spacing getSpacing(Block child1, @NotNull Block child2) {
  if (!(child1 instanceof AbstractBlock) || !(child2 instanceof AbstractBlock)) {
    return null;
  }

  final IElementType elementType = myNode.getElementType();
  final ASTNode node1 = ((AbstractBlock)child1).getNode();
  final IElementType type1 = node1.getElementType();
  final ASTNode node2 = ((AbstractBlock)child2).getNode();
  final IElementType type2 = node2.getElementType();

  if ((isXmlTag(node2) || type2 == XmlTokenType.XML_END_TAG_START || type2 == XmlElementType.XML_TEXT) && myXmlFormattingPolicy
    .getShouldKeepWhiteSpaces()) {
    return Spacing.getReadOnlySpacing();
  }

  if (elementType == XmlElementType.XML_TEXT) {
    return getSpacesInsideText(type1, type2);

  }
  else if (elementType == XmlElementType.XML_ATTRIBUTE) {
    return getSpacesInsideAttribute(type1, type2);
  }

  if (type1 == XmlElementType.XML_PROLOG) {
    return createDefaultSpace(true, false);
  }

  if (elementType == XmlElementType.XML_DOCTYPE) {
    return createDefaultSpace(true, false);
  }

  return createDefaultSpace(false, false);
}
项目:tools-idea    文件:AbstractJavaBlock.java   
protected boolean isAfter(final int newChildIndex, @NotNull final IElementType[] elementTypes) {
  if (newChildIndex == 0) return false;
  final Block previousBlock = getSubBlocks().get(newChildIndex - 1);
  if (!(previousBlock instanceof AbstractBlock)) return false;
  final IElementType previousElementType = ((AbstractBlock)previousBlock).getNode().getElementType();
  for (IElementType elementType : elementTypes) {
    if (previousElementType == elementType) return true;
  }
  return false;
}
项目:tools-idea    文件:CodeBlockBlock.java   
private SyntheticCodeBlock createCaseSectionBlock(final ArrayList<Block> localResult, final Alignment childAlignment, final Indent indent,
                                                  final Wrap childWrap) {
  final SyntheticCodeBlock result = new SyntheticCodeBlock(localResult, childAlignment, getSettings(), 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;
}
项目:tools-idea    文件:SimpleTemplateLanguageFormattingModelBuilder.java   
@Override
@NotNull
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, @NotNull final Block child2) {
      return Spacing.getReadOnlySpacing();
    }

    @Override
    public boolean isLeaf() {
      return true;
    }
  }, element.getProject(), settings, file.getFileType(), file);
}
项目:tools-idea    文件:AbstractSyntheticBlock.java   
private ASTNode getFirstNode(final List<Block> subBlocks) {
  LOG.assertTrue(!subBlocks.isEmpty());
  final Block firstBlock = subBlocks.get(0);
  if (firstBlock instanceof AbstractBlock) {
    return ((AbstractBlock)firstBlock).getNode();
  }
  else {
    return getFirstNode(firstBlock.getSubBlocks());
  }
}
项目:tools-idea    文件:AbstractSyntheticBlock.java   
private ASTNode getLastNode(final List<Block> subBlocks) {
  LOG.assertTrue(!subBlocks.isEmpty());
  final Block lastBlock = subBlocks.get(subBlocks.size() - 1);
  if (lastBlock instanceof AbstractBlock) {
    return ((AbstractBlock)lastBlock).getNode();
  }
  else {
    return getLastNode(lastBlock.getSubBlocks());
  }
}
项目:tools-idea    文件:XmlBlock.java   
public Spacing getSpacing(Block child1, @NotNull Block child2) {
  if (!(child1 instanceof AbstractBlock) || !(child2 instanceof AbstractBlock)) {
    return null;
  }

  final IElementType elementType = myNode.getElementType();
  final ASTNode node1 = ((AbstractBlock)child1).getNode();
  final IElementType type1 = node1.getElementType();
  final ASTNode node2 = ((AbstractBlock)child2).getNode();
  final IElementType type2 = node2.getElementType();

  if ((isXmlTag(node2) || type2 == XmlElementType.XML_END_TAG_START || type2 == XmlElementType.XML_TEXT) && myXmlFormattingPolicy
    .getShouldKeepWhiteSpaces()) {
    return Spacing.getReadOnlySpacing();
  }

  if (elementType == XmlElementType.XML_TEXT) {
    return getSpacesInsideText(type1, type2);

  }
  else if (elementType == XmlElementType.XML_ATTRIBUTE) {
    return getSpacesInsideAttribute(type1, type2);
  }

  if (type1 == XmlElementType.XML_PROLOG) {
    return createDefaultSpace(true, false);
  }

  if (elementType == XmlElementType.XML_DOCTYPE) {
    return createDefaultSpace(true, false);
  }

  return createDefaultSpace(false, false);
}
项目:consulo    文件:SimpleTemplateLanguageFormattingModelBuilder.java   
@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);
}
项目:consulo-xml    文件:AbstractSyntheticBlock.java   
private ASTNode getFirstNode(final List<Block> subBlocks) {
  LOG.assertTrue(!subBlocks.isEmpty());
  final Block firstBlock = subBlocks.get(0);
  if (firstBlock instanceof AbstractBlock) {
    return ((AbstractBlock)firstBlock).getNode();
  }
  else {
    return getFirstNode(firstBlock.getSubBlocks());
  }
}
项目:consulo-xml    文件:AbstractSyntheticBlock.java   
private ASTNode getLastNode(final List<Block> subBlocks) {
  LOG.assertTrue(!subBlocks.isEmpty());
  final Block lastBlock = subBlocks.get(subBlocks.size() - 1);
  if (lastBlock instanceof AbstractBlock) {
    return ((AbstractBlock)lastBlock).getNode();
  }
  else {
    return getLastNode(lastBlock.getSubBlocks());
  }
}
项目:consulo-xml    文件:XmlBlock.java   
public Spacing getSpacing(Block child1, @NotNull Block child2) {
  if (!(child1 instanceof AbstractBlock) || !(child2 instanceof AbstractBlock)) {
    return null;
  }

  final IElementType elementType = myNode.getElementType();
  final ASTNode node1 = ((AbstractBlock)child1).getNode();
  final IElementType type1 = node1.getElementType();
  final ASTNode node2 = ((AbstractBlock)child2).getNode();
  final IElementType type2 = node2.getElementType();

  if ((isXmlTag(node2) || type2 == XmlElementType.XML_END_TAG_START || type2 == XmlElementType.XML_TEXT) && myXmlFormattingPolicy
    .getShouldKeepWhiteSpaces()) {
    return Spacing.getReadOnlySpacing();
  }

  if (elementType == XmlElementType.XML_TEXT) {
    return getSpacesInsideText(type1, type2);

  }
  else if (elementType == XmlElementType.XML_ATTRIBUTE) {
    return getSpacesInsideAttribute(type1, type2);
  }

  if (type1 == XmlElementType.XML_PROLOG) {
    return createDefaultSpace(true, false);
  }

  if (elementType == XmlElementType.XML_DOCTYPE) {
    return createDefaultSpace(true, false);
  }

  return createDefaultSpace(false, false);
}
项目:consulo-java    文件:SyntheticCodeBlock.java   
public String toString()
{
    ASTNode treeNode = null;
    Block child = mySubBlocks.get(0);
    while(treeNode == null)
    {
        if(child instanceof AbstractBlock)
        {
            treeNode = ((AbstractBlock) child).getNode();
        }
        else if(child instanceof SyntheticCodeBlock)
        {
            child = ((SyntheticCodeBlock) child).mySubBlocks.get(0);
        }
        else
        {
            break;
        }
    }
    final TextRange textRange = getTextRange();
    if(treeNode != null)
    {
        PsiElement psi = treeNode.getPsi();
        if(psi != null)
        {
            PsiFile file = psi.getContainingFile();
            if(file != null)
            {
                return file.getText().subSequence(textRange.getStartOffset(), textRange.getEndOffset()) + " " + textRange;
            }
        }
    }
    return getClass().getName() + ": " + textRange;
}
项目:consulo-java    文件:CodeBlockBlock.java   
private SyntheticCodeBlock createCaseSectionBlock(final List<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;
}
项目:intellij-ce-playground    文件:DataLanguageBlockFragmentWrapper.java   
@Override
@NotNull
public List<Block> getSubBlocks() {
  return AbstractBlock.EMPTY;
}
项目:tools-idea    文件:DataLanguageBlockFragmentWrapper.java   
@Override
@NotNull
public List<Block> getSubBlocks() {
  return AbstractBlock.EMPTY;
}
项目:consulo    文件:DataLanguageBlockFragmentWrapper.java   
@Override
@Nonnull
public List<Block> getSubBlocks() {
  return AbstractBlock.EMPTY;
}