Skip to content

Commit

Permalink
#500 only add third party/special/standard imports if values are defi…
Browse files Browse the repository at this point in the history
…ned for them
  • Loading branch information
jshiell committed Apr 6, 2021
1 parent 7330082 commit 2245f84
Showing 1 changed file with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ public CustomImportOrderImporter() {
standardPackageRegExp.add("java");

thirdPartyPackageRegExp = new ArrayList<>();
thirdPartyPackageRegExp.add("");

specialImportsRegExp = new ArrayList<>();
specialImportsRegExp.add("");
}

@Override
Expand Down Expand Up @@ -85,40 +83,39 @@ private PackageEntryTable createCustomImportTable() {

if (customImportOrder != null) {
for (ImportGroup group : customImportOrder) {
boolean entryAdded = false;
switch (group) {
case STATIC:
table.addEntry(PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY);
entryAdded = true;
break;
case THIRD_PARTY_PACKAGE:
thirdPartyPackageRegExp.forEach(createPackageEntry);
entryAdded = thirdPartyPackageRegExp.size() > 0;
break;
case SPECIAL_IMPORTS:
specialImportsRegExp.forEach(createPackageEntry);
entryAdded = specialImportsRegExp.size() > 0;
break;
case STANDARD_JAVA_PACKAGE:
standardPackageRegExp.forEach(createPackageEntry);
entryAdded = standardPackageRegExp.size() > 0;
break;
default:
// IntelliJ does not support this option or group does not exist
break;
}

addBlankLineBetweenGroups(table);
if (entryAdded && separateLineBetweenGroups) {
table.addEntry(PackageEntry.BLANK_LINE_ENTRY);
}
}
}

table.addEntry(PackageEntry.ALL_OTHER_IMPORTS_ENTRY);
return table;
}

private void addBlankLineBetweenGroups(final PackageEntryTable table) {
if (!separateLineBetweenGroups) {
return;
}

table.addEntry(PackageEntry.BLANK_LINE_ENTRY);
}

private List<String> parseCustomPackagesRegExp(@NotNull final String value) {
String processedValue = value;

Expand All @@ -128,9 +125,9 @@ private List<String> parseCustomPackagesRegExp(@NotNull final String value) {
}

// The ending \. used in the regex value is not required in IntelliJ
processedValue = processedValue.endsWith("\\.")
? processedValue.substring(0, processedValue.length() - 2)
: processedValue;
if (processedValue.endsWith("\\.")) {
processedValue = processedValue.substring(0, processedValue.length() - 2);
}

String[] customPackages = processedValue.split("\\|");

Expand Down

0 comments on commit 2245f84

Please sign in to comment.