Java 类com.intellij.psi.formatter.PsiBasedFormattingModel 实例源码

项目:intellij-ce-playground    文件:FormatterImpl.java   
@Override
public int adjustLineIndent(final FormattingModel model,
                            final CodeStyleSettings settings,
                            final CommonCodeStyleSettings.IndentOptions indentOptions,
                            final int offset,
                            final TextRange affectedRange) throws IncorrectOperationException {
  disableFormatting();
  try {
    validateModel(model);
    if (model instanceof PsiBasedFormattingModel) {
      ((PsiBasedFormattingModel)model).canModifyAllWhiteSpaces();
    }
    final FormattingDocumentModel documentModel = model.getDocumentModel();
    final Block block = model.getRootBlock();
    final FormatProcessor processor = buildProcessorAndWrapBlocks(
      documentModel, block, settings, indentOptions, new FormatTextRanges(affectedRange, true), offset
    );

    final LeafBlockWrapper blockAfterOffset = processor.getBlockAtOrAfter(offset);

    if (blockAfterOffset != null && blockAfterOffset.contains(offset)) {
      return offset;
    }

    WhiteSpace whiteSpace = blockAfterOffset != null ? blockAfterOffset.getWhiteSpace() : processor.getLastWhiteSpace();
    return adjustLineIndent(offset, documentModel, processor, indentOptions, model, whiteSpace,
                            blockAfterOffset != null ? blockAfterOffset.getNode() : null);
  }
  catch (FormattingModelInconsistencyException e) {
    LOG.error(e);
  }
  finally {
    enableFormatting();
  }
  return offset;
}
项目:tools-idea    文件:FormatterImpl.java   
@Override
public int adjustLineIndent(final FormattingModel model,
                            final CodeStyleSettings settings,
                            final CommonCodeStyleSettings.IndentOptions indentOptions,
                            final int offset,
                            final TextRange affectedRange) throws IncorrectOperationException {
  disableFormatting();
  if (model instanceof PsiBasedFormattingModel) {
    ((PsiBasedFormattingModel)model).canModifyAllWhiteSpaces();
  }
  try {
    final FormattingDocumentModel documentModel = model.getDocumentModel();
    final Block block = model.getRootBlock();
    final FormatProcessor processor = buildProcessorAndWrapBlocks(
      documentModel, block, settings, indentOptions, new FormatTextRanges(affectedRange, true), offset
    );

    final LeafBlockWrapper blockAfterOffset = processor.getBlockAfter(offset);

    if (blockAfterOffset != null && blockAfterOffset.contains(offset)) {
      return offset;
    }

    WhiteSpace whiteSpace = blockAfterOffset != null ? blockAfterOffset.getWhiteSpace() : processor.getLastWhiteSpace();
    return adjustLineIndent(offset, documentModel, processor, indentOptions, model, whiteSpace);
  }
  finally {
    enableFormatting();
  }
}
项目:consulo-csharp    文件:CSharpFormattingModelBuilder.java   
@NotNull
@Override
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings)
{
    final PsiFile file = element.getContainingFile();
    FormattingDocumentModelImpl model = FormattingDocumentModelImpl.createOn(element.getContainingFile());
    Block rootBlock = new CSharpFormattingBlock(file.getNode(), null, null, settings);
    return new PsiBasedFormattingModel(file, rootBlock, model);
}
项目:consulo    文件:FormatterImpl.java   
@Override
public int adjustLineIndent(final FormattingModel model,
                            final CodeStyleSettings settings,
                            final CommonCodeStyleSettings.IndentOptions indentOptions,
                            final int offset,
                            final TextRange affectedRange) throws IncorrectOperationException {
  disableFormatting();
  try {
    validateModel(model);
    if (model instanceof PsiBasedFormattingModel) {
      ((PsiBasedFormattingModel)model).canModifyAllWhiteSpaces();
    }
    final FormattingDocumentModel documentModel = model.getDocumentModel();
    final Block block = model.getRootBlock();
    final FormatProcessor processor = buildProcessorAndWrapBlocks(
            documentModel, block, settings, indentOptions, new FormatTextRanges(affectedRange, true), offset
    );

    final LeafBlockWrapper blockAfterOffset = processor.getBlockRangesMap().getBlockAtOrAfter(offset);

    if (blockAfterOffset != null && blockAfterOffset.contains(offset)) {
      return offset;
    }

    WhiteSpace whiteSpace = blockAfterOffset != null ? blockAfterOffset.getWhiteSpace() : processor.getLastWhiteSpace();
    return adjustLineIndent(offset, documentModel, processor, indentOptions, model, whiteSpace,
                            blockAfterOffset != null ? blockAfterOffset.getNode() : null);
  }
  catch (FormattingModelInconsistencyException e) {
    LOG.error(e);
  }
  finally {
    enableFormatting();
  }
  return offset;
}
项目:consulo-css    文件:CssFormattingModelBuilder.java   
@NotNull
@Override
public FormattingModel createModel(PsiElement element, CodeStyleSettings codeStyleSettings)
{
    final PsiFile file = element.getContainingFile();
    FormattingDocumentModelImpl model = FormattingDocumentModelImpl.createOn(element.getContainingFile());
    Block rootBlock = new CssFormattingBlock(element.getNode(), null, null);
    return new PsiBasedFormattingModel(file, rootBlock, model);
}
项目:intellij-ce-playground    文件:FormatterImpl.java   
@Override
public FormattingModel createFormattingModelForPsiFile(final PsiFile file,
                                                       @NotNull final Block rootBlock,
                                                       final CodeStyleSettings settings) {
  return new PsiBasedFormattingModel(file, rootBlock, FormattingDocumentModelImpl.createOn(file));
}
项目:tools-idea    文件:FormatterImpl.java   
@Override
public FormattingModel createFormattingModelForPsiFile(final PsiFile file,
                                                       @NotNull final Block rootBlock,
                                                       final CodeStyleSettings settings) {
  return new PsiBasedFormattingModel(file, rootBlock, FormattingDocumentModelImpl.createOn(file));
}
项目:consulo    文件:FormatterImpl.java   
@Override
public FormattingModel createFormattingModelForPsiFile(final PsiFile file,
                                                       @Nonnull final Block rootBlock,
                                                       final CodeStyleSettings settings) {
  return new PsiBasedFormattingModel(file, rootBlock, FormattingDocumentModelImpl.createOn(file));
}