mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 00:16:47 +00:00
added contingency case in format pref scanning if there is no input
This commit is contained in:
1 parent
21415af7b1
commit
f865fe5fa2
1 file changed
+5
-5
@@ -37,18 +37,18 @@ import java.util.Map;
|
||||
*/
|
||||
public class FormatPreferenceScanner {
|
||||
/** Checks validity of preferences, and returns with a non-null value if ALL format keys are available, thus negating the need for a scan. */
|
||||
private FormatPreferences tryEasy(Map<String, String> preferences) {
|
||||
private FormatPreferences tryEasy(Map<String, String> preferences, boolean force) {
|
||||
int count = 0;
|
||||
for (Map.Entry<String, String> e : preferences.entrySet()) {
|
||||
if (!FormatPreferences.KEYS.containsKey(e.getKey())) throw new IllegalArgumentException("Unknown format key: " + e.getKey());
|
||||
if (!"scan".equalsIgnoreCase(e.getValue())) count++;
|
||||
}
|
||||
if (count >= FormatPreferences.KEYS.size()) return new FormatPreferences(preferences, "\t", false);
|
||||
if (force || count >= FormatPreferences.KEYS.size()) return new FormatPreferences(preferences, "\t", false);
|
||||
return null;
|
||||
}
|
||||
|
||||
public FormatPreferences scan(Map<String, String> preferences, final CharSequence source) {
|
||||
FormatPreferences fps = tryEasy(preferences);
|
||||
FormatPreferences fps = tryEasy(preferences, source == null);
|
||||
if (fps != null) return fps;
|
||||
|
||||
try {
|
||||
@@ -76,7 +76,7 @@ public class FormatPreferenceScanner {
|
||||
}
|
||||
|
||||
public FormatPreferences scan(Map<String, String> preferences, char[] source) {
|
||||
FormatPreferences fps = tryEasy(preferences);
|
||||
FormatPreferences fps = tryEasy(preferences, source == null);
|
||||
if (fps != null) return fps;
|
||||
|
||||
try {
|
||||
@@ -87,7 +87,7 @@ public class FormatPreferenceScanner {
|
||||
}
|
||||
|
||||
public FormatPreferences scan(Map<String, String> preferences, Reader in) throws IOException {
|
||||
FormatPreferences fps = tryEasy(preferences);
|
||||
FormatPreferences fps = tryEasy(preferences, in == null);
|
||||
if (fps != null) return fps;
|
||||
|
||||
return scan_(preferences, in);
|
||||
|
||||
Reference in new issue
Block a user