mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-imports] IDEA-368382 incorrect place for module import
GitOrigin-RevId: ce6ec1c65d5777e5e3059093fdd01baf24f95e50
This commit is contained in:
committed by
intellij-monorepo-bot
parent
203b4d4a70
commit
abca56d632
@@ -380,6 +380,10 @@ 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));
|
||||
initImportLayout();
|
||||
}
|
||||
|
||||
private void initImportLayout() {
|
||||
IMPORT_LAYOUT_TABLE.addEntry(PackageEntry.ALL_MODULE_IMPORTS);
|
||||
IMPORT_LAYOUT_TABLE.addEntry(PackageEntry.ALL_OTHER_IMPORTS_ENTRY);
|
||||
IMPORT_LAYOUT_TABLE.addEntry(PackageEntry.BLANK_LINE_ENTRY);
|
||||
@@ -458,8 +462,31 @@ public class JavaCodeStyleSettings extends CustomCodeStyleSettings implements Im
|
||||
myOldVersion = myVersion = CustomCodeStyleSettingsUtils.readVersion(parentElement.getChild(getTagName()));
|
||||
myIsInitialized = true;
|
||||
PackageEntry[] entries = IMPORT_LAYOUT_TABLE.getEntries();
|
||||
if (!ContainerUtil.exists(entries, entry -> entry == PackageEntry.ALL_MODULE_IMPORTS)) {
|
||||
IMPORT_LAYOUT_TABLE.setEntryAt(PackageEntry.ALL_MODULE_IMPORTS, 0);
|
||||
//if it is broken, try to restore
|
||||
if (entries.length == 0) {
|
||||
initImportLayout();
|
||||
}
|
||||
else {
|
||||
//if something is missed, restore it
|
||||
if (!ContainerUtil.exists(entries, entry -> entry == PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY)) {
|
||||
if (entries[0] == PackageEntry.ALL_MODULE_IMPORTS) {
|
||||
IMPORT_LAYOUT_TABLE.insertEntryAt(PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY, 1);
|
||||
}
|
||||
else {
|
||||
IMPORT_LAYOUT_TABLE.insertEntryAt(PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY, 0);
|
||||
}
|
||||
}
|
||||
if (!ContainerUtil.exists(entries, entry -> entry == PackageEntry.ALL_OTHER_IMPORTS_ENTRY)) {
|
||||
if (entries[0] == PackageEntry.ALL_MODULE_IMPORTS) {
|
||||
IMPORT_LAYOUT_TABLE.insertEntryAt(PackageEntry.ALL_OTHER_IMPORTS_ENTRY, 1);
|
||||
}
|
||||
else {
|
||||
IMPORT_LAYOUT_TABLE.insertEntryAt(PackageEntry.ALL_OTHER_IMPORTS_ENTRY, 0);
|
||||
}
|
||||
}
|
||||
if (!ContainerUtil.exists(entries, entry -> entry == PackageEntry.ALL_MODULE_IMPORTS)) {
|
||||
IMPORT_LAYOUT_TABLE.insertEntryAt(PackageEntry.ALL_MODULE_IMPORTS, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<code_scheme name="Project" version="173">
|
||||
<JavaCodeStyleSettings>
|
||||
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="100" />
|
||||
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="100" />
|
||||
<option name="IMPORT_LAYOUT_TABLE">
|
||||
<value>
|
||||
</value>
|
||||
</option>
|
||||
</JavaCodeStyleSettings>
|
||||
</code_scheme>
|
||||
@@ -0,0 +1,19 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<JavaCodeStyleSettings>
|
||||
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="100" />
|
||||
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="100" />
|
||||
<option name="IMPORT_LAYOUT_TABLE">
|
||||
<value>
|
||||
<package name="" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<emptyLine />
|
||||
<package name="javax" withSubpackages="true" static="false" />
|
||||
<package name="java" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="" withSubpackages="true" static="true" />
|
||||
</value>
|
||||
</option>
|
||||
</JavaCodeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
||||
@@ -0,0 +1,15 @@
|
||||
<code_scheme name="Project" version="173">
|
||||
<JavaCodeStyleSettings>
|
||||
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="100" />
|
||||
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="100" />
|
||||
<option name="IMPORT_LAYOUT_TABLE">
|
||||
<value>
|
||||
<emptyLine />
|
||||
<emptyLine />
|
||||
<package name="javax" withSubpackages="true" static="false" />
|
||||
<package name="java" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="" withSubpackages="true" static="true" />
|
||||
</value> </option>
|
||||
</JavaCodeStyleSettings>
|
||||
</code_scheme>
|
||||
@@ -0,0 +1,14 @@
|
||||
<code_scheme name="Project" version="173">
|
||||
<JavaCodeStyleSettings>
|
||||
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="100" />
|
||||
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="100" />
|
||||
<option name="IMPORT_LAYOUT_TABLE">
|
||||
<value>
|
||||
<emptyLine />
|
||||
<emptyLine />
|
||||
<package name="javax" withSubpackages="true" static="false" />
|
||||
<package name="java" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
</value> </option>
|
||||
</JavaCodeStyleSettings>
|
||||
</code_scheme>
|
||||
@@ -0,0 +1,16 @@
|
||||
<code_scheme name="Project" version="173">
|
||||
<JavaCodeStyleSettings>
|
||||
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="100" />
|
||||
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="100" />
|
||||
<option name="IMPORT_LAYOUT_TABLE">
|
||||
<value>
|
||||
<emptyLine />
|
||||
<emptyLine />
|
||||
<package name="javax" withSubpackages="true" static="false" />
|
||||
<package name="java" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="" withSubpackages="true" static="false" module="true" />
|
||||
<package name="" withSubpackages="true" static="true" />
|
||||
</value> </option>
|
||||
</JavaCodeStyleSettings>
|
||||
</code_scheme>
|
||||
@@ -0,0 +1,16 @@
|
||||
<code_scheme name="Project" version="173">
|
||||
<JavaCodeStyleSettings>
|
||||
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="100" />
|
||||
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="100" />
|
||||
<option name="IMPORT_LAYOUT_TABLE">
|
||||
<value>
|
||||
<package name="" withSubpackages="true" static="false" module="true" />
|
||||
<emptyLine />
|
||||
<emptyLine />
|
||||
<package name="javax" withSubpackages="true" static="false" />
|
||||
<package name="java" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="" withSubpackages="true" static="false" />
|
||||
</value> </option>
|
||||
</JavaCodeStyleSettings>
|
||||
</code_scheme>
|
||||
+106
-2
@@ -76,7 +76,7 @@ public class JavaCodeStyleSettingsTest extends CodeStyleTestCase {
|
||||
CodeStyleScheme testScheme = createTestScheme();
|
||||
final CodeStyleSettings settings = testScheme.getCodeStyleSettings();
|
||||
final CommonCodeStyleSettings commonJavaSettings = settings.getCommonSettings(JavaLanguage.INSTANCE);
|
||||
settings.setSoftMargins(JavaLanguage.INSTANCE, Arrays.asList(11,22));
|
||||
settings.setSoftMargins(JavaLanguage.INSTANCE, Arrays.asList(11, 22));
|
||||
commonJavaSettings.METHOD_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
|
||||
commonJavaSettings.CALL_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_ON_EVERY_ITEM;
|
||||
commonJavaSettings.WRAP_ON_TYPING = CommonCodeStyleSettings.WrapOnTyping.WRAP.intValue;
|
||||
@@ -122,7 +122,7 @@ public class JavaCodeStyleSettingsTest extends CodeStyleTestCase {
|
||||
assertEquals("com.jetbrains.First", repeatAnno.get(0));
|
||||
assertEquals("com.jetbrains.Second", repeatAnno.get(1));
|
||||
}
|
||||
|
||||
|
||||
private static void setSimple(@NotNull AbstractCodeStylePropertyMapper mapper, @NotNull String name, @NotNull String value) {
|
||||
CodeStylePropertyAccessor accessor = mapper.getAccessor(name);
|
||||
assertNotNull(name + " not found", accessor);
|
||||
@@ -154,6 +154,110 @@ public class JavaCodeStyleSettingsTest extends CodeStyleTestCase {
|
||||
assertEquals(7, customSettings.BLANK_LINES_AROUND_FIELD_WITH_ANNOTATIONS);
|
||||
}
|
||||
|
||||
public void testWithoutModulesAndOtherImport() throws SchemeImportException {
|
||||
CodeStyleSettings settings = importSettings();
|
||||
|
||||
JavaCodeStyleSettings customSettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
|
||||
|
||||
PackageEntryTable table = customSettings.IMPORT_LAYOUT_TABLE;
|
||||
assertSize(8, table.getEntries());
|
||||
|
||||
assertEquals(PackageEntry.ALL_MODULE_IMPORTS, table.getEntryAt(0));
|
||||
assertEquals(PackageEntry.ALL_OTHER_IMPORTS_ENTRY, table.getEntryAt(1));
|
||||
assertEquals(PackageEntry.BLANK_LINE_ENTRY, table.getEntryAt(2));
|
||||
assertEquals(PackageEntry.BLANK_LINE_ENTRY, table.getEntryAt(3));
|
||||
assertEquals("javax", table.getEntryAt(4).getPackageName());
|
||||
assertEquals("java", table.getEntryAt(5).getPackageName());
|
||||
assertEquals(PackageEntry.BLANK_LINE_ENTRY, table.getEntryAt(6));
|
||||
assertEquals(PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY, table.getEntryAt(7));
|
||||
}
|
||||
|
||||
public void testWithoutModulesAndOtherImportAndStaticImport() throws SchemeImportException {
|
||||
CodeStyleSettings settings = importSettings();
|
||||
|
||||
JavaCodeStyleSettings customSettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
|
||||
|
||||
PackageEntryTable table = customSettings.IMPORT_LAYOUT_TABLE;
|
||||
assertSize(8, table.getEntries());
|
||||
|
||||
assertEquals(PackageEntry.ALL_MODULE_IMPORTS, table.getEntryAt(0));
|
||||
assertEquals(PackageEntry.ALL_OTHER_IMPORTS_ENTRY, table.getEntryAt(1));
|
||||
assertEquals(PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY, table.getEntryAt(2));
|
||||
assertEquals(PackageEntry.BLANK_LINE_ENTRY, table.getEntryAt(3));
|
||||
assertEquals(PackageEntry.BLANK_LINE_ENTRY, table.getEntryAt(4));
|
||||
assertEquals("javax", table.getEntryAt(5).getPackageName());
|
||||
assertEquals("java", table.getEntryAt(6).getPackageName());
|
||||
assertEquals(PackageEntry.BLANK_LINE_ENTRY, table.getEntryAt(7));
|
||||
}
|
||||
|
||||
public void testWithoutModules() throws SchemeImportException {
|
||||
CodeStyleSettings settings = importSettings();
|
||||
|
||||
JavaCodeStyleSettings customSettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
|
||||
|
||||
PackageEntryTable table = customSettings.IMPORT_LAYOUT_TABLE;
|
||||
assertSize(8, table.getEntries());
|
||||
assertEquals(PackageEntry.ALL_MODULE_IMPORTS, table.getEntryAt(0));
|
||||
assertEquals(PackageEntry.ALL_OTHER_IMPORTS_ENTRY, table.getEntryAt(1));
|
||||
assertEquals(PackageEntry.BLANK_LINE_ENTRY, table.getEntryAt(2));
|
||||
assertEquals(PackageEntry.BLANK_LINE_ENTRY, table.getEntryAt(3));
|
||||
assertEquals("javax", table.getEntryAt(4).getPackageName());
|
||||
assertEquals("java", table.getEntryAt(5).getPackageName());
|
||||
assertEquals(PackageEntry.BLANK_LINE_ENTRY, table.getEntryAt(6));
|
||||
assertEquals(PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY, table.getEntryAt(7));
|
||||
}
|
||||
|
||||
public void testWithoutOtherImportWithModule() throws SchemeImportException {
|
||||
CodeStyleSettings settings = importSettings();
|
||||
|
||||
JavaCodeStyleSettings customSettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
|
||||
|
||||
PackageEntryTable table = customSettings.IMPORT_LAYOUT_TABLE;
|
||||
assertSize(8, table.getEntries());
|
||||
assertEquals(PackageEntry.ALL_OTHER_IMPORTS_ENTRY, table.getEntryAt(0));
|
||||
assertEquals(PackageEntry.BLANK_LINE_ENTRY, table.getEntryAt(1));
|
||||
assertEquals(PackageEntry.BLANK_LINE_ENTRY, table.getEntryAt(2));
|
||||
assertEquals("javax", table.getEntryAt(3).getPackageName());
|
||||
assertEquals("java", table.getEntryAt(4).getPackageName());
|
||||
assertEquals(PackageEntry.BLANK_LINE_ENTRY, table.getEntryAt(5));
|
||||
assertEquals(PackageEntry.ALL_MODULE_IMPORTS, table.getEntryAt(6));
|
||||
assertEquals(PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY, table.getEntryAt(7));
|
||||
}
|
||||
|
||||
public void testWithoutStaticImportWithoutModule() throws SchemeImportException {
|
||||
CodeStyleSettings settings = importSettings();
|
||||
|
||||
JavaCodeStyleSettings customSettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
|
||||
|
||||
PackageEntryTable table = customSettings.IMPORT_LAYOUT_TABLE;
|
||||
assertSize(8, table.getEntries());
|
||||
|
||||
assertEquals(PackageEntry.ALL_MODULE_IMPORTS, table.getEntryAt(0));
|
||||
assertEquals(PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY, table.getEntryAt(1));
|
||||
assertEquals(PackageEntry.BLANK_LINE_ENTRY, table.getEntryAt(2));
|
||||
assertEquals(PackageEntry.BLANK_LINE_ENTRY, table.getEntryAt(3));
|
||||
assertEquals("javax", table.getEntryAt(4).getPackageName());
|
||||
assertEquals("java", table.getEntryAt(5).getPackageName());
|
||||
assertEquals(PackageEntry.BLANK_LINE_ENTRY, table.getEntryAt(6));
|
||||
assertEquals(PackageEntry.ALL_OTHER_IMPORTS_ENTRY, table.getEntryAt(7));
|
||||
}
|
||||
|
||||
public void testEmptyConfigImport() throws SchemeImportException {
|
||||
CodeStyleSettings settings = importSettings();
|
||||
|
||||
JavaCodeStyleSettings customSettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
|
||||
|
||||
PackageEntryTable table = customSettings.IMPORT_LAYOUT_TABLE;
|
||||
assertSize(7, table.getEntries());
|
||||
assertEquals(PackageEntry.ALL_MODULE_IMPORTS, table.getEntryAt(0));
|
||||
assertEquals(PackageEntry.ALL_OTHER_IMPORTS_ENTRY, table.getEntryAt(1));
|
||||
assertEquals(PackageEntry.BLANK_LINE_ENTRY, table.getEntryAt(2));
|
||||
assertEquals("javax", table.getEntryAt(3).getPackageName());
|
||||
assertEquals("java", table.getEntryAt(4).getPackageName());
|
||||
assertEquals(PackageEntry.BLANK_LINE_ENTRY, table.getEntryAt(5));
|
||||
assertEquals(PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY, table.getEntryAt(6));
|
||||
}
|
||||
|
||||
private static boolean isPrimitiveOrString(Class type) {
|
||||
return type.isPrimitive() || type.equals(String.class);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user