[configuration] Small improvements to the command line app

This commit is contained in:
Roel Spilker committed 2014-01-23 23:07:59 +01:00
1 parent ed061712f5
commit 0293e13fed
3 files changed
+22 -19

No files matched your search

+5 -3
View File
@@ -269,21 +269,21 @@ public class ConfigurationKeys {
*
* For any class without an {@code @Accessors} that explicitly defines the {@code prefix} option, this list of prefixes is used.
*/
public static final ConfigurationKey<List<String>> ACCESSORS_PREFIX = new ConfigurationKey<List<String>>("lombok.Accessors.prefix", "Specify field prefixes, like 'f' or 'm_', to be stipped when generating getters and setters.") {};
public static final ConfigurationKey<List<String>> ACCESSORS_PREFIX = new ConfigurationKey<List<String>>("lombok.Accessors.prefix", "Strip this field prefix, like 'f' or 'm_', from the names of generated getters and setters.") {};
/**
* lombok configuration: {@code lombok.Accessors.chain} = {@code true} | {@code false}.
*
* For any class without an {@code @Accessors} that explicitly defines the {@code chain} option, this value is used.
*/
public static final ConfigurationKey<Boolean> ACCESSORS_CHAIN = new ConfigurationKey<Boolean>("lombok.Accessors.chain", "Generated setters should return 'this' instead if 'void'.") {};
public static final ConfigurationKey<Boolean> ACCESSORS_CHAIN = new ConfigurationKey<Boolean>("lombok.Accessors.chain", "Generate setters that return 'this' instead of 'void'.") {};
/**
* lombok configuration: {@code lombok.Accessors.fluent} = {@code true} | {@code false}.
*
* For any class without an {@code @Accessors} that explicitly defines the {@code fluent} option, this value is used.
*/
public static final ConfigurationKey<Boolean> ACCESSORS_FLUENT = new ConfigurationKey<Boolean>("lombok.Accessors.fluent", "The name for generated getters and setters will only be the field name (no get/set prefix).") {};
public static final ConfigurationKey<Boolean> ACCESSORS_FLUENT = new ConfigurationKey<Boolean>("lombok.Accessors.fluent", "Generate getters and setters using only the field name (no get/set prefix).") {};
// ----- Builder -----
@@ -322,6 +322,8 @@ public class ConfigurationKeys {
public static final ConfigurationKey<FlagUsageType> WITHER_FLAG_USAGE = new ConfigurationKey<FlagUsageType>("lombok.Wither.flagUsage", "Emit a warning or error if @Wither is used.") {};
// ----- Configuration System -----
/**
* lombok configuration: {@code stop-bubbling} = {@code true} | {@code false}.
*
@@ -32,6 +32,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -58,7 +59,7 @@ public class ConfigurationApp extends LombokApp {
private static final URI NO_CONFIG = URI.create("");
@Override public String getAppName() {
return "configuration";
return "config";
}
@Override public String getAppDescription() {
@@ -66,7 +67,7 @@ public class ConfigurationApp extends LombokApp {
}
@Override public List<String> getAppAliases() {
return Arrays.asList("configuration", "config");
return Arrays.asList("configuration", "config", "conf", "settings");
}
public static class CmdArgs {
@@ -192,19 +193,14 @@ public class ConfigurationApp extends LombokApp {
}
URI directory = entry.getKey();
ConfigurationResolver resolver = new BubblingConfigurationResolver(cache.sourcesForDirectory(directory, reporter));
Map<ConfigurationKey<?>, ? extends Collection<String>> traces = trace(keys, directory, verbose);
Map<ConfigurationKey<?>, ? extends Collection<String>> traces = trace(keys, directory);
boolean printed = false;
for (ConfigurationKey<?> key : keys) {
Object value = resolver.resolve(key);
if (value == null || (value instanceof List<?> && ((List<?>)value).isEmpty())) {
if (explicitKeys) {
if (printed && verbose) out.println();
printValue(out, key, value, verbose, traces.get(key));
printed = true;
}
} else {
Collection<String> modifications = traces.get(key);
if (!modifications.isEmpty() || explicitKeys) {
if (printed && verbose) out.println();
printValue(out, key, value, verbose, traces.get(key));
printValue(out, key, value, verbose, modifications);
printed = true;
}
}
@@ -237,11 +233,10 @@ public class ConfigurationApp extends LombokApp {
@Override public void report(String sourceDescription, String problem, int lineNumber, CharSequence line) {}
};
private Map<ConfigurationKey<?>, ? extends Collection<String>> trace(Collection<ConfigurationKey<?>> keys, URI directory, boolean verbose) throws Exception {
if (!verbose) return Collections.emptyMap();
private Map<ConfigurationKey<?>, ? extends Collection<String>> trace(Collection<ConfigurationKey<?>> keys, URI directory) throws Exception {
Map<ConfigurationKey<?>, List<String>> result = new HashMap<ConfigurationKey<?>, List<String>>();
for (ConfigurationKey<?> key : keys) result.put(key, new ArrayList<String>());
Set<ConfigurationKey<?>> used = new HashSet<ConfigurationKey<?>>();
boolean stopBubbling = false;
String previousFileName = null;
@@ -257,6 +252,8 @@ public class ConfigurationApp extends LombokApp {
if (modifications == null) {
modifications = new ArrayList<String>();
modifications.add(" <'" + key.getKeyName() + "' not mentioned>");
} else {
used.add(key);
}
if (previousFileName != null) {
modifications.add("");
@@ -267,7 +264,11 @@ public class ConfigurationApp extends LombokApp {
previousFileName = configFile.getAbsolutePath();
}
for (ConfigurationKey<?> key : keys) {
result.get(key).add(0, previousFileName + (stopBubbling ? " (stop bubbling):" : " (highest found):"));
if (used.contains(key)) {
result.get(key).add(0, previousFileName + (stopBubbling ? " (stopped bubbling):" : ":"));
} else {
result.put(key, Collections.<String>emptyList());
}
}
return result;
}
@@ -84,7 +84,7 @@ public class ConfigurationParser {
if (stringValue != null) try {
value = type.getParser().parse(stringValue);
} catch (Exception e) {
reporter.report(contentDescription, "Error while parsing the value for '" + keyName + "' value '" + stringValue + "' (should be a " + type.getParser().description() + ")", lineNumber, line);
reporter.report(contentDescription, "Error while parsing the value for '" + keyName + "' value '" + stringValue + "' (should be " + type.getParser().exampleValue() + ")", lineNumber, line);
continue;
}