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

项目:intellij-ce-playground    文件:GroovySpacingProcessorBasic.java   
@NotNull
static Spacing createDependentSpacingForClosure(@NotNull CommonCodeStyleSettings settings,
                                                @NotNull GroovyCodeStyleSettings groovySettings,
                                                @NotNull GrClosableBlock closure,
                                                final boolean forArrow) {
  boolean spaceWithinBraces = closure.getParent() instanceof GrStringInjection
                              ? groovySettings.SPACE_WITHIN_GSTRING_INJECTION_BRACES
                              : settings.SPACE_WITHIN_BRACES;
  GrStatement[] statements = closure.getStatements();
  if (statements.length > 0) {
    final PsiElement startElem = forArrow ? statements[0] : closure;
    int start = startElem.getTextRange().getStartOffset();
    int end = statements[statements.length - 1].getTextRange().getEndOffset();
    TextRange range = new TextRange(start, end);

    int minSpaces = spaceWithinBraces || forArrow ? 1 : 0;
    int maxSpaces = spaceWithinBraces || forArrow ? 1 : 0;
    return Spacing.createDependentLFSpacing(minSpaces, maxSpaces, range, settings.KEEP_LINE_BREAKS, settings.KEEP_BLANK_LINES_IN_CODE);
  }
  return spaceWithinBraces || forArrow ? COMMON_SPACING : NO_SPACING_WITH_NEWLINE;
}
项目:intellij-ce-playground    文件:SettingsImpl.java   
private void reinitDocumentIndentOptions() {
  if (myEditor == null) return;
  final Project project = myEditor.getProject();
  final DocumentEx document = myEditor.getDocument();

  if (project == null || project.isDisposed()) return;

  final PsiDocumentManager psiManager = PsiDocumentManager.getInstance(project);
  final PsiFile file = psiManager.getPsiFile(document);
  if (file == null) return;

  CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(project).getCurrentSettings();
  CommonCodeStyleSettings.IndentOptions options = settings.getIndentOptionsByFile(file);

  if (CodeStyleSettings.isRecalculateForCommittedDocument(options)) {
    PsiDocumentManager.getInstance(project).performForCommittedDocument(document, new Runnable() {
      @Override
      public void run() {
        CodeStyleSettingsManager.updateDocumentIndentOptions(project, document);
      }
    });
  }
  else {
    CodeStyleSettingsManager.updateDocumentIndentOptions(project, document);
  }
}
项目:intellij-ce-playground    文件:CodeStyleHtmlPanel.java   
@Override
public void apply(CodeStyleSettings settings) {
  settings.HTML_KEEP_BLANK_LINES = getIntValue(myKeepBlankLines);
  settings.HTML_ATTRIBUTE_WRAP = ourWrappings[myWrapAttributes.getSelectedIndex()];
  settings.HTML_TEXT_WRAP = myWrapText.isSelected() ? CommonCodeStyleSettings.WRAP_AS_NEEDED : CommonCodeStyleSettings.DO_NOT_WRAP;
  settings.HTML_SPACE_INSIDE_EMPTY_TAG = mySpaceInEmptyTag.isSelected();
  settings.HTML_ALIGN_ATTRIBUTES = myAlignAttributes.isSelected();
  settings.HTML_ALIGN_TEXT = myAlignText.isSelected();
  settings.HTML_KEEP_WHITESPACES = myKeepWhiteSpaces.isSelected();
  settings.HTML_SPACE_AROUND_EQUALITY_IN_ATTRINUTE = mySpacesAroundEquality.isSelected();
  settings.HTML_SPACE_AFTER_TAG_NAME = mySpacesAroundTagName.isSelected();

  settings.HTML_ELEMENTS_TO_INSERT_NEW_LINE_BEFORE = myInsertNewLineTagNames.getText();
  settings.HTML_ELEMENTS_TO_REMOVE_NEW_LINE_BEFORE = myRemoveNewLineTagNames.getText();
  settings.HTML_DO_NOT_INDENT_CHILDREN_OF = myDoNotAlignChildrenTagNames.getText();
  settings.HTML_DO_NOT_ALIGN_CHILDREN_OF_MIN_LINES = getIntValue(myDoNotAlignChildrenMinSize);
  settings.HTML_INLINE_ELEMENTS = myInlineElementsTagNames.getText();
  settings.HTML_DONT_ADD_BREAKS_IF_INLINE_CONTENT = myDontBreakIfInlineContent.getText();
  settings.HTML_KEEP_WHITESPACES_INSIDE = myKeepWhiteSpacesTagNames.getText();
  settings.HTML_KEEP_LINE_BREAKS = myShouldKeepBlankLines.isSelected();
  settings.HTML_KEEP_LINE_BREAKS_IN_TEXT = myShouldKeepLineBreaksInText.isSelected();
  myRightMarginForm.apply(settings);
}
项目:intellij-ce-playground    文件:PyWrapTest.java   
public void testWrapRightMargin() {
  final CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(myFixture.getProject()).getCurrentSettings();
  final CommonCodeStyleSettings pythonSettings = settings.getCommonSettings(PythonLanguage.getInstance());
  int oldValue = pythonSettings.RIGHT_MARGIN;
  boolean oldMarginValue = settings.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN;
  pythonSettings.RIGHT_MARGIN = 100;
  settings.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN = true;
  try {
    final String testName = "wrap/" + getTestName(true);
    myFixture.configureByFile(testName + ".py");
    for (int i = 0; i != 45; ++i) {
      myFixture.type(' ');
    }
    myFixture.checkResultByFile(testName + ".after.py");
  }
  finally {
    pythonSettings.RIGHT_MARGIN = oldValue;
    settings.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN = oldMarginValue;
  }
}
项目:intellij-ce-playground    文件:JavaFormatterWrapTest.java   
@SuppressWarnings("SpellCheckingInspection")
public void testEnumConstantsWrapping() {
  // Inspired by IDEA-54667
  getSettings().ENUM_CONSTANTS_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
  getSettings().RIGHT_MARGIN = 80;

  // Don't expect the constants to be placed on new line.
  doTextTest(
    "enum Test {FIRST, SECOND}",
    "enum Test {FIRST, SECOND}"
  );

  // Expect not only enum constants to be wrapped but line break inside enum-level curly braces as well.
  doTextTest(
    "enum Test {FIRST, SECOND, THIIIIIIIIIIIIIIIIIRRDDDDDDDDDDDDDD, FOURTHHHHHHHHHHHHHHHH}",

    "enum Test {\n" +
    "    FIRST, SECOND, THIIIIIIIIIIIIIIIIIRRDDDDDDDDDDDDDD, FOURTHHHHHHHHHHHHHHHH\n" +
    "}"
  );
}
项目:intellij-ce-playground    文件:JavaFormatterWrapTest.java   
public void testResourceListWrap() {
  getSettings().KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = true;
  getSettings().RIGHT_MARGIN = 40;
  getSettings().RESOURCE_LIST_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
  doMethodTest("try (MyResource r1 = null; MyResource r2 = null) { }",
               "try (MyResource r1 = null;\n" +
               "     MyResource r2 = null) { }");

  getSettings().RESOURCE_LIST_LPAREN_ON_NEXT_LINE = true;
  getSettings().RESOURCE_LIST_RPAREN_ON_NEXT_LINE = true;
  doMethodTest("try (MyResource r1 = null; MyResource r2 = null) { }",
               "try (\n" +
               "        MyResource r1 = null;\n" +
               "        MyResource r2 = null\n" +
               ") { }");
}
项目:intellij-ce-playground    文件:JavaFormatterTest.java   
public void testSCR1615() throws Exception {
  getSettings().CLASS_BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE_SHIFTED;
  getSettings().METHOD_BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE_SHIFTED;
  getSettings().BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE_SHIFTED;

  doTextTest(
    "public class ZZZZ \n" +
    "   { \n" +
    "   public ZZZZ() \n" +
    "      { \n" +
    "      if (a){\n" +
    "foo();}\n" +
    "      } \n" +
    "   }",
    "public class ZZZZ\n" +
    "    {\n" +
    "    public ZZZZ()\n" +
    "        {\n" +
    "        if (a)\n" +
    "            {\n" +
    "            foo();\n" +
    "            }\n" +
    "        }\n" +
    "    }");
}
项目:intellij-ce-playground    文件:JsonEditingTest.java   
private void doEnterTestForWeb11600() {
  final JsonCodeStyleSettings settings = getCustomCodeStyleSettings();
  final CommonCodeStyleSettings.IndentOptions indentOptions = getIndentOptions();

  final int oldPropertyAlignment = settings.PROPERTY_ALIGNMENT;
  final int oldIndentSize = indentOptions.INDENT_SIZE;
  settings.PROPERTY_ALIGNMENT = JsonCodeStyleSettings.ALIGN_PROPERTY_ON_VALUE;
  indentOptions.INDENT_SIZE = 4;
  try {
    doTest("\n");
  }
  finally {
    indentOptions.INDENT_SIZE = oldIndentSize;
    settings.PROPERTY_ALIGNMENT = oldPropertyAlignment;
  }
}
项目:intellij-ce-playground    文件:JavaFormatterTest.java   
public void testSCR1703() throws Exception {
    getSettings().BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE;
    doTextTest("class Foo{\n" +
               "    void foo() {\n" +
               "        for (Object o : localizations) {\n" +
               "            //do something \n" +
               "        }\n" +
               "    }\n" +
"}", "class Foo {\n" +
     "    void foo() {\n" +
     "        for (Object o : localizations)\n" +
     "        {\n" +
     "            //do something \n" +
     "        }\n" +
     "    }\n" +
     "}");
  }
项目:intellij-ce-playground    文件:SyntheticCodeBlock.java   
public SyntheticCodeBlock(List<Block> subBlocks,
                          Alignment alignment,
                          CommonCodeStyleSettings settings,
                          JavaCodeStyleSettings javaSettings,
                          Indent indent,
                          Wrap wrap)
{
  myJavaSettings = javaSettings;
  myIndentContent = indent;
  if (subBlocks.isEmpty()) {
    LOG.assertTrue(false);
  }
  mySubBlocks = new ArrayList<Block>(subBlocks);
  myAlignment = alignment;
  mySettings = settings;
  myWrap = wrap;
  myTextRange = new TextRange(mySubBlocks.get(0).getTextRange().getStartOffset(),
                              mySubBlocks.get(mySubBlocks.size() - 1).getTextRange().getEndOffset());
}
项目:intellij-ce-playground    文件:BlockAlignmentProcessor.java   
public Context(@NotNull Document document,
               @NotNull AlignmentImpl alignment,
               @NotNull LeafBlockWrapper targetBlock,
               @NotNull Map<AbstractBlockWrapper, Set<AbstractBlockWrapper>> alignmentMappings,
               @NotNull Map<LeafBlockWrapper, Set<LeafBlockWrapper>> backwardShiftedAlignedBlocks,
               @NotNull CommonCodeStyleSettings.IndentOptions indentOptions,
               int maxAlignmentSpaces)
{
  this.document = document;
  this.alignment = alignment;
  this.targetBlock = targetBlock;
  this.alignmentMappings = alignmentMappings;
  this.backwardShiftedAlignedBlocks = backwardShiftedAlignedBlocks;
  this.indentOptions = indentOptions;
  this.maxAlignmentSpaces = maxAlignmentSpaces;
}
项目:intellij-ce-playground    文件:JavaFormatterTest.java   
public void testDoNotWrapLBrace() throws IncorrectOperationException {
    getSettings().BRACE_STYLE = CommonCodeStyleSettings.END_OF_LINE;
    getSettings().RIGHT_MARGIN = 66;
    doTextTest("public class Test {\n" +
               "    void foo(){\n" +
               "        if (veryLongIdentifier1 == 1 && veryLongIdentifier2 == 2) {\n" +
               "            doSmth();\n" +
               "        }\n" +
               "    }\n" +
"}", "public class Test {\n" +
     "    void foo() {\n" +
     "        if (veryLongIdentifier1 == 1 && veryLongIdentifier2 == 2) {\n" +
     "            doSmth();\n" +
     "        }\n" +
     "    }\n" +
     "}");
  }
项目:intellij-ce-playground    文件:JavaFormatterBracesTest.java   
public void testIfStatementElseBranchIsOnNewLine() throws Exception {
  getSettings().KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = true;
  getSettings().BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE;
  String before = "if (2 > 3) {\n" +
                  "    System.out.println(\"AA!\");\n" +
                  "} else {\n" +
                  "    int a = 3;\n" +
                  "}";
  String after = "if (2 > 3)\n" +
                 "{\n" +
                 "    System.out.println(\"AA!\");\n" +
                 "} else\n" +
                 "{\n" +
                 "    int a = 3;\n" +
                 "}";
  doMethodTest(before, after);
}
项目:intellij-ce-playground    文件:JavaFormatterWrapTest.java   
public void test_RParen_OnNextLine_IfWrapped() {
  getSettings().CALL_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_ALWAYS;
  getSettings().CALL_PARAMETERS_RPAREN_ON_NEXT_LINE = true;

  doMethodTest("fuun(\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\", \"cccccccccccccc\");",
               "fuun(\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\n" +
               "        \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\n" +
               "        \"cccccccccccccc\"" +
               "\n);");


  getSettings().CALL_PARAMETERS_RPAREN_ON_NEXT_LINE = false;
  doMethodTest("fuun(\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\", \"cccccccccccccc\");",
               "fuun(\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\n" +
               "        \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\n" +
               "        \"cccccccccccccc\");");

}
项目:intellij-ce-playground    文件:JavaFormatterWrapTest.java   
@SuppressWarnings("SpellCheckingInspection")
public void testDoNotWrapMethodsWithMethodCallAsParameters() {
  getSettings().WRAP_LONG_LINES = true;
  getSettings().RIGHT_MARGIN = 140;
  getSettings().PREFER_PARAMETERS_WRAP = true;
  getSettings().CALL_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_ON_EVERY_ITEM;
  getSettings().CALL_PARAMETERS_RPAREN_ON_NEXT_LINE = true;
  getSettings().CALL_PARAMETERS_LPAREN_ON_NEXT_LINE = true;

  String before = "   processingEnv.getMessenger().printMessage(Diagnostic.Kind.ERROR, getMessage());";
  String after = "processingEnv.getMessenger().printMessage(Diagnostic.Kind.ERROR, getMessage());";

  doMethodTest(before, after);

  before = "   processingEnv.getMessenger().printMessage(Diagnostic.Kind.ERROR, getMessage(loooooooooooooooooongParamName));";
  after = "processingEnv.getMessenger().printMessage(Diagnostic.Kind.ERROR, getMessage(loooooooooooooooooongParamName));";

  doMethodTest(before, after);
}
项目:intellij-ce-playground    文件:CodeBlockBlock.java   
/**
 * There is a possible case that 'implements' section is incomplete (e.g. ends with comma). We may want to align lbrace
 * to the comma then.
 *
 * @param alignment     block alignment
 * @param baseNode      base AST node
 * @return              alignment strategy to use for the given node
 */
private static AlignmentStrategy getAlignmentStrategy(Alignment alignment, ASTNode baseNode, @NotNull CommonCodeStyleSettings settings) {
  if (baseNode.getElementType() != JavaElementType.CLASS || !settings.ALIGN_MULTILINE_EXTENDS_LIST) {
    return AlignmentStrategy.wrap(alignment);
  }
  for (ASTNode node = baseNode.getLastChildNode(); node != null; node = FormatterUtil.getPreviousNonWhitespaceSibling(node)) {
    if (node.getElementType() != JavaElementType.IMPLEMENTS_LIST) {
      continue;
    }
    ASTNode lastChildNode = node.getLastChildNode();
    if (lastChildNode != null && lastChildNode.getElementType() == TokenType.ERROR_ELEMENT) {
      Alignment alignmentToUse = alignment;
      if (alignment == null) {
        alignmentToUse = Alignment.createAlignment();
      }
      return AlignmentStrategy.wrap(
        alignmentToUse, false, JavaTokenType.LBRACE, JavaElementType.JAVA_CODE_REFERENCE, node.getElementType()
      );
    }
    break;
  }
  return AlignmentStrategy.wrap(alignment);
}
项目:intellij-ce-playground    文件:JavaFormatterTest.java   
public void testLabel() throws Exception {
    final CommonCodeStyleSettings settings = getSettings();
    settings.getRootSettings().getIndentOptions(StdFileTypes.JAVA).LABEL_INDENT_ABSOLUTE = true;
    settings.SPECIAL_ELSE_IF_TREATMENT = true;
    settings.FOR_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS;
    myTextRange = new TextRange(59, 121);
    doTextTest("public class Foo {\n" +
               "    public void foo() {\n" +
               "label2:\n" +
               "        for (int i = 0; i < 5; i++)\n" +
               "        {doSomething(i);\n" +
               "        }\n" +
               "    }\n" +
"}", "public class Foo {\n" +
     "    public void foo() {\n" +
     "label2:\n" +
     "        for (int i = 0; i < 5; i++) {\n" +
     "            doSomething(i);\n" +
     "        }\n" +
     "    }\n" +
     "}");
  }
项目:intellij-ce-playground    文件:FormatterImpl.java   
@Override
public String getLineIndent(final FormattingModel model,
                            final CodeStyleSettings settings,
                            final CommonCodeStyleSettings.IndentOptions indentOptions,
                            final int offset,
                            final TextRange affectedRange) {
  final FormattingDocumentModel documentModel = model.getDocumentModel();
  final Block block = model.getRootBlock();
  if (block.getTextRange().isEmpty()) return null; // handing empty document case
  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)) {
    final WhiteSpace whiteSpace = blockAfterOffset.getWhiteSpace();
    final IndentInfo indent = calcIndent(offset, documentModel, processor, whiteSpace);

    return indent.generateNewWhiteSpace(indentOptions);
  }
  return null;
}
项目:intellij-spring-assistant    文件:Util.java   
@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);
}
项目:AppleScript-IDEA    文件:AppleScriptLanguageCodeStyleSettingsProvider.java   
@Override
public CommonCodeStyleSettings getDefaultCommonSettings() {
  CommonCodeStyleSettings defaultSettings = new CommonCodeStyleSettings(getLanguage());
  CommonCodeStyleSettings.IndentOptions indentOptions = defaultSettings.initIndentOptions();
  indentOptions.INDENT_SIZE = 2;
  indentOptions.CONTINUATION_INDENT_SIZE = 4;
  indentOptions.TAB_SIZE = 2;
  return defaultSettings;
}
项目:hybris-integration-intellij-idea-plugin    文件:ImportProjectProgressModalWindow.java   
private void disableWrapOnType(final Language impexLanguage) {
    final CodeStyleScheme currentScheme = CodeStyleSchemes.getInstance().getCurrentScheme();
    final CodeStyleSettings codeStyleSettings = currentScheme.getCodeStyleSettings();
    if (impexLanguage != null) {
        CommonCodeStyleSettings langSettings = codeStyleSettings.getCommonSettings(impexLanguage);
        if (langSettings != null) {
            langSettings.WRAP_ON_TYPING = CommonCodeStyleSettings.WrapOnTyping.NO_WRAP.intValue;
        }
    }
}
项目:intellij-csv-validator    文件:CsvLanguageCodeStyleSettingsProvider.java   
@Override
public CommonCodeStyleSettings getDefaultCommonSettings() {
    CommonCodeStyleSettings commonSettings = new CommonCodeStyleSettings(getLanguage());
    commonSettings.initIndentOptions();
    commonSettings.getIndentOptions().TAB_SIZE = 1;
    commonSettings.getIndentOptions().INDENT_SIZE = 1;
    commonSettings.getIndentOptions().USE_TAB_CHARACTER = false;
    return commonSettings;
}
项目:smcplugin    文件:SmcFormattingModelBuilder.java   
static SpacingBuilder createSpacingBuilder(CodeStyleSettings settings) {
    final SmcCodeStyleSettings smcSettings = settings.getCustomSettings(SmcCodeStyleSettings.class);
    final CommonCodeStyleSettings commonSettings = settings.getCommonSettings(SmcLanguage.INSTANCE);

    return new SpacingBuilder(settings, SmcLanguage.INSTANCE)
            .before(COLON).spaceIf(commonSettings.SPACE_BEFORE_COLON)
            .after(COLON).spaceIf(commonSettings.SPACE_AFTER_COLON)
            .withinPair(BRACE_OPEN, BRACE_CLOSE).spaceIf(commonSettings.SPACE_WITHIN_BRACES, true)
            .withinPair(PARENTHESES_OPEN, PARENTHESES_CLOSE).spaceIf(smcSettings.SPACE_WITHIN_PARENTHESES)
            .before(COMMA).spaceIf(commonSettings.SPACE_BEFORE_COMMA)
            .before(SEMICOLON).spaceIf(commonSettings.SPACE_BEFORE_SEMICOLON)
            .after(SEMICOLON).spaceIf(commonSettings.SPACE_AFTER_SEMICOLON)
            .after(COMMA).spaceIf(commonSettings.SPACE_AFTER_COMMA)
            .before(TRANSITIONS_BLOCK).spaceIf(smcSettings.SPACE_BEFORE_TRANSITIONS_BLOCK)
            .before(PARENTHESES_OPEN).spaceIf(smcSettings.SPACE_BEFORE_PARENTHESES_OPEN)
            .around(MAP_NAME_STATE_NAME_SEPARATOR).spaceIf(smcSettings.SPACE_AROUND_MAP_STATE_SEPARATOR)
            .after(SmcParserDefinition.BEGIN_LINE_KEYWORDS).spaces(REQUIRED_SPACE_AFTER_BEGIN_LINE_KEYWORD)
            .after(SmcParserDefinition.IN_CODE_KEYWORDS).spaceIf(smcSettings.SPACE_AFTER_KEYWORD)
            .after(SmcParserDefinition.ON_ENTRY_EXIT_KEYWORDS).spaceIf(smcSettings.SPACE_AFTER_ENTRY_EXIT_KEYWORDS)
            .around(MAP).blankLines(smcSettings.BLANK_LINES_AROUND_MAP)
            .around(STATE).blankLines(smcSettings.BLANK_LINES_AROUND_STATE)
            .around(TRANSITION).blankLines(smcSettings.BLANK_LINES_AROUND_TRANSITION)
            .around(ENTRY).blankLines(smcSettings.BLANK_LINES_AROUND_ENTRY)
            .around(EXIT).blankLines(smcSettings.BLANK_LINES_AROUND_EXIT)
            .before(POP_TRANSITION).spaces(OBLIGATORY_SPACE)
            .before(PUSH_TRANSITION).spaces(OBLIGATORY_SPACE)
            .before(TRANSITION_ARGS).spaceIf(smcSettings.SPACE_BEFORE_TRANSITION_ARGS)
            .before(ACTIONS_BLOCK).spaceIf(smcSettings.SPACE_BEFORE_ACTIONS_BLOCK)
            .around(SmcTypes.PUSH_PROXY_STATE_KEYWORD_SEPARATOR).spaceIf(smcSettings.SPACE_AROUND_PUSH_PROXY_STATE_KEYWORD_SEPARATOR)
            .before(SmcTypes.ON_STATE).spaces(OBLIGATORY_SPACE)
            .before(SmcTypes.NEXT_STATE).spaces(OBLIGATORY_SPACE)
            .after(PUSH_PROXY_STATE).spaceIf(smcSettings.SPACE_AROUND_PUSH_PROXY_STATE_KEYWORD_SEPARATOR)
            ;
}
项目:intellij-ce-playground    文件: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 append(int newEndOffset, FormattingDocumentModel model, CommonCodeStyleSettings.IndentOptions options) {
  final int oldEndOffset = myEnd;
  if (newEndOffset == oldEndOffset) return;
  if (myStart >= newEndOffset) {
    InitialInfoBuilder.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)) {
    InitialInfoBuilder.assertInvalidRanges(myStart,
      myEnd,
      model,
      "nonempty text is not covered by block"
    );
  }

  // There is a possible case that this method is called more than once on the same object. We want to
  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);
}
项目:intellij-ce-playground    文件:CodeStyleBlankLinesPanel.java   
public void setFieldValue(CodeStyleSettings settings, int value) {
  try {
    if (myTargetClass != null) {
      myTarget.setInt(settings.getCustomSettings(myTargetClass), value);
    }
    else {
      CommonCodeStyleSettings commonSettings = settings.getCommonSettings(getDefaultLanguage());
      myTarget.setInt(commonSettings, value);
    }
  }
  catch (IllegalAccessException e) {
    LOG.error(e);
  }
}
项目:intellij-ce-playground    文件:CreateFieldFromUsageTest.java   
public void testWithAlignment() throws Exception {
  final CommonCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
  boolean old = settings.ALIGN_GROUP_FIELD_DECLARATIONS;
  try {
    settings.ALIGN_GROUP_FIELD_DECLARATIONS = true;
    doSingleTest();
  }
  finally {
    settings.ALIGN_GROUP_FIELD_DECLARATIONS = old;
  }
}
项目:intellij-ce-playground    文件:JavaFormatterSpaceTest.java   
public void testSpacesBeforeResourceList() {
  getSettings().KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = true;
  getSettings().BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE;

  getSettings().SPACE_BEFORE_TRY_PARENTHESES = true;
  getSettings().SPACE_BEFORE_TRY_LBRACE = true;
  doMethodTest("try(AutoCloseable r = null){ }",
               "try (AutoCloseable r = null) { }");

  getSettings().SPACE_BEFORE_TRY_PARENTHESES = false;
  getSettings().SPACE_BEFORE_TRY_LBRACE = false;
  doMethodTest("try (AutoCloseable r = null) { }",
               "try(AutoCloseable r = null){ }");
}
项目:protobuf-jetbrains-plugin    文件:FormatterTest.java   
private void run(String test, Consumer<CommonCodeStyleSettings> settings) {
    myFixture.configureByFiles(test + "/Source.proto");
    CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(getProject());
    CommonCodeStyleSettings protoSettings = codeStyleSettings.getCommonSettings(ProtoLanguage.INSTANCE);
    settings.accept(protoSettings);
    new WriteCommandAction.Simple(getProject()) {
        @Override
        protected void run() throws Throwable {
            CodeStyleManager.getInstance(getProject()).reformat(myFixture.getFile());
        }
    }.execute();
    myFixture.checkResultByFile(test + "/Expected.proto");
}
项目:intellij-ce-playground    文件: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();
  }
}
项目:intellij    文件:BuildLanguageCodeStyleSettingsProvider.java   
@Nullable
@Override
public CommonCodeStyleSettings getDefaultCommonSettings() {
  CommonCodeStyleSettings defaultSettings =
      new CommonCodeStyleSettings(BuildFileLanguage.INSTANCE);
  CommonCodeStyleSettings.IndentOptions indentOptions = defaultSettings.initIndentOptions();
  indentOptions.TAB_SIZE = 2;
  indentOptions.INDENT_SIZE = 2;
  indentOptions.CONTINUATION_INDENT_SIZE = 4;
  return defaultSettings;
}
项目:intellij-ce-playground    文件:EclipseCodeStyleImportWorker.java   
private static int valueToInt(@NotNull String value) {
  if (VALUE_END_OF_LINE.equals(value)) return CommonCodeStyleSettings.END_OF_LINE;
  if (VALUE_NEXT_LINE.equals(value)) return CommonCodeStyleSettings.NEXT_LINE;
  if (VALUE_NEXT_LINE_SHIFTED.equals(value)) return CommonCodeStyleSettings.NEXT_LINE_SHIFTED;
  if (VALUE_NEXT_LINE_IF_WRAPPED.equals(value)) return CommonCodeStyleSettings.NEXT_LINE_IF_WRAPPED;
  return Integer.parseInt(value);
}
项目:intellij-ce-playground    文件:JavaFormatterBracesTest.java   
public void testMethodBraceOnNextLineIfWrapped() {
  getSettings().METHOD_BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE_IF_WRAPPED;
  getSettings().METHOD_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
  getSettings().RIGHT_MARGIN = 50;
  doClassTest(
    "public static void main(int state, int column, int width, int rate) {\n" +
    "}\n",
    "public static void main(int state, int column,\n" +
    "                        int width, int rate)\n" +
    "{\n" +
    "}\n"
  );
}
项目:intellij-ce-playground    文件:GroovyIndentProcessor.java   
public static Indent getSwitchCaseIndent(final CommonCodeStyleSettings settings) {
  if (settings.INDENT_CASE_FROM_SWITCH) {
    return Indent.getNormalIndent();
  }
  else {
    return Indent.getNoneIndent();
  }
}
项目:intellij-ce-playground    文件:JavaFormatterWrapTest.java   
public void testWrapMethodAnnotationBeforeParams() {
  // Inspired by IDEA-59536
  getSettings().RIGHT_MARGIN = 90;
  getSettings().METHOD_ANNOTATION_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
  getSettings().METHOD_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;

  doClassTest(
      "@SuppressWarnings({\"SomeInspectionIWantToIgnore\"}) public void doSomething(int x, int y) {}",
      "@SuppressWarnings({\"SomeInspectionIWantToIgnore\"})\n" +
      "public void doSomething(int x, int y) {\n}"
  );
}
项目:intellij-ce-playground    文件: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;
  }
}
项目:intellij-ce-playground    文件:JavaFormatterWrapTest.java   
public void test_WrapIfLong_On_Second_Parameter_ActivatesPlaceNewLineAfterParenthesis() {
  getSettings().CALL_PARAMETERS_LPAREN_ON_NEXT_LINE = true;
  getSettings().CALL_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;

  doMethodTest("fuun(\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\", \"cccccccccccccc\");",
               "fuun(\n" +
               "        \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\n" +
               "        \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\", \"cccccccccccccc\");");
}
项目:intellij-ce-playground    文件:JavaFormatterTest.java   
public void testIDEADEV_22967() throws IncorrectOperationException {
  getSettings().METHOD_ANNOTATION_WRAP = CommonCodeStyleSettings.WRAP_ALWAYS;

  doTextTest("public interface TestInterface {\n" +
             "\n" +
             "    void empty();\n" +
             "\n" +
             "    @Deprecated\n" +
             "    void annotated();\n" +
             "\n" +
             "    <T> void parametrized(T data);\n" +
             "\n" +
             "    @Deprecated\n" +
             "    <T> void parametrizedAnnotated(T data);\n" +
             "\n" +
             "    @Deprecated\n" +
             "    public <T> void publicParametrizedAnnotated(T data);\n" +
             "\n" +
             "}", "public interface TestInterface {\n" +
                  "\n" +
                  "    void empty();\n" +
                  "\n" +
                  "    @Deprecated\n" +
                  "    void annotated();\n" +
                  "\n" +
                  "    <T> void parametrized(T data);\n" +
                  "\n" +
                  "    @Deprecated\n" +
                  "    <T> void parametrizedAnnotated(T data);\n" +
                  "\n" +
                  "    @Deprecated\n" +
                  "    public <T> void publicParametrizedAnnotated(T data);\n" +
                  "\n" +
                  "}");
}
项目:intellij-ce-playground    文件:JoinLinesTest.java   
public void testReformatInsertsNewlines() throws Exception {
  CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
  final Element root = new Element("fake");
  settings.writeExternal(root);
  try {
    settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = true;
    settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = true;
    settings.IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS;
    settings.METHOD_BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE;
    doTest();
  } finally {
    settings.readExternal(root);
  }
}
项目:intellij-ce-playground    文件:SimpleIndentingBackspaceHandlerTest.java   
public void testDeletingTabWhenIndentSizeIsSmaller() {
  CodeStyleSettings settings = new CodeStyleSettings();
  CommonCodeStyleSettings.IndentOptions indentOptions = settings.getIndentOptions();
  assertNotNull(indentOptions);
  indentOptions.INDENT_SIZE = 2;
  indentOptions.TAB_SIZE = 4;
  CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(settings);
  try {
    doTest("\t<caret>text",
           "  <caret>text");
  }
  finally {
    CodeStyleSettingsManager.getInstance().dropTemporarySettings();
  }
}
项目:intellij-ce-playground    文件:PyLanguageCodeStyleSettingsProvider.java   
@Override
public CommonCodeStyleSettings getDefaultCommonSettings() {
  CommonCodeStyleSettings defaultSettings = new CommonCodeStyleSettings(PythonLanguage.getInstance());
  CommonCodeStyleSettings.IndentOptions indentOptions = defaultSettings.initIndentOptions();
  indentOptions.INDENT_SIZE = 4;
  defaultSettings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true;
  defaultSettings.KEEP_BLANK_LINES_IN_DECLARATIONS = 1;
  defaultSettings.KEEP_BLANK_LINES_IN_CODE = 1;
  return defaultSettings;
}