[java-settings] IDEA-369838 project code style xml changed after introducing module imports

GitOrigin-RevId: 5b1ae9120367dc5b266fca9125fbb0dbe5f24a56
This commit is contained in:
Mikhail Pyltsin
2025-05-08 15:51:39 +00:00
committed by intellij-monorepo-bot
parent 5fbb85b2a2
commit 95c9932fa0
6 changed files with 592 additions and 19 deletions
@@ -186,6 +186,7 @@ public class JavaCodeStyleSettings extends CustomCodeStyleSettings implements Im
@Property(externalName = "imports_layout")
public PackageEntryTable IMPORT_LAYOUT_TABLE = new PackageEntryTable();
private boolean updatedModuleImportLayout = false;
/**
* <pre>
@@ -389,7 +390,7 @@ public class JavaCodeStyleSettings extends CustomCodeStyleSettings implements Im
private void initImportsByDefault() {
PACKAGES_TO_USE_IMPORT_ON_DEMAND.addEntry(new PackageEntry(false, "java.awt", false));
PACKAGES_TO_USE_IMPORT_ON_DEMAND.addEntry(new PackageEntry(false,"javax.swing", false));
PACKAGES_TO_USE_IMPORT_ON_DEMAND.addEntry(new PackageEntry(false, "javax.swing", false));
initImportLayout();
}
@@ -499,6 +500,7 @@ public class JavaCodeStyleSettings extends CustomCodeStyleSettings implements Im
}
if (!ContainerUtil.exists(entries, entry -> entry == PackageEntry.ALL_MODULE_IMPORTS)) {
IMPORT_LAYOUT_TABLE.insertEntryAt(PackageEntry.ALL_MODULE_IMPORTS, 0);
updatedModuleImportLayout = true;
}
}
}
@@ -508,9 +510,34 @@ public class JavaCodeStyleSettings extends CustomCodeStyleSettings implements Im
super.writeExternal(parentElement, parentSettings);
writeExternalCollection(parentElement, myRepeatAnnotations, REPEAT_ANNOTATIONS, REPEAT_ANNOTATIONS_ITEM);
writeExternalCollection(parentElement, myDoNotImportInner, DO_NOT_IMPORT_INNER, DO_NOT_IMPORT_INNER_ITEM);
//don't change setting file if it was generated and not changed
if (updatedModuleImportLayout && IMPORT_LAYOUT_TABLE.getEntries() != null &&
IMPORT_LAYOUT_TABLE.getEntries()[0] == PackageEntry.ALL_MODULE_IMPORTS) {
deleteFirstModuleFromImportLayoutTable(parentElement);
}
writeVersion(parentElement);
}
private void deleteFirstModuleFromImportLayoutTable(Element parentElement) {
Element child = parentElement.getChild(getTagName());
if (child == null) return;
Element table = null;
for (Element option : child.getChildren("option")) {
if (option.getAttributeValue("name").equals("IMPORT_LAYOUT_TABLE")) {
table = option;
break;
}
}
if (table == null) return;
Element value = table.getChild("value");
if (value == null) return;
List<Element> entries = value.getChildren();
if (entries == null || entries.isEmpty()) return;
Element firstEntry = entries.get(0);
if (!"true".equals(firstEntry.getAttributeValue("module"))) return;
firstEntry.detach();
}
/**
* Appends {@code version} attribute to the {@code JavaCodeStyleSettings} tag in {@link CodeStyleScheme}
@@ -18,7 +18,6 @@ public class JavaPackageEntryTableAccessor extends ValueListPropertyAccessor<Pac
public static final String STATIC_PREFIX = "$";
public static final String MODULE_PREFIX = "@";
private final Field myField;
public JavaPackageEntryTableAccessor(@NotNull Object object, @NotNull Field field) {
super(object, field);
myField = field;
@@ -80,7 +79,9 @@ public class JavaPackageEntryTableAccessor extends ValueListPropertyAccessor<Pac
@Override
protected @NotNull List<String> toExternal(@NotNull PackageEntryTable value) {
List<String> externalList = new ArrayList<>();
for (PackageEntry entry : value.getEntries()) {
PackageEntry[] entries = value.getEntries();
for (int i = 0; i < entries.length; i++) {
PackageEntry entry = entries[i];
if (entry == PackageEntry.BLANK_LINE_ENTRY) {
externalList.add(String.valueOf(BLANK_LINE_CHAR));
}
@@ -90,6 +91,11 @@ public class JavaPackageEntryTableAccessor extends ValueListPropertyAccessor<Pac
entryBuilder.append(STATIC_PREFIX);
}
if (entry == PackageEntry.ALL_MODULE_IMPORTS) {
Object dataObject = getDataObject();
//do not save if it was generated
if (i == 0 && dataObject instanceof JavaCodeStyleSettings) {
continue;
}
entryBuilder.append(MODULE_PREFIX);
}
if (entry.isSpecial()) {
@@ -108,7 +108,6 @@
"generate_use_type_annotation_before_type": true,
"if_brace_force": "never",
"imports_layout": [
"@*",
"*",
"|",
"javax.**",
@@ -0,0 +1,293 @@
{
"schemeName": "Test",
"version": "1.0",
"codeStyle": {
"java": {
"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_deconstruction_list_components": true,
"align_multiline_extends_list": false,
"align_multiline_for": true,
"align_multiline_method_parentheses": false,
"align_multiline_parameters": true,
"align_multiline_parameters_in_calls": false,
"align_multiline_parenthesized_expression": false,
"align_multiline_records": true,
"align_multiline_resources": true,
"align_multiline_ternary_operation": false,
"align_multiline_text_blocks": false,
"align_multiline_throws_list": false,
"align_subsequent_simple_methods": false,
"align_throws_keyword": false,
"align_types_in_multi_catch": true,
"annotation_new_line_in_record_component": 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_field_with_annotations": 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,
"blank_lines_between_record_components": 0,
"block_brace_style": "end_of_line",
"block_comment_add_space": false,
"block_comment_at_first_column": true,
"builder_methods": [
""
],
"call_parameters_new_line_after_left_paren": false,
"call_parameters_right_paren_on_new_line": false,
"call_parameters_wrap": "off",
"case_statement_on_separate_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,
"deconstruction_list_wrap": "normal",
"do_not_indent_top_level_class_members": false,
"do_not_wrap_after_single_annotation": false,
"do_not_wrap_after_single_annotation_in_parameter": 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",
"enum_field_annotation_wrap": "off",
"extends_keyword_wrap": "off",
"extends_list_wrap": "off",
"field_annotation_wrap": "split_into_lines",
"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,
"generate_use_type_annotation_before_type": true,
"if_brace_force": "never",
"imports_layout": [
"*",
"@*",
"com.**",
"|",
"edu.**",
"|",
"net.**",
"|",
"org.**",
"|",
"javax.**",
"|",
"java.**",
"|",
"$*"
],
"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_builder_methods_indents": false,
"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,
"label_indent_absolute": false,
"label_indent_size": 0,
"lambda_brace_style": "end_of_line",
"layout_on_demand_import_from_same_package_first": true,
"layout_static_imports_separately": true,
"line_comment_add_space": false,
"line_comment_add_space_on_reformat": 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": "off",
"modifier_list_wrap": false,
"multi_catch_types_wrap": "normal",
"names_count_to_use_import_on_demand": 3,
"new_line_after_lparen_in_annotation": false,
"new_line_after_lparen_in_deconstruction_pattern": true,
"new_line_after_lparen_in_record_header": false,
"new_line_when_body_is_presented": false,
"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,
"preserve_module_imports": true,
"record_components_wrap": "normal",
"repeat_annotations": [],
"repeat_synchronized": true,
"replace_instanceof_and_cast": false,
"replace_null_check": true,
"replace_sum_lambda_with_method_ref": true,
"resource_list_new_line_after_left_paren": false,
"resource_list_right_paren_on_new_line": false,
"resource_list_wrap": "off",
"rparen_on_new_line_in_annotation": false,
"rparen_on_new_line_in_deconstruction_pattern": true,
"rparen_on_new_line_in_record_header": false,
"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_annotation_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_deconstruction_list": 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,
"space_within_empty_array_initializer_braces": false,
"space_within_empty_method_call_parentheses": false,
"space_within_empty_method_parentheses": false,
"spaces_around_additive_operators": true,
"spaces_around_annotation_eq": 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_inside_block_braces_when_body_is_present": 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_deconstruction_list": 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_record_header": 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,
"subclass_name_suffix": "Impl",
"switch_expressions_wrap": "normal",
"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_relative_indents": false,
"use_single_class_imports": true,
"variable_annotation_wrap": "off",
"visibility": "public",
"visual_guides": [],
"while_brace_force": "never",
"while_on_new_line": false,
"wrap_comments": false,
"wrap_first_method_in_call_chain": false,
"wrap_long_lines": false,
"wrap_semicolon_after_call_chain": false
}
}
}
@@ -0,0 +1,21 @@
<code_scheme name="Code Style">
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="" withSubpackages="true" static="false" />
<package name="" withSubpackages="true" static="false" module="true" />
<package name="com" withSubpackages="true" static="false" />
<emptyLine />
<package name="edu" withSubpackages="true" static="false" />
<emptyLine />
<package name="net" withSubpackages="true" static="false" />
<emptyLine />
<package name="org" withSubpackages="true" static="false" />
<emptyLine />
<package name="javax" withSubpackages="true" static="false" />
<emptyLine />
<package name="java" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="true" />
</value>
</option>
</code_scheme>
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.java.psi.codeStyle;
import com.intellij.application.options.CodeStyle;
@@ -22,8 +8,11 @@ import com.intellij.ide.codeStyleSettings.CodeStyleTestCase;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.application.ex.PathManagerEx;
import com.intellij.openapi.options.SchemeImportException;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.psi.codeStyle.*;
import com.intellij.psi.impl.source.codeStyle.json.CodeStyleSchemeJsonExporter;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -92,6 +81,244 @@ public class JavaCodeStyleSettingsTest extends CodeStyleTestCase {
compareWithExpected(outputStream.toString(), "json");
}
public void testNotFirstImportModule() throws IOException {
CodeStyleScheme testScheme = new CodeStyleScheme() {
@NotNull
@Override
public String getName() {
return "Test";
}
@Override
public boolean isDefault() {
return false;
}
@NotNull
@Override
public CodeStyleSettings getCodeStyleSettings() {
try {
return importSettings();
}
catch (SchemeImportException e) {
throw new RuntimeException(e);
}
}
};
CodeStyleSchemeJsonExporter exporter = new CodeStyleSchemeJsonExporter();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
exporter.exportScheme(testScheme, outputStream, Collections.singletonList("java"));
compareWithExpected(outputStream.toString(), "json");
}
public void testFirstNotImportedImportModule() throws IOException, JDOMException {
CodeStyleSettings originalRoot = CodeStyle.getSettings(getProject());
JavaCodeStyleSettings settings = originalRoot.getCustomSettings(JavaCodeStyleSettings.class);
String text = """
<root>
<JavaCodeStyleSettings>
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="" withSubpackages="true" static="true" />
<package name="" withSubpackages="true" static="false" />
<package name="com" withSubpackages="true" static="false" />
</value>
</option>
</JavaCodeStyleSettings>
</root>
""";
settings.readExternal(JDOMUtil.load(text));
Element root = new Element("root");
PackageEntry moduleEntry = settings.IMPORT_LAYOUT_TABLE.getEntryAt(0);
assertSame(PackageEntry.ALL_MODULE_IMPORTS, moduleEntry);
settings.IMPORT_LAYOUT_TABLE.addEntry(new PackageEntry(true, "org.foo", true));
settings.writeExternal(root, new JavaCodeStyleSettings(originalRoot));
String actual = """
<root>
<JavaCodeStyleSettings>
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="" withSubpackages="true" static="true" />
<package name="" withSubpackages="true" static="false" />
<package name="com" withSubpackages="true" static="false" />
<package name="org.foo" withSubpackages="true" static="true" />
</value>
</option>
</JavaCodeStyleSettings>
</root>""";
assertEquals(actual, JDOMUtil.writeElement(root));
}
public void testMovedFirstNotImportedImportModule() throws IOException, JDOMException {
CodeStyleSettings originalRoot = CodeStyle.getSettings(getProject());
JavaCodeStyleSettings settings = originalRoot.getCustomSettings(JavaCodeStyleSettings.class);
String text = """
<root>
<JavaCodeStyleSettings>
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="" withSubpackages="true" static="true" />
<package name="" withSubpackages="true" static="false" />
<package name="com" withSubpackages="true" static="false" />
</value>
</option>
</JavaCodeStyleSettings>
</root>
""";
settings.readExternal(JDOMUtil.load(text));
Element root = new Element("root");
PackageEntry moduleEntry = settings.IMPORT_LAYOUT_TABLE.getEntryAt(0);
assertSame(PackageEntry.ALL_MODULE_IMPORTS, moduleEntry);
settings.IMPORT_LAYOUT_TABLE.removeEntryAt(0);
settings.IMPORT_LAYOUT_TABLE.insertEntryAt(moduleEntry, 1);
settings.writeExternal(root, new JavaCodeStyleSettings(originalRoot));
String actual = """
<root>
<JavaCodeStyleSettings>
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="" withSubpackages="true" static="true" />
<package name="" withSubpackages="true" static="false" module="true" />
<package name="" withSubpackages="true" static="false" />
<package name="com" withSubpackages="true" static="false" />
</value>
</option>
</JavaCodeStyleSettings>
</root>""";
assertEquals(actual, JDOMUtil.writeElement(root));
}
public void testMovedFirstImportedImportModule() throws IOException, JDOMException {
CodeStyleSettings originalRoot = CodeStyle.getSettings(getProject());
JavaCodeStyleSettings settings = originalRoot.getCustomSettings(JavaCodeStyleSettings.class);
String text = """
<root>
<JavaCodeStyleSettings>
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="" withSubpackages="true" static="false" module="true" />
<package name="" withSubpackages="true" static="true" />
<package name="" withSubpackages="true" static="false" />
<package name="com" withSubpackages="true" static="false" />
</value>
</option>
</JavaCodeStyleSettings>
</root>
""";
settings.readExternal(JDOMUtil.load(text));
Element root = new Element("root");
PackageEntry moduleEntry = settings.IMPORT_LAYOUT_TABLE.getEntryAt(0);
assertSame(PackageEntry.ALL_MODULE_IMPORTS, moduleEntry);
settings.IMPORT_LAYOUT_TABLE.removeEntryAt(0);
settings.IMPORT_LAYOUT_TABLE.insertEntryAt(moduleEntry, 1);
settings.writeExternal(root, new JavaCodeStyleSettings(originalRoot));
String actual = """
<root>
<JavaCodeStyleSettings>
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="" withSubpackages="true" static="true" />
<package name="" withSubpackages="true" static="false" module="true" />
<package name="" withSubpackages="true" static="false" />
<package name="com" withSubpackages="true" static="false" />
</value>
</option>
</JavaCodeStyleSettings>
</root>""";
assertEquals(actual, JDOMUtil.writeElement(root));
}
public void testMovedNotFirstImportedImportModule() throws IOException, JDOMException {
CodeStyleSettings originalRoot = CodeStyle.getSettings(getProject());
JavaCodeStyleSettings settings = originalRoot.getCustomSettings(JavaCodeStyleSettings.class);
String text = """
<root>
<JavaCodeStyleSettings>
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="" withSubpackages="true" static="true" />
<package name="" withSubpackages="true" static="false" />
<package name="" withSubpackages="true" static="false" module="true" />
<package name="com" withSubpackages="true" static="false" />
</value>
</option>
</JavaCodeStyleSettings>
</root>
""";
settings.readExternal(JDOMUtil.load(text));
Element root = new Element("root");
PackageEntry notModuleEntry = settings.IMPORT_LAYOUT_TABLE.getEntryAt(0);
assertNotSame(PackageEntry.ALL_MODULE_IMPORTS, notModuleEntry);
settings.IMPORT_LAYOUT_TABLE.removeEntryAt(0);
settings.IMPORT_LAYOUT_TABLE.insertEntryAt(notModuleEntry, 1);
settings.writeExternal(root, new JavaCodeStyleSettings(originalRoot));
String actual = """
<root>
<JavaCodeStyleSettings>
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="" withSubpackages="true" static="false" />
<package name="" withSubpackages="true" static="true" />
<package name="" withSubpackages="true" static="false" module="true" />
<package name="com" withSubpackages="true" static="false" />
</value>
</option>
</JavaCodeStyleSettings>
</root>""";
assertEquals(actual, JDOMUtil.writeElement(root));
}
public void testFirstImportedImportModule() throws IOException, JDOMException {
CodeStyleSettings originalRoot = CodeStyle.getSettings(getProject());
JavaCodeStyleSettings settings = originalRoot.getCustomSettings(JavaCodeStyleSettings.class);
String text = """
<root>
<JavaCodeStyleSettings>
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="" withSubpackages="true" static="false" module="true" />
<package name="" withSubpackages="true" static="true" />
<package name="" withSubpackages="true" static="false" />
<package name="com" withSubpackages="true" static="false" />
</value>
</option>
</JavaCodeStyleSettings>
</root>
""";
settings.readExternal(JDOMUtil.load(text));
Element root = new Element("root");
PackageEntryTable table = settings.IMPORT_LAYOUT_TABLE;
assertSize(4,table.getEntries());
PackageEntry moduleEntry = table.getEntryAt(0);
assertSame(PackageEntry.ALL_MODULE_IMPORTS, moduleEntry);
table.addEntry(new PackageEntry(true, "org.foo", true));
settings.writeExternal(root, new JavaCodeStyleSettings(originalRoot));
String actual = """
<root>
<JavaCodeStyleSettings>
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="" withSubpackages="true" static="false" module="true" />
<package name="" withSubpackages="true" static="true" />
<package name="" withSubpackages="true" static="false" />
<package name="com" withSubpackages="true" static="false" />
<package name="org.foo" withSubpackages="true" static="true" />
</value>
</option>
</JavaCodeStyleSettings>
</root>""";
assertEquals(actual, JDOMUtil.writeElement(root));
}
public void testSetProperties() {
final CodeStyleSettings settings = getCurrentCodeStyleSettings();
AbstractCodeStylePropertyMapper mapper =