mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
IDEA-65433 Code style feature: simple classes and interfaces in one line
1. Added new code style setting - 'keep simple classes and interfaces in one line'; 2. Corresponding tests are added;
This commit is contained in:
@@ -220,7 +220,10 @@ public class JavaLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSett
|
||||
" throws Exception { \n" +
|
||||
" foo.foo().bar(\"arg1\", \n" +
|
||||
" \"arg2\"); \n" +
|
||||
" new Object() {};" +
|
||||
" } \n" +
|
||||
" class TestInnerClass {}\n" +
|
||||
" interface TestInnerInterface {}\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
"enum Breed {\n" +
|
||||
|
||||
@@ -213,6 +213,10 @@ public class JavaSpacePropertyProcessor extends JavaElementVisitor {
|
||||
if (aClass.isEnum()) {
|
||||
createParenSpace(true, false);
|
||||
}
|
||||
else if (myRole2 == ChildRole.RBRACE && mySettings.KEEP_SIMPLE_CLASSES_IN_ONE_LINE) {
|
||||
int spaces = mySettings.SPACE_WITHIN_BRACES ? 1 : 0;
|
||||
myResult = Spacing.createSpacing(spaces, spaces, 0, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_DECLARATIONS);
|
||||
}
|
||||
else if (aClass instanceof PsiAnonymousClass) {
|
||||
if (myRole2 == ChildRole.CLASS_INITIALIZER && isTheOnlyClassMember(myChild2)) {
|
||||
myResult = Spacing.createSpacing(0, 0, 0,
|
||||
|
||||
@@ -113,4 +113,23 @@ public class JavaFormatterBracesTest extends AbstractJavaFormatterTest {
|
||||
"}"
|
||||
);
|
||||
}
|
||||
|
||||
public void testKeepSimpleClassesAndInterfacesInOneLine() {
|
||||
// Inspired by IDEA-65433
|
||||
getSettings().KEEP_SIMPLE_CLASSES_IN_ONE_LINE = true;
|
||||
|
||||
String[] tests = {
|
||||
"class Test {}",
|
||||
"interface Test {}",
|
||||
"class Test {\n" +
|
||||
" void test() {\n" +
|
||||
" new Object() {};\n" +
|
||||
" }\n" +
|
||||
"}"
|
||||
};
|
||||
|
||||
for (String test : tests) {
|
||||
doTextTest(test, test);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -654,6 +654,7 @@ public class CommonCodeStyleSettings {
|
||||
|
||||
public boolean KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = false;
|
||||
public boolean KEEP_SIMPLE_METHODS_IN_ONE_LINE = false;
|
||||
public boolean KEEP_SIMPLE_CLASSES_IN_ONE_LINE = false;
|
||||
public boolean KEEP_MULTIPLE_EXPRESSIONS_IN_ONE_LINE = false;
|
||||
|
||||
public int FOR_STATEMENT_WRAP = DO_NOT_WRAP;
|
||||
|
||||
@@ -35,9 +35,10 @@ public class WrappingAndBracesPanel extends OptionTableWithPreviewPanel {
|
||||
addOption("KEEP_FIRST_COLUMN_COMMENT", ApplicationBundle.message("wrapping.keep.comment.at.first.column"), WRAPPING_KEEP);
|
||||
addOption("KEEP_CONTROL_STATEMENT_IN_ONE_LINE", ApplicationBundle.message("checkbox.keep.when.reformatting.control.statement.in.one.line"),
|
||||
WRAPPING_KEEP);
|
||||
addOption("KEEP_MULTIPLE_EXPRESSIONS_IN_ONE_LINE", ApplicationBundle.message("wrapping.keep.multiple.expressions.in.one.line"), WRAPPING_KEEP);
|
||||
addOption("KEEP_SIMPLE_BLOCKS_IN_ONE_LINE", ApplicationBundle.message("wrapping.keep.simple.blocks.in.one.line"), WRAPPING_KEEP);
|
||||
addOption("KEEP_SIMPLE_METHODS_IN_ONE_LINE", ApplicationBundle.message("wrapping.keep.simple.methods.in.one.line"), WRAPPING_KEEP);
|
||||
addOption("KEEP_MULTIPLE_EXPRESSIONS_IN_ONE_LINE", ApplicationBundle.message("wrapping.keep.multiple.expressions.in.one.line"), WRAPPING_KEEP);
|
||||
addOption("KEEP_SIMPLE_CLASSES_IN_ONE_LINE", ApplicationBundle.message("wrapping.keep.simple.classes.in.one.line"), WRAPPING_KEEP);
|
||||
|
||||
addOption("CLASS_BRACE_STYLE", ApplicationBundle.message("wrapping.brace.placement.class.declaration"), WRAPPING_BRACES, BRACE_PLACEMENT_OPTIONS, BRACE_PLACEMENT_VALUES);
|
||||
addOption("METHOD_BRACE_STYLE", ApplicationBundle.message("wrapping.brace.placement.method.declaration"), WRAPPING_BRACES, BRACE_PLACEMENT_OPTIONS, BRACE_PLACEMENT_VALUES);
|
||||
|
||||
@@ -131,6 +131,7 @@ wrapping.and.braces=Wrapping and Braces
|
||||
wrapping.keep.when.reformatting=Keep when reformatting
|
||||
wrapping.keep.line.breaks=Line breaks
|
||||
wrapping.keep.comment.at.first.column=Comment at first column
|
||||
wrapping.keep.simple.classes.in.one.line=Simple classes in one line
|
||||
wrapping.keep.simple.methods.in.one.line=Simple methods in one line
|
||||
wrapping.keep.multiple.expressions.in.one.line=Multiple expressions in one line
|
||||
wrapping.keep.simple.blocks.in.one.line=Simple blocks in one line
|
||||
|
||||
Reference in New Issue
Block a user