--- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Sat Aug 15 13:21:26 2015 +0200
+++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Sat Aug 15 13:58:43 2015 +0200
@@ -47,8 +47,10 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
import java.util.ServiceLoader;
import java.util.Set;
@@ -186,6 +188,17 @@
}
}
+ private PropertyDeclaration[] getPropertyDeclarations(Class<? extends Formatter> formatterClass) {
+ PropertyDeclarations properties = formatterClass.getAnnotation(PropertyDeclarations.class);
+
+ if (properties == null) {
+ PropertyDeclaration p = formatterClass.getAnnotation(PropertyDeclaration.class);
+ return p == null ? new PropertyDeclaration[]{} : new PropertyDeclaration[]{p};
+ } else {
+ return properties.value();
+ }
+ }
+
private void listFormatterProperties(String formatterName) throws FormatterException, ConfigurationException {
FormatterDefinition fd = configurationProvider.getConfiguration().getFormatter(formatterName);
try {
@@ -196,31 +209,21 @@
new HeaderField("default", SQLType.VARCHAR),
new HeaderField("description", SQLType.VARCHAR)
);
- List<Object[]> data = new ArrayList<>();
+ Map<String, Object[]> data = new HashMap<>();
Class<Formatter> formatterClass = (Class<Formatter>) Class.forName(fd.getClassName());
-
- // TOOD: formatterClass.getDeclaredAnnotation(PropertyDeclarations.class); and separate inherited properties
- // Repeated PropertyDeclaration wrapped in PropertyDeclarations
- PropertyDeclarations properties = formatterClass.getAnnotation(PropertyDeclarations.class);
- if (properties == null) {
- log.log(Level.WARNING, "Formatter „{0}“ has no declared properties", formatterName);
- } else {
- for (PropertyDeclaration p : properties.value()) {
- data.add(propertyDeclarationToRow(p));
+ List<Class<? extends Formatter>> hierarchy = Functions.getClassHierarchy(formatterClass, Formatter.class);
+ Collections.reverse(hierarchy);
+ hierarchy.stream().forEach((c) -> {
+ for (PropertyDeclaration p : getPropertyDeclarations(c)) {
+ data.put(p.name(), propertyDeclarationToRow(p));
}
- }
-
- // Single PropertyDeclaration
- PropertyDeclaration property = formatterClass.getAnnotation(PropertyDeclaration.class);
- if (property != null) {
- data.add(propertyDeclarationToRow(property));
- }
+ });
List<Parameter> parameters = new ArrayList<>();
parameters.add(new NamedParameter("formatter", formatterName, SQLType.VARCHAR));
- printTable(formatter, header, "-- formatter properties", parameters, data);
+ printTable(formatter, header, "-- formatter properties", parameters, new ArrayList<>(data.values()));
} catch (ClassNotFoundException e) {
throw new ConfigurationException("Unable to find class " + fd.getClassName() + " of formatter" + fd.getName(), e);
}