本文整理汇总了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;
}
}
示例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" +
"}");
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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;
}
}
示例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();
}
示例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();
}
示例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();
}
示例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!\"); }"
);
}
示例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" +
"}"
);
}
示例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;
}
}
示例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);
}
}
示例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;
}
}
示例15: testFormatterOnOffTags
public void testFormatterOnOffTags() throws Exception {
getSettings().getRootSettings().FORMATTER_TAGS_ENABLED = true;
getSettings().IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS;
doTest();
}