[configuration] ConfigurationKey now has a description

This commit is contained in:
Roel Spilker committed 2014-01-20 00:44:57 +01:00
1 parent a016e623de
commit 5be1c574d6
3 files changed
+36 -13

No files matched your search

+1 -1
View File
@@ -306,5 +306,5 @@ public class ConfigurationKeys {
*
* If set to {@code true}, no futher {@code lombok.config} files will be checked.
*/
public static final ConfigurationKey<Boolean> STOP_BUBBLING = new ConfigurationKey<Boolean>("stop-bubbling") {};
public static final ConfigurationKey<Boolean> STOP_BUBBLING = new ConfigurationKey<Boolean>("stop-bubbling", "Tells the configuration system if it should stop looking for other configuration files.") {};
}
@@ -119,19 +119,32 @@ public class ConfigurationApp extends LombokApp {
for (ConfigurationKey<?> key : ConfigurationKey.registeredKeys()) {
String keyName = key.getKeyName();
ConfigurationDataType type = key.getType();
String description = key.getDescription();
boolean hasDescription = description != null && !description.isEmpty();
if (!verbose) {
out.printf("# %s (%s)\n", keyName, type);
if (hasDescription) {
out.printf("%s: %s\n", keyName, description);
} else {
out.printf("%s\n", keyName);
}
continue;
}
out.printf("### Key %s type %s\n", keyName, type);
out.printf("#clear %s\n", keyName);
if (type.isList()) {
out.printf("#%s += %s\n", keyName, exampleValue(type));
out.printf("#%s -= %s\n", keyName, exampleValue(type));
} else {
out.printf("#%s = %s\n", keyName, exampleValue(type));
out.printf("##\n## Key : %s\n## Type: %s\n", keyName, type);
if (hasDescription) {
out.printf("##\n## %s\n", description);
}
out.println();
out.println("##\n## Examples:\n#");
out.printf("# clear %s\n", keyName);
if (type.isList()) {
out.printf("# %s += %s\n", keyName, exampleValue(type));
out.printf("# %s -= %s\n", keyName, exampleValue(type));
} else {
out.printf("# %s = %s\n", keyName, exampleValue(type));
}
out.println("#\n");
}
if (!verbose) {
out.println("\nUse --verbose for more information.");
}
}
@@ -32,7 +32,7 @@ import java.util.regex.Pattern;
* <p>
* The recommended usage is to create a type token:
* <pre>
* private static ConfigurationKey&lt;String> KEY = new ConfigurationKey&lt;String>("keyName") {};
* private static ConfigurationKey&lt;String> KEY = new ConfigurationKey&lt;String>("keyName", "description") {};
* </pre>
*/
public abstract class ConfigurationKey<T> {
@@ -42,14 +42,20 @@ public abstract class ConfigurationKey<T> {
private static Map<String, ConfigurationKey<?>> copy;
private final String keyName;
private final String description;
private final ConfigurationDataType type;
@Deprecated
public ConfigurationKey(String keyName) {
this(keyName, null);
}
public ConfigurationKey(String keyName, String description) {
this.keyName = checkName(keyName);
@SuppressWarnings("unchecked")
ConfigurationDataType type = ConfigurationDataType.toDataType((Class<? extends ConfigurationKey<?>>)getClass());
this.type = type;
this.description = description;
registerKey(keyName, this);
}
@@ -57,12 +63,16 @@ public abstract class ConfigurationKey<T> {
return keyName;
}
public String getDescription() {
return description;
}
public final ConfigurationDataType getType() {
return type;
}
@Override public String toString() {
return keyName + " : " + type;
return keyName + " (" + type + "): " + description;
}
private static String checkName(String keyName) {