[configuration] Code cleanup

This commit is contained in:
Roel Spilker committed 2014-01-20 03:18:22 +01:00
1 parent 01cee6f22d
commit e8059d4e9e
4 files changed
+7 -26

No files matched your search

@@ -60,7 +60,7 @@ public class LombokConfiguration {
// create a new empty 'cache' to make sure all problems are reported
cache.reset();
ConfigurationResolver resolver = new BubblingConfigurationResolver(cache.sourcesForJavaFile(ast.getAbsoluteFileLocation(), reporter));
for (ConfigurationKey<?> key : ConfigurationKey.registeredKeys()) {
for (ConfigurationKey<?> key : ConfigurationKey.registeredKeys().values()) {
Object value = resolver.resolve(key);
if (value == null || value instanceof List<?> && ((List<?>)value).isEmpty()) continue;
stream.printf("%s: %s\n", key.getKeyName(), value);
@@ -116,7 +116,7 @@ public class ConfigurationApp extends LombokApp {
}
private void printConfiguration(PrintStream out, boolean verbose) {
for (ConfigurationKey<?> key : ConfigurationKey.registeredKeys()) {
for (ConfigurationKey<?> key : ConfigurationKey.registeredKeys().values()) {
String keyName = key.getKeyName();
ConfigurationDataType type = key.getType();
String description = key.getDescription();
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013 The Project Lombok Authors.
* Copyright (C) 2013-2014 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -22,7 +22,6 @@
package lombok.core.configuration;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
import java.util.regex.Pattern;
@@ -36,7 +35,7 @@ import java.util.regex.Pattern;
* </pre>
*/
public abstract class ConfigurationKey<T> {
private static final Pattern VALID_NAMES = Pattern.compile("[\\-_a-zA-Z][\\-\\.\\w]*(?<![\\.\\-])");
private static final Pattern VALID_NAMES = Pattern.compile("[-_a-zA-Z][-.\\w]*(?<![-.])");
private static final TreeMap<String, ConfigurationKey<?>> registeredKeys = new TreeMap<String, ConfigurationKey<?>>(String.CASE_INSENSITIVE_ORDER);
private static Map<String, ConfigurationKey<?>> copy;
@@ -45,11 +44,6 @@ public abstract class ConfigurationKey<T> {
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")
@@ -63,7 +57,7 @@ public abstract class ConfigurationKey<T> {
return keyName;
}
public String getDescription() {
public final String getDescription() {
return description;
}
@@ -85,26 +79,13 @@ public abstract class ConfigurationKey<T> {
* Returns a copy of the currently registered keys.
*/
@SuppressWarnings("unchecked")
public static Map<String, ConfigurationKey<?>> registeredKeysMap() {
public static Map<String, ConfigurationKey<?>> registeredKeys() {
synchronized (registeredKeys) {
if (copy == null) copy = Collections.unmodifiableMap((Map<String, ConfigurationKey<?>>) registeredKeys.clone());
return copy;
}
}
/**
* Returns a copy of the currently registered keys.
*/
public static Iterable<ConfigurationKey<?>> registeredKeys() {
final Map<String, ConfigurationKey<?>> map = registeredKeysMap();
return new Iterable<ConfigurationKey<?>>() {
@Override public Iterator<ConfigurationKey<?>> iterator() {
return map.values().iterator();
}
};
}
private static void registerKey(String keyName, ConfigurationKey<?> key) {
synchronized (registeredKeys) {
if (registeredKeys.containsKey(keyName)) throw new IllegalArgumentException("Key '" + keyName + "' already registered");
@@ -42,7 +42,7 @@ public class StringConfigurationSource implements ConfigurationSource {
Map<String, Result> values = new TreeMap<String, Result>(String.CASE_INSENSITIVE_ORDER);
Map<String, ConfigurationKey<?>> registeredKeys = ConfigurationKey.registeredKeysMap();
Map<String, ConfigurationKey<?>> registeredKeys = ConfigurationKey.registeredKeys();
int lineNumber = 0;
Matcher lineMatcher = NEWLINE_FINDER.matcher(content);
while (lineMatcher.find()) {