类com.intellij.psi.codeStyle.CommonCodeStyleSettings源码实例Demo

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

源代码1 项目: consulo   文件: IndentCalculator.java

@Nullable
String getIndentString(@Nullable Language language, @Nonnull SemanticEditorPosition currPosition) {
  String baseIndent = getBaseIndent(currPosition);
  Document document = myEditor.getDocument();
  PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(document);
  if (file != null) {
    CommonCodeStyleSettings.IndentOptions fileOptions = CodeStyle.getIndentOptions(file);
    CommonCodeStyleSettings.IndentOptions options =
            !fileOptions.isOverrideLanguageOptions() && language != null && !(language.is(file.getLanguage()) || language.is(Language.ANY)) ? CodeStyle.getLanguageSettings(file, language)
                    .getIndentOptions() : fileOptions;
    if (options != null) {
      return baseIndent + new IndentInfo(0, indentToSize(myIndent, options), 0, false).generateNewWhiteSpace(options);
    }
  }
  return null;
}
 
源代码2 项目: 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 FormatProcessor processor = buildProcessorAndWrapBlocks(model, settings, indentOptions, affectedRange, 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;
}
 
源代码3 项目: Buck-IntelliJ-Plugin   文件: BuckBlock.java

public BuckBlock(@Nullable final BuckBlock parent,
                 @NotNull final ASTNode node,
                 @NotNull CodeStyleSettings settings,
                 @Nullable final Alignment alignment,
                 @NotNull final Indent indent,
                 @Nullable final Wrap wrap) {
  myParent = parent;
  myAlignment = alignment;
  myIndent = indent;
  myNode = node;
  myPsiElement = node.getPsi();
  myWrap = wrap;
  mySettings = settings;

  mySpacingBuilder = BuckFormattingModelBuilder.createSpacingBuilder(settings);

  if (myPsiElement instanceof BuckArrayElements ||
      myPsiElement instanceof BuckRuleBody ||
      myPsiElement instanceof BuckListElements ||
      myPsiElement instanceof BuckObjectElements) {
    myChildWrap = Wrap.createWrap(CommonCodeStyleSettings.WRAP_ALWAYS, true);
  } else {
    myChildWrap = null;
  }
}
 
源代码4 项目: consulo   文件: BlockIndentOptions.java

@Nonnull
public CommonCodeStyleSettings.IndentOptions getIndentOptions(@Nonnull AbstractBlockWrapper block) {
  if (!myIndentOptions.isOverrideLanguageOptions()) {
    final Language language = block.getLanguage();
    if (language != null) {
      final CommonCodeStyleSettings commonSettings = mySettings.getCommonSettings(language);
      if (commonSettings != null) {
        final CommonCodeStyleSettings.IndentOptions result = commonSettings.getIndentOptions();
        if (result != null) {
          return result;
        }
      }
    }
  }
  return myIndentOptions;
}
 

private SpacingBuilder createSpacingBuilder(CodeStyleSettings codeStyleSettings) {
    final CommonCodeStyleSettings commonSettings = codeStyleSettings.getCommonSettings(GLSLLanguage.GLSL_LANGUAGE);

    return new SpacingBuilder(codeStyleSettings, GLSLLanguage.GLSL_LANGUAGE)
            .before(COMMA).spaceIf(commonSettings.SPACE_BEFORE_COMMA)
            .after(COMMA).spaceIf(commonSettings.SPACE_AFTER_COMMA)
            .before(SEMICOLON).none()

            .after(LEFT_BRACKET).none()
            .before(RIGHT_BRACKET).none()

            .after(LEFT_BRACE).spaces(1)
            .before(RIGHT_BRACE).spaces(1)

            .withinPair(LEFT_PAREN, RIGHT_PAREN).spaceIf(commonSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES)

            .around(FLOW_KEYWORDS).spaces(1)

            .before(COMMENT_LINE).spaceIf(commonSettings.LINE_COMMENT_ADD_SPACE)
            ;
}
 
源代码6 项目: intellij-haxe   文件: HaxeFormatterTest.java

public void testWrappingMeth() throws Exception {
  myTestStyleSettings.METHOD_ANNOTATION_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
  myTestStyleSettings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE = true;
  myTestStyleSettings.METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE = true;
  myTestStyleSettings.CALL_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
  myTestStyleSettings.CALL_PARAMETERS_LPAREN_ON_NEXT_LINE = true;
  myTestStyleSettings.CALL_PARAMETERS_RPAREN_ON_NEXT_LINE = true;
  myTestStyleSettings.ELSE_ON_NEW_LINE = true;
  myTestStyleSettings.SPECIAL_ELSE_IF_TREATMENT = true;
  myTestStyleSettings.FOR_STATEMENT_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
  myTestStyleSettings.FOR_STATEMENT_LPAREN_ON_NEXT_LINE = true;
  myTestStyleSettings.FOR_STATEMENT_RPAREN_ON_NEXT_LINE = true;
  myTestStyleSettings.WHILE_ON_NEW_LINE = true;
  myTestStyleSettings.CATCH_ON_NEW_LINE = true;
  myTestStyleSettings.BINARY_OPERATION_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
  myTestStyleSettings.BINARY_OPERATION_SIGN_ON_NEXT_LINE = true;
  myTestStyleSettings.PARENTHESES_EXPRESSION_LPAREN_WRAP = true;
  myTestStyleSettings.PARENTHESES_EXPRESSION_RPAREN_WRAP = true;
  myTestStyleSettings.ASSIGNMENT_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
  myTestStyleSettings.PLACE_ASSIGNMENT_SIGN_ON_NEXT_LINE = true;
  myTestStyleSettings.TERNARY_OPERATION_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
  myTestStyleSettings.TERNARY_OPERATION_SIGNS_ON_NEXT_LINE = true;
  myTestStyleSettings.BLOCK_COMMENT_AT_FIRST_COLUMN = true;
  doTest();
}
 
源代码7 项目: consulo   文件: CoreFormatterUtil.java

/**
 * Calculates indent for the given block and target start offset according to the given indent options.
 *
 * @param options               indent options to use
 * @param block                 target wrapped block
 * @param tokenBlockStartOffset target wrapped block offset
 * @return indent to use for the given parameters
 */
public static IndentData getIndent(CommonCodeStyleSettings.IndentOptions options, AbstractBlockWrapper block, final int tokenBlockStartOffset) {
  final IndentImpl indent = block.getIndent();
  if (indent.getType() == Indent.Type.CONTINUATION) {
    return new IndentData(options.CONTINUATION_INDENT_SIZE);
  }
  if (indent.getType() == Indent.Type.CONTINUATION_WITHOUT_FIRST) {
    if (block.getStartOffset() != block.getParent().getStartOffset() && block.getStartOffset() == tokenBlockStartOffset) {
      return new IndentData(options.CONTINUATION_INDENT_SIZE);
    }
    else {
      return new IndentData(0);
    }
  }
  if (indent.getType() == Indent.Type.LABEL) return new IndentData(options.LABEL_INDENT_SIZE);
  if (indent.getType() == Indent.Type.NONE) return new IndentData(0);
  if (indent.getType() == Indent.Type.SPACES) return new IndentData(indent.getSpaces(), 0);
  return new IndentData(options.INDENT_SIZE);
}
 

public void testSoftWrapsRecalculationOnTabWidthChange() throws IOException {
  // Inspired by IDEA-78616 - the point is to recalculate soft wraps when tab width is changed.
  String text =
          "\t<caret> my text";

  // Build soft wraps cache.
  init(40, text);

  VisualPosition caretPositionBefore = getEditor().getCaretModel().getVisualPosition();

  // Change tab size.
  final CommonCodeStyleSettings.IndentOptions indentOptions = getCurrentCodeStyleSettings().getIndentOptions();
  assertNotNull(indentOptions);
  indentOptions.TAB_SIZE++;

  ((DesktopEditorImpl)getEditor()).reinitSettings();
  assertEquals(
          new VisualPosition(caretPositionBefore.line, caretPositionBefore.column + 1),
          getEditor().getCaretModel().getVisualPosition()
  );
}
 

@NotNull
public static String getCodeStyleIntent(InsertionContext insertionContext) {
  final CodeStyleSettings currentSettings =
      CodeStyleSettingsManager.getSettings(insertionContext.getProject());
  final CommonCodeStyleSettings.IndentOptions indentOptions =
      currentSettings.getIndentOptions(insertionContext.getFile().getFileType());
  return indentOptions.USE_TAB_CHARACTER ?
      "\t" :
      StringUtil.repeatSymbol(' ', indentOptions.INDENT_SIZE);
}
 
源代码10 项目: consulo   文件: WrappingUtil.java

public static WrapType getWrapType(int setting) {
  switch (setting) {
    case CommonCodeStyleSettings.WRAP_ALWAYS:
      return WrapType.ALWAYS;
    case CommonCodeStyleSettings.WRAP_AS_NEEDED:
      return WrapType.NORMAL;
    case CommonCodeStyleSettings.DO_NOT_WRAP:
      return WrapType.NONE;
    default:
      return WrapType.CHOP_DOWN_IF_LONG;
  }
}
 
源代码11 项目: consulo   文件: WhiteSpace.java

public StringBuilder generateWhiteSpace(final CommonCodeStyleSettings.IndentOptions indentOptions,
                                        final int offset,
                                        final IndentInfo indent) {
  final StringBuilder result = new StringBuilder();
  int currentOffset = getStartOffset();
  CharSequence[] lines = getInitialLines();
  int currentLine = 0;
  for (int i = 0; i < lines.length - 1 && currentOffset + lines[i].length() <= offset; i++) {
    result.append(lines[i]);
    currentOffset += lines[i].length();
    result.append(LINE_FEED);
    currentOffset++;
    currentLine++;
    if (currentOffset == offset) {
      break;
    }

  }
  final String newIndentSpaces = indent.generateNewWhiteSpace(indentOptions);
  result.append(newIndentSpaces);
  appendNonWhitespaces(result, lines, currentLine);
  if (currentLine + 1 < lines.length) {
    result.append(LINE_FEED);
    for (int i = currentLine + 1; i < lines.length - 1; i++) {
      result.append(lines[i]);
      result.append(LINE_FEED);
    }
    appendNonWhitespaces(result, lines, lines.length-1);
    result.append(lines[lines.length - 1]);

  }
  return result;
}
 
源代码12 项目: consulo   文件: InitialInfoBuilder.java

@Nonnull
static InitialInfoBuilder prepareToBuildBlocksSequentially(Block root, FormattingDocumentModel model, FormatProcessor.FormatOptions formatOptions, CommonCodeStyleSettings.IndentOptions options, @Nonnull FormattingProgressCallback progressCallback) {
  InitialInfoBuilder builder = new InitialInfoBuilder(root, model, formatOptions.myAffectedRanges, options, formatOptions.myInterestingOffset, progressCallback);
  builder.setCollectAlignmentsInsideFormattingRange(formatOptions.isReformatWithContext());
  builder.buildFrom(root, 0, null, null, null);
  return builder;
}
 

private void run(String test, Consumer<CommonCodeStyleSettings> settings) {
    myFixture.configureByFiles(test + "/Source.proto");
    CodeStyleSettings codeStyleSettings = CodeStyle.getSettings(getProject());
    CommonCodeStyleSettings protoSettings = codeStyleSettings.getCommonSettings(ProtoLanguage.INSTANCE);
    settings.accept(protoSettings);
    WriteCommandAction.writeCommandAction(getProject())
            .run(() -> CodeStyleManager.getInstance(getProject()).reformat(myFixture.getFile()));
    myFixture.checkResultByFile(test + "/Expected.proto");
}
 
源代码14 项目: consulo   文件: FormatterImpl.java

@Nonnull
private static FormatProcessor buildProcessorAndWrapBlocks(final FormattingModel model,
                                                           CodeStyleSettings settings,
                                                           CommonCodeStyleSettings.IndentOptions indentOptions,
                                                           @Nullable TextRange affectedRange,
                                                           int offset) {
  FormattingDocumentModel docModel = model.getDocumentModel();
  Block rootBlock = model.getRootBlock();
  return buildProcessorAndWrapBlocks(docModel, rootBlock, settings, indentOptions, new FormatTextRanges(affectedRange, true), offset);
}
 

/**
 * Create a {@link LookupElementBuilder} for completing the text of a key. Do not use when completing a value.
 *
 * @param completionObject the object to pass to {@link LookupElementBuilder#create(Object)}.
 * @param addLayerOfNesting whether a newline and indent should be added when accepting the completed value - this is used when inserting the value will introduce a level of nesting (i.e. for an
 * object or array type).
 * @return the created {@code LookupElementBuilder}.
 */
private static LookupElementBuilder createKeyLookupElement(@NotNull final Object completionObject, final boolean addLayerOfNesting) {
    return LookupElementBuilder.create(completionObject).withInsertHandler((insertionContext, lookupElement) -> {
        // If the caret is at the end of the line, add in the property colon when completing
        if (insertionContext.getCompletionChar() != ':' && insertionContext.getCompletionChar() != ' ') {
            final Editor editor = insertionContext.getEditor();
            final int offset = editor.getCaretModel().getOffset();
            final int lineNumber = editor.getDocument().getLineNumber(offset);
            final int lineEndOffset = editor.getDocument().getLineEndOffset(lineNumber);
            if (lineEndOffset == offset) {
                final String autocompleteString;
                if (addLayerOfNesting) {
                    // Copy the indentation characters present on this line, and add one additional level of indentation
                    final int lineStartOffset = editor.getDocument().getLineStartOffset(lineNumber);
                    final String lineContent = editor.getDocument().getText().substring(lineStartOffset, lineEndOffset);
                    final int offsetOfContent = lineContent.length() - StringUtil.trimLeading(lineContent).length();
                    final String indentToLine = lineContent.substring(0, offsetOfContent);
                    final CodeStyleSettings currentSettings = CodeStyleSettingsManager.getSettings(insertionContext.getProject());
                    final CommonCodeStyleSettings.IndentOptions indentOptions = currentSettings.getIndentOptions(insertionContext.getFile().getFileType());
                    final String additionalIndent = indentOptions.USE_TAB_CHARACTER ? "\t" : StringUtil.repeatSymbol(' ', indentOptions.INDENT_SIZE);
                    autocompleteString = ":\n" + indentToLine + additionalIndent;
                } else {
                    autocompleteString = ": ";
                }
                EditorModificationUtil.insertStringAtCaret(editor, autocompleteString);
            }
        }
    });
}
 

@Nullable
@Override
public CommonCodeStyleSettings getDefaultCommonSettings() {
    CommonCodeStyleSettings settings = new CommonCodeStyleSettings(getLanguage());
    CommonCodeStyleSettings.IndentOptions indentOptions = settings.initIndentOptions();
    indentOptions.INDENT_SIZE = 2;
    indentOptions.CONTINUATION_INDENT_SIZE = 2;
    indentOptions.TAB_SIZE = 2;
    indentOptions.USE_TAB_CHARACTER = false;

    return settings;
}
 

@Nullable
@Override
public CommonCodeStyleSettings getDefaultCommonSettings() {
  CommonCodeStyleSettings defaultSettings =
      new CommonCodeStyleSettings(ProjectViewLanguage.INSTANCE);
  defaultSettings.LINE_COMMENT_AT_FIRST_COLUMN = false;
  defaultSettings.LINE_COMMENT_ADD_SPACE = true;
  CommonCodeStyleSettings.IndentOptions indentOptions = defaultSettings.initIndentOptions();
  indentOptions.TAB_SIZE = 2;
  indentOptions.INDENT_SIZE = 2;
  indentOptions.CONTINUATION_INDENT_SIZE = 2;
  return defaultSettings;
}
 

@Override
public CommonCodeStyleSettings getDefaultCommonSettings() {
  CommonCodeStyleSettings defaultSettings = new CommonCodeStyleSettings(BuckLanguage.INSTANCE);
  CommonCodeStyleSettings.IndentOptions indentOptions = defaultSettings.initIndentOptions();

  indentOptions.INDENT_SIZE = 2;
  indentOptions.TAB_SIZE = 2;
  indentOptions.CONTINUATION_INDENT_SIZE = 2;

  defaultSettings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true;
  defaultSettings.KEEP_BLANK_LINES_IN_DECLARATIONS = 1;
  defaultSettings.KEEP_BLANK_LINES_IN_CODE = 1;
  defaultSettings.RIGHT_MARGIN = 100;
  return defaultSettings;
}
 

@Override
public CommonCodeStyleSettings getDefaultCommonSettings() {
    CommonCodeStyleSettings commonCodeStyleSettings = new CommonCodeStyleSettings(HaskellLanguage.INSTANCE);
    CommonCodeStyleSettings.IndentOptions indentOptions = commonCodeStyleSettings.initIndentOptions();
    indentOptions.INDENT_SIZE = 4;
    indentOptions.TAB_SIZE = 8;
    return commonCodeStyleSettings;
}
 
源代码20 项目: consulo   文件: InitialInfoBuilderState.java

public boolean childBlockProcessed(@Nonnull Block child, @Nonnull AbstractBlockWrapper wrappedChild, CommonCodeStyleSettings.IndentOptions options) {
  myWrappedChildren.add(wrappedChild);
  previousBlock = child;

  int subBlocksNumber = parentBlock.getSubBlocks().size();
  if (myWrappedChildren.size() > subBlocksNumber) {
    return true;
  }
  else if (myWrappedChildren.size() == subBlocksNumber) {
    setDefaultIndents(myWrappedChildren, options.USE_RELATIVE_INDENTS);
    wrappedBlock.setChildren(myWrappedChildren);
    return true;
  }
  return false;
}
 
源代码21 项目: consulo   文件: FormatterImpl.java

private static FormatProcessor buildProcessorAndWrapBlocks(final FormattingDocumentModel docModel,
                                                           Block rootBlock,
                                                           CodeStyleSettings settings,
                                                           CommonCodeStyleSettings.IndentOptions indentOptions,
                                                           @Nullable FormatTextRanges affectedRanges) {
  return buildProcessorAndWrapBlocks(docModel, rootBlock, settings, indentOptions, affectedRanges, -1);
}
 

@Override
public CommonCodeStyleSettings getDefaultCommonSettings()
{
	CommonCodeStyleSettings settings = new CommonCodeStyleSettings(CSharpLanguage.INSTANCE);
	settings.initIndentOptions();
	return settings;
}
 
源代码23 项目: consulo   文件: FormatterImpl.java

private static FormatProcessor buildProcessorAndWrapBlocks(final FormattingDocumentModel docModel,
                                                           Block rootBlock,
                                                           CodeStyleSettings settings,
                                                           CommonCodeStyleSettings.IndentOptions indentOptions,
                                                           @Nullable FormatTextRanges affectedRanges,
                                                           int interestingOffset) {
  FormatOptions options = new FormatOptions(settings, indentOptions, affectedRanges, interestingOffset);
  FormatProcessor processor = new FormatProcessor(docModel, rootBlock, options, FormattingProgressCallback.EMPTY);
  //noinspection StatementWithEmptyBody
  while (!processor.iteration()) ;
  return processor;
}
 
源代码24 项目: consulo   文件: FormatterImpl.java

@Override
public void adjustLineIndentsForRange(final FormattingModel model, final CodeStyleSettings settings, final CommonCodeStyleSettings.IndentOptions indentOptions, final TextRange rangeToAdjust) {
  disableFormatting();
  try {
    validateModel(model);
    final FormattingDocumentModel documentModel = model.getDocumentModel();
    final Block block = model.getRootBlock();
    final FormatProcessor processor = buildProcessorAndWrapBlocks(documentModel, block, settings, indentOptions, new FormatTextRanges(rangeToAdjust, true));
    LeafBlockWrapper tokenBlock = processor.getFirstTokenBlock();
    while (tokenBlock != null) {
      final WhiteSpace whiteSpace = tokenBlock.getWhiteSpace();
      whiteSpace.setLineFeedsAreReadOnly(true);
      if (!whiteSpace.containsLineFeeds()) {
        whiteSpace.setIsReadOnly(true);
      }
      tokenBlock = tokenBlock.getNextBlock();
    }
    processor.formatWithoutRealModifications();
    processor.performModifications(model);
  }
  catch (FormattingModelInconsistencyException e) {
    LOG.error(e);
  }
  finally {
    enableFormatting();
  }
}
 

private Spacing setBraceSpace(boolean needSpaceSetting,
                              @CommonCodeStyleSettings.BraceStyleConstant int braceStyleSetting,
                              TextRange textRange) {
  final int spaces = needSpaceSetting ? 1 : 0;
  if (braceStyleSetting == CommonCodeStyleSettings.NEXT_LINE_IF_WRAPPED && textRange != null) {
    return Spacing.createDependentLFSpacing(spaces, spaces, textRange, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE);
  }
  else {
    final int lineBreaks = braceStyleSetting == CommonCodeStyleSettings.END_OF_LINE ||
                           braceStyleSetting == CommonCodeStyleSettings.NEXT_LINE_IF_WRAPPED ? 0 : 1;
    return Spacing.createSpacing(spaces, spaces, lineBreaks, false, 0);
  }
}
 
源代码26 项目: intellij-haxe   文件: HaxeFormatterTest.java

protected void defineStyleSettings(CodeStyleSettings tempSettings) {
  myTestStyleSettings = tempSettings.getCommonSettings(HaxeLanguage.INSTANCE);
  myTestStyleSettings.KEEP_BLANK_LINES_IN_CODE = 2;
  myTestStyleSettings.METHOD_BRACE_STYLE = CommonCodeStyleSettings.END_OF_LINE;
  myTestStyleSettings.BRACE_STYLE = CommonCodeStyleSettings.END_OF_LINE;
  myTestStyleSettings.ALIGN_MULTILINE_PARAMETERS = false;
  myTestStyleSettings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS = false;
  myTestStyleSettings.KEEP_FIRST_COLUMN_COMMENT = false;
}
 

@Override
public CommonCodeStyleSettings getDefaultCommonSettings() {
    CommonCodeStyleSettings defaultSettings = new CommonCodeStyleSettings(getLanguage());
    CommonCodeStyleSettings.IndentOptions indentOptions = defaultSettings.initIndentOptions();
    indentOptions.INDENT_SIZE = 4;
    indentOptions.CONTINUATION_INDENT_SIZE = 8;
    indentOptions.TAB_SIZE = 4;

    return defaultSettings;
}
 

@NotNull
@Override
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {
    CommonCodeStyleSettings commonSettings = settings.getCommonSettings(XQueryLanguage.INSTANCE);
    XQueryCodeStyleSettings xQuerySettings = settings.getCustomSettings(XQueryCodeStyleSettings.class);
    final XQueryFormattingBlock block = new XQueryFormattingBlock(element.getNode(), null, null, commonSettings,
            createSpacingBuilder(commonSettings, xQuerySettings, settings));
    FormattingModel result = createFormattingModelForPsiFile(element.getContainingFile(), block, settings);
    return result;
}
 
源代码29 项目: consulo   文件: WhiteSpace.java

/**
 * Applies new end offset to the current object.
 * <p/>
 * Namely, performs the following:
 * <ol>
 *   <li>Checks if new end offset can be applied, return in case of negative answer;</li>
 *   <li>
 *          Processes all new symbols introduced by the new end offset value, calculates number of line feeds,
 *          white spaces and tabulations between them and updates {@link #getLineFeeds() lineFeeds}, {@link #getSpaces() spaces},
 *          {@link #getIndentSpaces() indentSpaces} and {@link #getTotalSpaces() totalSpaces} properties accordingly;
 *    </li>
 * </ol>
 *
 * @param newEndOffset      new end offset value
 * @param model                 formatting model that is used to access to the underlying document text
 * @param options               indent formatting options
 */
public void changeEndOffset(int newEndOffset, FormattingDocumentModel model, CommonCodeStyleSettings.IndentOptions options) {
  final int oldEndOffset = myEnd;
  if (newEndOffset == oldEndOffset) return;
  if (myStart >= newEndOffset) {
    myRangesAssert.assertInvalidRanges(myStart, newEndOffset, model, "some block intersects with whitespace");
  }

  myEnd = newEndOffset;
  TextRange range = new TextRange(myStart, myEnd);
  CharSequence oldText = myInitial;
  myInitial = model.getText(range);

  if (!coveredByBlock(model)) {
    myRangesAssert.assertInvalidRanges(myStart, myEnd, model, "nonempty text is not covered by block");
  }

  if (newEndOffset > oldEndOffset) {
    refreshStateOnEndOffsetIncrease(newEndOffset, oldEndOffset, options.TAB_SIZE);
  } else {
    refreshStateOnEndOffsetDecrease(oldText, newEndOffset, oldEndOffset, options.TAB_SIZE);
  }
  IndentInside indent = IndentInside.getLastLineIndent(myInitial);
  myInitialLastLinesSpaces = indent.whiteSpaces;
  myInitialLastLinesTabs = indent.tabs;

  setFlag(CONTAINS_LF_INITIALLY_MASK, getLineFeeds() > 0);

  final int totalSpaces = getTotalSpaces();
  setFlag(CONTAINS_SPACES_INITIALLY_MASK, totalSpaces > 0);
}
 

private void applyIndentOptions(CommonCodeStyleSettings.IndentOptions indentOptions,
                                String indentSize, String tabWidth, String indentStyle, String filePath) {
    final String calculatedIndentSize = calculateIndentSize(tabWidth, indentSize);
    final String calculatedTabWidth = calculateTabWidth(tabWidth, indentSize);
    if (!calculatedIndentSize.isEmpty()) {
        if (applyIndentSize(indentOptions, calculatedIndentSize)) {
            LOG.debug(Utils.appliedConfigMessage(calculatedIndentSize, indentSizeKey, filePath));
        } else {
            LOG.warn(Utils.invalidConfigMessage(calculatedIndentSize, indentSizeKey, filePath));
        }
    }
    if (!calculatedTabWidth.isEmpty()) {
        if (applyTabWidth(indentOptions, calculatedTabWidth)) {
            LOG.debug(Utils.appliedConfigMessage(calculatedTabWidth, tabWidthKey, filePath));
        } else {
            LOG.warn(Utils.invalidConfigMessage(calculatedTabWidth, tabWidthKey, filePath));
        }
    }
    if (!indentStyle.isEmpty()) {
        if (applyIndentStyle(indentOptions, indentStyle)) {
            LOG.debug(Utils.appliedConfigMessage(indentStyle, indentStyleKey, filePath));

        } else {
            LOG.warn(Utils.invalidConfigMessage(indentStyle, indentStyleKey, filePath));
        }
    }
}
 
 类所在包
 同包方法