当前位置: 首页>>代码示例>>Java>>正文


Java CommonCodeStyleSettings.FORCE_BRACES_ALWAYS属性代码示例

本文整理汇总了Java中com.intellij.psi.codeStyle.CommonCodeStyleSettings.FORCE_BRACES_ALWAYS属性的典型用法代码示例。如果您正苦于以下问题:Java CommonCodeStyleSettings.FORCE_BRACES_ALWAYS属性的具体用法?Java CommonCodeStyleSettings.FORCE_BRACES_ALWAYS怎么用?Java CommonCodeStyleSettings.FORCE_BRACES_ALWAYS使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在com.intellij.psi.codeStyle.CommonCodeStyleSettings的用法示例。


在下文中一共展示了CommonCodeStyleSettings.FORCE_BRACES_ALWAYS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testUnwrapCodeBlock2

public void testUnwrapCodeBlock2() throws Exception {
  CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
  boolean use_tab_character = settings.useTabCharacter(null);
  boolean smart_tabs = settings.isSmartTabs(null);
  int old = settings.IF_BRACE_FORCE;
  try {
    settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = true;
    settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = true;
    settings.getCommonSettings(JavaLanguage.INSTANCE).IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS;
    doTest();
  } finally {
    settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = use_tab_character;
    settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = smart_tabs;
    settings.getCommonSettings(JavaLanguage.INSTANCE).IF_BRACE_FORCE = old;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:JoinLinesTest.java

示例2: testLabel

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" +
     "}");
  }
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:JavaFormatterTest.java

示例3: tryJoinLines

@Override
public int tryJoinLines(final Document document, final PsiFile psiFile, final int start, final int end) {
  PsiElement elementAtStartLineEnd = psiFile.findElementAt(start);
  PsiElement elementAtNextLineStart = psiFile.findElementAt(end);
  if (elementAtStartLineEnd == null || elementAtNextLineStart == null) return -1;
  if (!(elementAtStartLineEnd instanceof PsiJavaToken) || ((PsiJavaToken)elementAtStartLineEnd).getTokenType() != JavaTokenType.LBRACE) {
    return -1;
  }
  final PsiElement codeBlock = elementAtStartLineEnd.getParent();
  if (!(codeBlock instanceof PsiCodeBlock)) return -1;
  if (!(codeBlock.getParent() instanceof PsiBlockStatement)) return -1;
  final PsiElement parentStatement = codeBlock.getParent().getParent();

  if (getForceBraceSetting(parentStatement) == CommonCodeStyleSettings.FORCE_BRACES_ALWAYS) {
    return CANNOT_JOIN;
  }
  PsiElement foundStatement = null;
  for (PsiElement element = elementAtStartLineEnd.getNextSibling(); element != null; element = element.getNextSibling()) {
    if (element instanceof PsiWhiteSpace) continue;
    if (element instanceof PsiJavaToken &&
        ((PsiJavaToken)element).getTokenType() == JavaTokenType.RBRACE &&
        element.getParent() == codeBlock) {
      if (foundStatement == null) return -1;
      break;
    }
    if (foundStatement != null) return -1;
    foundStatement = element;
  }
  try {
    final PsiElement newStatement = codeBlock.getParent().replace(foundStatement);

    return newStatement.getTextRange().getStartOffset();
  }
  catch (IncorrectOperationException e) {
    LOG.error(e);
  }
  return -1;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:38,代码来源:BlockJoinLinesHandler.java

示例4: processStatement

private void processStatement(PsiStatement statement, PsiStatement blockCandidate, int options) {
  if (blockCandidate instanceof PsiBlockStatement || blockCandidate == null) return;
  if (options == CommonCodeStyleSettings.FORCE_BRACES_ALWAYS
      || (options == CommonCodeStyleSettings.FORCE_BRACES_IF_MULTILINE && PostFormatProcessorHelper.isMultiline(statement)))
  {
    replaceWithBlock(statement, blockCandidate);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:BraceEnforcer.java

示例5: testReformatInsertsNewlines

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);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:JoinLinesTest.java

示例6: testForceBrace

public void testForceBrace() throws Exception {
  CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
  int old = settings.IF_BRACE_FORCE;
  try {
    settings.IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS;
    doTest();
  } finally {
    settings.IF_BRACE_FORCE = old;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:JoinLinesTest.java

示例7: testIfBraces

public void testIfBraces() throws Exception {
  final CommonCodeStyleSettings settings = getSettings();
  settings.IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS;
  settings.BRACE_STYLE = CommonCodeStyleSettings.END_OF_LINE;
  settings.KEEP_LINE_BREAKS = false;
  doTest();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:JavaFormatterTest.java

示例8: testSCR260

public void testSCR260() throws Exception {
  final CommonCodeStyleSettings settings = getSettings();
  settings.IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS;
  settings.BRACE_STYLE = CommonCodeStyleSettings.END_OF_LINE;
  settings.KEEP_LINE_BREAKS = false;
  doTest();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:JavaFormatterTest.java

示例9: testSCR259

public void testSCR259() throws Exception {
  myTextRange = new TextRange(36, 60);
  final CommonCodeStyleSettings settings = getSettings();
  settings.IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS;
  settings.KEEP_LINE_BREAKS = false;
  doTest();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:JavaFormatterTest.java

示例10: testSimpleBlockInOneLinesAndForceBraces

public void testSimpleBlockInOneLinesAndForceBraces() throws Exception {
  // Inspired by IDEA-19328
  getSettings().KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = true;
  getSettings().IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS;

  doMethodTest(
    "if (x > y) System.out.println(\"foo!\");",

    "if (x > y) { System.out.println(\"foo!\"); }"
  );
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:JavaFormatterBracesTest.java

示例11: testEnforcingBracesForExpressionEndingWithLineComment

public void testEnforcingBracesForExpressionEndingWithLineComment() throws Exception {
  // Inspired by IDEA-57936
  getSettings().IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS;

  doMethodTest(
    "if (true) i = 1; // Cool if\n" +
    "else i = 2;",

    "if (true) {\n" +
    "    i = 1; // Cool if\n" +
    "} else {\n" +
    "    i = 2;\n" +
    "}"
  );
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:JavaFormatterBracesTest.java

示例12: testForceBraces

public void testForceBraces() throws Exception {
  final CommonCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
  int old = settings.IF_BRACE_FORCE;
  settings.IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS;
  try {
    doTest();
  }
  finally {
    settings.IF_BRACE_FORCE = old;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:ExtractMethodTest.java

示例13: processStatement

private void processStatement(GrStatement statement, @Nullable GrStatement blockCandidate, int options) {
  if (blockCandidate instanceof GrCodeBlock || blockCandidate instanceof GrBlockStatement || blockCandidate == null) return;
  if (options == CommonCodeStyleSettings.FORCE_BRACES_ALWAYS ||
      options == CommonCodeStyleSettings.FORCE_BRACES_IF_MULTILINE && PostFormatProcessorHelper.isMultiline(statement)) {
    replaceWithBlock(statement, blockCandidate);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:GroovyBraceEnforcer.java

示例14: testBraces

public void testBraces() {
  final CommonCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
  final int oldValue = settings.IF_BRACE_FORCE;
  try {
    settings.IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS;
    doTest();
  } finally {
    settings.IF_BRACE_FORCE = oldValue;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:ExpandBooleanIntentionTest.java

示例15: testFormatterOnOffTags

public void testFormatterOnOffTags() throws Exception {
  getSettings().getRootSettings().FORMATTER_TAGS_ENABLED = true;
  getSettings().IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS;
  doTest();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:5,代码来源:JavaFormatterTest.java


注:本文中的com.intellij.psi.codeStyle.CommonCodeStyleSettings.FORCE_BRACES_ALWAYS属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。