Replace a simple code style property test with export to Json

This commit is contained in:
Rustam Vishnyakov
2019-01-23 16:22:56 +03:00
parent 0ea170514d
commit 254c3dff56
3 changed files with 266 additions and 246 deletions
@@ -0,0 +1,244 @@
[
{
"language": "java",
"options": {
"align_consecutive_assignments": "false",
"align_consecutive_variable_declarations": "false",
"align_group_field_declarations": "false",
"align_multiline_annotation_parameters": "false",
"align_multiline_array_initializer_expression": "false",
"align_multiline_assignment": "false",
"align_multiline_binary_operation": "false",
"align_multiline_chained_methods": "false",
"align_multiline_extends_list": "false",
"align_multiline_for": "true",
"align_multiline_method_brackets": "false",
"align_multiline_parameters": "true",
"align_multiline_parameters_in_calls": "false",
"align_multiline_parenthesized_expression": "false",
"align_multiline_resources": "true",
"align_multiline_ternary_operation": "false",
"align_multiline_throws_list": "false",
"align_subsequent_simple_methods": "false",
"align_throws_keyword": "false",
"annotation_parameter_wrap": "off",
"array_initializer_new_line_after_left_brace": "false",
"array_initializer_right_brace_on_new_line": "false",
"array_initializer_wrap": "off",
"assert_statement_colon_on_next_line": "false",
"assert_statement_wrap": "off",
"assignment_wrap": "off",
"binary_operation_sign_on_next_line": "false",
"binary_operation_wrap": "off",
"blank_lines_after_anonymous_class_header": "0",
"blank_lines_after_class_header": "0",
"blank_lines_after_imports": "1",
"blank_lines_after_package": "1",
"blank_lines_around_class": "1",
"blank_lines_around_field": "0",
"blank_lines_around_field_in_interface": "0",
"blank_lines_around_initializer": "1",
"blank_lines_around_method": "1",
"blank_lines_around_method_in_interface": "1",
"blank_lines_before_class_end": "0",
"blank_lines_before_imports": "1",
"blank_lines_before_method_body": "0",
"blank_lines_before_package": "0",
"block_comment_at_first_column": "true",
"brace_style": "end_of_line",
"call_parameters_new_line_after_left_paren": "false",
"call_parameters_right_paren_on_new_line": "false",
"call_parameters_wrap": "on_every_item",
"case_statement_on_new_line": "true",
"catch_on_new_line": "false",
"class_annotation_wrap": "split_into_lines",
"class_brace_style": "end_of_line",
"class_count_to_use_import_on_demand": "5",
"class_names_in_javadoc": "1",
"continuation_indent_size": "8",
"do_not_indent_top_level_class_members": "false",
"do_not_wrap_after_single_annotation": "false",
"do_while_brace_force": "never",
"doc_add_blank_line_after_description": "true",
"doc_add_blank_line_after_param_comments": "false",
"doc_add_blank_line_after_return": "false",
"doc_add_p_tag_on_empty_lines": "true",
"doc_align_exception_comments": "true",
"doc_align_param_comments": "true",
"doc_do_not_wrap_if_one_line": "false",
"doc_enable_formatting": "true",
"doc_enable_leading_asterisks": "true",
"doc_indent_on_continuation": "false",
"doc_keep_empty_lines": "true",
"doc_keep_empty_parameter_tag": "true",
"doc_keep_empty_return_tag": "true",
"doc_keep_empty_throws_tag": "true",
"doc_keep_invalid_tags": "true",
"doc_param_description_on_new_line": "false",
"doc_preserve_line_breaks": "false",
"doc_use_throws_not_exception_tag": "true",
"else_on_new_line": "false",
"enum_constants_wrap": "off",
"extends_keyword_wrap": "off",
"extends_list_wrap": "off",
"field_annotation_wrap": "split_into_lines",
"field_name_prefix": "m_",
"finally_on_new_line": "false",
"for_brace_force": "never",
"for_statement_new_line_after_left_paren": "false",
"for_statement_right_paren_on_new_line": "false",
"for_statement_wrap": "off",
"generate_final_locals": "false",
"generate_final_parameters": "false",
"if_brace_force": "never",
"imports_layout": [
"*",
"blank_line",
"javax.**",
"java.**",
"blank_line",
"static *"
],
"indent_case_from_switch": "true",
"indent_size": "4",
"indent_style": "space",
"insert_inner_class_imports": "false",
"insert_override_annotation": "true",
"keep_blank_lines_before_right_brace": "2",
"keep_blank_lines_between_package_declaration_and_header": "2",
"keep_blank_lines_in_code": "2",
"keep_blank_lines_in_declarations": "2",
"keep_control_statement_in_one_line": "true",
"keep_first_column_comment": "true",
"keep_indents_on_empty_lines": "false",
"keep_line_breaks": "true",
"keep_multiple_expressions_in_one_line": "false",
"keep_simple_blocks_in_one_line": "false",
"keep_simple_classes_in_one_line": "false",
"keep_simple_lambdas_in_one_line": "false",
"keep_simple_methods_in_one_line": "false",
"lambda_brace_style": "end_of_line",
"layout_static_imports_separately": "true",
"line_comment_add_space": "false",
"line_comment_at_first_column": "true",
"method_annotation_wrap": "split_into_lines",
"method_brace_style": "end_of_line",
"method_call_chain_wrap": "off",
"method_parameters_new_line_after_left_paren": "false",
"method_parameters_right_paren_on_new_line": "false",
"method_parameters_wrap": "normal",
"modifier_list_wrap": "false",
"names_count_to_use_import_on_demand": "3",
"packages_to_use_import_on_demand": [
"java.awt.*",
"javax.swing.*"
],
"parameter_annotation_wrap": "off",
"parentheses_expression_new_line_after_left_paren": "false",
"parentheses_expression_right_paren_on_new_line": "false",
"place_assignment_sign_on_next_line": "false",
"prefer_longer_names": "true",
"prefer_parameters_wrap": "false",
"repeat_synchronized": "true",
"replace_instanceof_and_cast": "false",
"replace_null_check": "true",
"resource_list_new_line_after_left_paren": "false",
"resource_list_right_paren_on_new_line": "false",
"resource_list_wrap": "off",
"smart_tabs": "false",
"space_after_closing_angle_bracket_in_type_argument": "false",
"space_after_colon": "true",
"space_after_comma": "true",
"space_after_comma_in_type_arguments": "true",
"space_after_for_semicolon": "true",
"space_after_quest": "true",
"space_after_type_cast": "true",
"space_before_annotation_array_initializer_left_brace": "false",
"space_before_anotation_parameter_list": "false",
"space_before_array_initializer_left_brace": "false",
"space_before_catch_keyword": "true",
"space_before_catch_left_brace": "true",
"space_before_catch_parentheses": "true",
"space_before_class_left_brace": "true",
"space_before_colon": "true",
"space_before_colon_in_foreach": "true",
"space_before_comma": "false",
"space_before_do_left_brace": "true",
"space_before_else_keyword": "true",
"space_before_else_left_brace": "true",
"space_before_finally_keyword": "true",
"space_before_finally_left_brace": "true",
"space_before_for_left_brace": "true",
"space_before_for_parentheses": "true",
"space_before_for_semicolon": "false",
"space_before_if_left_brace": "true",
"space_before_if_parentheses": "true",
"space_before_method_call_parentheses": "false",
"space_before_method_left_brace": "true",
"space_before_method_parentheses": "false",
"space_before_opening_angle_bracket_in_type_parameter": "false",
"space_before_quest": "true",
"space_before_switch_left_brace": "true",
"space_before_switch_parentheses": "true",
"space_before_synchronized_left_brace": "true",
"space_before_synchronized_parentheses": "true",
"space_before_try_left_brace": "true",
"space_before_try_parentheses": "true",
"space_before_type_parameter_list": "false",
"space_before_while_keyword": "true",
"space_before_while_left_brace": "true",
"space_before_while_parentheses": "true",
"space_inside_one_line_enum_braces": "false",
"spaces_around_additive_operators": "true",
"spaces_around_assignment_operators": "true",
"spaces_around_bitwise_operators": "true",
"spaces_around_equality_operators": "true",
"spaces_around_lambda_arrow": "true",
"spaces_around_logical_operators": "true",
"spaces_around_method_ref_dbl_colon": "false",
"spaces_around_multiplicative_operators": "true",
"spaces_around_relational_operators": "true",
"spaces_around_shift_operators": "true",
"spaces_around_type_bounds_in_type_parameters": "true",
"spaces_around_unary_operator": "false",
"spaces_within_angle_brackets": "false",
"spaces_within_annotation_parentheses": "false",
"spaces_within_array_initializer_braces": "false",
"spaces_within_braces": "false",
"spaces_within_brackets": "false",
"spaces_within_cast_parentheses": "false",
"spaces_within_catch_parentheses": "false",
"spaces_within_empty_array_initializer_braces": "false",
"spaces_within_empty_method_call_parentheses": "false",
"spaces_within_empty_method_parentheses": "false",
"spaces_within_for_parentheses": "false",
"spaces_within_if_parentheses": "false",
"spaces_within_method_call_parentheses": "false",
"spaces_within_method_parentheses": "false",
"spaces_within_parentheses": "false",
"spaces_within_switch_parentheses": "false",
"spaces_within_synchronized_parentheses": "false",
"spaces_within_try_parentheses": "false",
"spaces_within_while_parentheses": "false",
"special_else_if_treatment": "true",
"static_field_name_suffix": "_s",
"subclass_name_suffix": "Impl",
"tab_width": "4",
"ternary_operation_signs_on_next_line": "false",
"ternary_operation_wrap": "off",
"test_name_suffix": "Test",
"throws_keyword_wrap": "off",
"throws_list_wrap": "off",
"use_external_annotations": "false",
"use_fq_class_names": "false",
"use_single_class_imports": "true",
"variable_annotation_wrap": "off",
"visibility": "public",
"while_brace_force": "never",
"while_on_new_line": "false",
"wrap_comments": "false",
"wrap_first_method_in_call_chain": "false",
"wrap_long_lines": "false"
}
}
]
@@ -22,8 +22,12 @@ import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.application.ex.PathManagerEx;
import com.intellij.openapi.options.SchemeImportException;
import com.intellij.psi.codeStyle.*;
import com.intellij.psi.impl.source.codeStyle.json.CodeStyleSchemeJsonExporter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Arrays;
@@ -72,258 +76,22 @@ public class JavaCodeStyleSettingsTest extends CodeStyleTestCase {
assertFalse(imported.WRAP_COMMENTS);
}
public void testGetProperties() {
final CodeStyleSettings settings = getCurrentCodeStyleSettings();
public void testJsonExport() throws IOException {
CodeStyleScheme testScheme = createTestScheme();
final CodeStyleSettings settings = testScheme.getCodeStyleSettings();
final CommonCodeStyleSettings commonJavaSettings = settings.getCommonSettings(JavaLanguage.INSTANCE);
commonJavaSettings.METHOD_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
commonJavaSettings.CALL_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_ON_EVERY_ITEM;
final JavaCodeStyleSettings javaSettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
javaSettings.FIELD_NAME_PREFIX = "m_";
javaSettings.STATIC_FIELD_NAME_SUFFIX = "_s";
AbstractCodeStylePropertyMapper mapper =
LanguageCodeStyleSettingsProvider.forLanguage(JavaLanguage.INSTANCE).getPropertyMapper(settings);
StringBuilder builder = new StringBuilder();
for (String property : mapper.enumPropertiesFor(
JavaCodeStyleSettings.class,
CommonCodeStyleSettings.class,
CommonCodeStyleSettings.IndentOptions.class)
) {
CodeStylePropertyAccessor accessor = mapper.getAccessor(property);
Object value = accessor.get();
if (value != null) {
builder.append(property).append(" = ").append(value).append('\n');
}
}
assertEquals(
"align_consecutive_assignments = false\n" +
"align_consecutive_variable_declarations = false\n" +
"align_group_field_declarations = false\n" +
"align_multiline_annotation_parameters = false\n" +
"align_multiline_array_initializer_expression = false\n" +
"align_multiline_assignment = false\n" +
"align_multiline_binary_operation = false\n" +
"align_multiline_chained_methods = false\n" +
"align_multiline_extends_list = false\n" +
"align_multiline_for = true\n" +
"align_multiline_method_brackets = false\n" +
"align_multiline_parameters = true\n" +
"align_multiline_parameters_in_calls = false\n" +
"align_multiline_parenthesized_expression = false\n" +
"align_multiline_resources = true\n" +
"align_multiline_ternary_operation = false\n" +
"align_multiline_throws_list = false\n" +
"align_subsequent_simple_methods = false\n" +
"align_throws_keyword = false\n" +
"annotation_parameter_wrap = off\n" +
"array_initializer_new_line_after_left_brace = false\n" +
"array_initializer_right_brace_on_new_line = false\n" +
"array_initializer_wrap = off\n" +
"assert_statement_colon_on_next_line = false\n" +
"assert_statement_wrap = off\n" +
"assignment_wrap = off\n" +
"binary_operation_sign_on_next_line = false\n" +
"binary_operation_wrap = off\n" +
"blank_lines_after_anonymous_class_header = 0\n" +
"blank_lines_after_class_header = 0\n" +
"blank_lines_after_imports = 1\n" +
"blank_lines_after_package = 1\n" +
"blank_lines_around_class = 1\n" +
"blank_lines_around_field = 0\n" +
"blank_lines_around_field_in_interface = 0\n" +
"blank_lines_around_initializer = 1\n" +
"blank_lines_around_method = 1\n" +
"blank_lines_around_method_in_interface = 1\n" +
"blank_lines_before_class_end = 0\n" +
"blank_lines_before_imports = 1\n" +
"blank_lines_before_method_body = 0\n" +
"blank_lines_before_package = 0\n" +
"block_comment_at_first_column = true\n" +
"brace_style = end_of_line\n" +
"call_parameters_new_line_after_left_paren = false\n" +
"call_parameters_right_paren_on_new_line = false\n" +
"call_parameters_wrap = on_every_item\n" +
"case_statement_on_new_line = true\n" +
"catch_on_new_line = false\n" +
"class_annotation_wrap = split_into_lines\n" +
"class_brace_style = end_of_line\n" +
"class_count_to_use_import_on_demand = 5\n" +
"class_names_in_javadoc = 1\n" +
"continuation_indent_size = 8\n" +
"do_not_indent_top_level_class_members = false\n" +
"do_not_wrap_after_single_annotation = false\n" +
"do_while_brace_force = never\n" +
"doc_add_blank_line_after_description = true\n" +
"doc_add_blank_line_after_param_comments = false\n" +
"doc_add_blank_line_after_return = false\n" +
"doc_add_p_tag_on_empty_lines = true\n" +
"doc_align_exception_comments = true\n" +
"doc_align_param_comments = true\n" +
"doc_do_not_wrap_if_one_line = false\n" +
"doc_enable_formatting = true\n" +
"doc_enable_leading_asterisks = true\n" +
"doc_indent_on_continuation = false\n" +
"doc_keep_empty_lines = true\n" +
"doc_keep_empty_parameter_tag = true\n" +
"doc_keep_empty_return_tag = true\n" +
"doc_keep_empty_throws_tag = true\n" +
"doc_keep_invalid_tags = true\n" +
"doc_param_description_on_new_line = false\n" +
"doc_preserve_line_breaks = false\n" +
"doc_use_throws_not_exception_tag = true\n" +
"else_on_new_line = false\n" +
"enum_constants_wrap = off\n" +
"extends_keyword_wrap = off\n" +
"extends_list_wrap = off\n" +
"field_annotation_wrap = split_into_lines\n" +
"field_name_prefix = m_\n" +
"finally_on_new_line = false\n" +
"for_brace_force = never\n" +
"for_statement_new_line_after_left_paren = false\n" +
"for_statement_right_paren_on_new_line = false\n" +
"for_statement_wrap = off\n" +
"generate_final_locals = false\n" +
"generate_final_parameters = false\n" +
"if_brace_force = never\n" +
"imports_layout = [*, blank_line, javax.**, java.**, blank_line, static *]\n" +
"indent_case_from_switch = true\n" +
"indent_size = 4\n" +
"indent_style = space\n" +
"insert_inner_class_imports = false\n" +
"insert_override_annotation = true\n" +
"keep_blank_lines_before_right_brace = 2\n" +
"keep_blank_lines_between_package_declaration_and_header = 2\n" +
"keep_blank_lines_in_code = 2\n" +
"keep_blank_lines_in_declarations = 2\n" +
"keep_control_statement_in_one_line = true\n" +
"keep_first_column_comment = true\n" +
"keep_indents_on_empty_lines = false\n" +
"keep_line_breaks = true\n" +
"keep_multiple_expressions_in_one_line = false\n" +
"keep_simple_blocks_in_one_line = false\n" +
"keep_simple_classes_in_one_line = false\n" +
"keep_simple_lambdas_in_one_line = false\n" +
"keep_simple_methods_in_one_line = false\n" +
"lambda_brace_style = end_of_line\n" +
"layout_static_imports_separately = true\n" +
"line_comment_add_space = false\n" +
"line_comment_at_first_column = true\n" +
"method_annotation_wrap = split_into_lines\n" +
"method_brace_style = end_of_line\n" +
"method_call_chain_wrap = off\n" +
"method_parameters_new_line_after_left_paren = false\n" +
"method_parameters_right_paren_on_new_line = false\n" +
"method_parameters_wrap = normal\n" +
"modifier_list_wrap = false\n" +
"names_count_to_use_import_on_demand = 3\n" +
"packages_to_use_import_on_demand = [java.awt.*, javax.swing.*]\n" +
"parameter_annotation_wrap = off\n" +
"parentheses_expression_new_line_after_left_paren = false\n" +
"parentheses_expression_right_paren_on_new_line = false\n" +
"place_assignment_sign_on_next_line = false\n" +
"prefer_longer_names = true\n" +
"prefer_parameters_wrap = false\n" +
"repeat_synchronized = true\n" +
"replace_instanceof_and_cast = false\n" +
"replace_null_check = true\n" +
"resource_list_new_line_after_left_paren = false\n" +
"resource_list_right_paren_on_new_line = false\n" +
"resource_list_wrap = off\n" +
"smart_tabs = false\n" +
"space_after_closing_angle_bracket_in_type_argument = false\n" +
"space_after_colon = true\n" +
"space_after_comma = true\n" +
"space_after_comma_in_type_arguments = true\n" +
"space_after_for_semicolon = true\n" +
"space_after_quest = true\n" +
"space_after_type_cast = true\n" +
"space_before_annotation_array_initializer_left_brace = false\n" +
"space_before_anotation_parameter_list = false\n" +
"space_before_array_initializer_left_brace = false\n" +
"space_before_catch_keyword = true\n" +
"space_before_catch_left_brace = true\n" +
"space_before_catch_parentheses = true\n" +
"space_before_class_left_brace = true\n" +
"space_before_colon = true\n" +
"space_before_colon_in_foreach = true\n" +
"space_before_comma = false\n" +
"space_before_do_left_brace = true\n" +
"space_before_else_keyword = true\n" +
"space_before_else_left_brace = true\n" +
"space_before_finally_keyword = true\n" +
"space_before_finally_left_brace = true\n" +
"space_before_for_left_brace = true\n" +
"space_before_for_parentheses = true\n" +
"space_before_for_semicolon = false\n" +
"space_before_if_left_brace = true\n" +
"space_before_if_parentheses = true\n" +
"space_before_method_call_parentheses = false\n" +
"space_before_method_left_brace = true\n" +
"space_before_method_parentheses = false\n" +
"space_before_opening_angle_bracket_in_type_parameter = false\n" +
"space_before_quest = true\n" +
"space_before_switch_left_brace = true\n" +
"space_before_switch_parentheses = true\n" +
"space_before_synchronized_left_brace = true\n" +
"space_before_synchronized_parentheses = true\n" +
"space_before_try_left_brace = true\n" +
"space_before_try_parentheses = true\n" +
"space_before_type_parameter_list = false\n" +
"space_before_while_keyword = true\n" +
"space_before_while_left_brace = true\n" +
"space_before_while_parentheses = true\n" +
"space_inside_one_line_enum_braces = false\n" +
"spaces_around_additive_operators = true\n" +
"spaces_around_assignment_operators = true\n" +
"spaces_around_bitwise_operators = true\n" +
"spaces_around_equality_operators = true\n" +
"spaces_around_lambda_arrow = true\n" +
"spaces_around_logical_operators = true\n" +
"spaces_around_method_ref_dbl_colon = false\n" +
"spaces_around_multiplicative_operators = true\n" +
"spaces_around_relational_operators = true\n" +
"spaces_around_shift_operators = true\n" +
"spaces_around_type_bounds_in_type_parameters = true\n" +
"spaces_around_unary_operator = false\n" +
"spaces_within_angle_brackets = false\n" +
"spaces_within_annotation_parentheses = false\n" +
"spaces_within_array_initializer_braces = false\n" +
"spaces_within_braces = false\n" +
"spaces_within_brackets = false\n" +
"spaces_within_cast_parentheses = false\n" +
"spaces_within_catch_parentheses = false\n" +
"spaces_within_empty_array_initializer_braces = false\n" +
"spaces_within_empty_method_call_parentheses = false\n" +
"spaces_within_empty_method_parentheses = false\n" +
"spaces_within_for_parentheses = false\n" +
"spaces_within_if_parentheses = false\n" +
"spaces_within_method_call_parentheses = false\n" +
"spaces_within_method_parentheses = false\n" +
"spaces_within_parentheses = false\n" +
"spaces_within_switch_parentheses = false\n" +
"spaces_within_synchronized_parentheses = false\n" +
"spaces_within_try_parentheses = false\n" +
"spaces_within_while_parentheses = false\n" +
"special_else_if_treatment = true\n" +
"static_field_name_suffix = _s\n" +
"subclass_name_suffix = Impl\n" +
"tab_width = 4\n" +
"ternary_operation_signs_on_next_line = false\n" +
"ternary_operation_wrap = off\n" +
"test_name_suffix = Test\n" +
"throws_keyword_wrap = off\n" +
"throws_list_wrap = off\n" +
"use_external_annotations = false\n" +
"use_fq_class_names = false\n" +
"use_single_class_imports = true\n" +
"variable_annotation_wrap = off\n" +
"visibility = public\n" +
"while_brace_force = never\n" +
"while_on_new_line = false\n" +
"wrap_comments = false\n" +
"wrap_first_method_in_call_chain = false\n" +
"wrap_long_lines = false\n",
builder.toString());
CodeStyleSchemeJsonExporter exporter = new CodeStyleSchemeJsonExporter();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
exporter.exportScheme(testScheme, outputStream, Collections.singletonList("java"));
String expected = loadExpected("json");
assertEquals(expected, outputStream.toString());
}
public void testSetProperties() {
@@ -374,4 +142,10 @@ public class JavaCodeStyleSettingsTest extends CodeStyleTestCase {
protected String getBasePath() {
return PathManagerEx.getTestDataPath() + "/codeStyle";
}
@Nullable
@Override
protected String getTestDir() {
return "";
}
}
@@ -87,6 +87,8 @@ public abstract class CodeStyleTestCase extends LightPlatformTestCase {
protected CodeStyleScheme createTestScheme() {
return new CodeStyleScheme() {
private final CodeStyleSettings mySettings = new CodeStyleSettings();
@NotNull
@Override
public String getName() {
@@ -101,7 +103,7 @@ public abstract class CodeStyleTestCase extends LightPlatformTestCase {
@NotNull
@Override
public CodeStyleSettings getCodeStyleSettings() {
return new CodeStyleSettings();
return mySettings;
}
};
}