1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Sat Aug 15 13:21:26 2015 +0200
1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Sat Aug 15 13:58:43 2015 +0200
1.3 @@ -47,8 +47,10 @@
1.4 import java.util.Collections;
1.5 import java.util.Comparator;
1.6 import java.util.EnumSet;
1.7 +import java.util.HashMap;
1.8 import java.util.HashSet;
1.9 import java.util.List;
1.10 +import java.util.Map;
1.11 import java.util.Map.Entry;
1.12 import java.util.ServiceLoader;
1.13 import java.util.Set;
1.14 @@ -186,6 +188,17 @@
1.15 }
1.16 }
1.17
1.18 + private PropertyDeclaration[] getPropertyDeclarations(Class<? extends Formatter> formatterClass) {
1.19 + PropertyDeclarations properties = formatterClass.getAnnotation(PropertyDeclarations.class);
1.20 +
1.21 + if (properties == null) {
1.22 + PropertyDeclaration p = formatterClass.getAnnotation(PropertyDeclaration.class);
1.23 + return p == null ? new PropertyDeclaration[]{} : new PropertyDeclaration[]{p};
1.24 + } else {
1.25 + return properties.value();
1.26 + }
1.27 + }
1.28 +
1.29 private void listFormatterProperties(String formatterName) throws FormatterException, ConfigurationException {
1.30 FormatterDefinition fd = configurationProvider.getConfiguration().getFormatter(formatterName);
1.31 try {
1.32 @@ -196,31 +209,21 @@
1.33 new HeaderField("default", SQLType.VARCHAR),
1.34 new HeaderField("description", SQLType.VARCHAR)
1.35 );
1.36 - List<Object[]> data = new ArrayList<>();
1.37
1.38 + Map<String, Object[]> data = new HashMap<>();
1.39 Class<Formatter> formatterClass = (Class<Formatter>) Class.forName(fd.getClassName());
1.40 -
1.41 - // TOOD: formatterClass.getDeclaredAnnotation(PropertyDeclarations.class); and separate inherited properties
1.42 - // Repeated PropertyDeclaration wrapped in PropertyDeclarations
1.43 - PropertyDeclarations properties = formatterClass.getAnnotation(PropertyDeclarations.class);
1.44 - if (properties == null) {
1.45 - log.log(Level.WARNING, "Formatter „{0}“ has no declared properties", formatterName);
1.46 - } else {
1.47 - for (PropertyDeclaration p : properties.value()) {
1.48 - data.add(propertyDeclarationToRow(p));
1.49 + List<Class<? extends Formatter>> hierarchy = Functions.getClassHierarchy(formatterClass, Formatter.class);
1.50 + Collections.reverse(hierarchy);
1.51 + hierarchy.stream().forEach((c) -> {
1.52 + for (PropertyDeclaration p : getPropertyDeclarations(c)) {
1.53 + data.put(p.name(), propertyDeclarationToRow(p));
1.54 }
1.55 - }
1.56 -
1.57 - // Single PropertyDeclaration
1.58 - PropertyDeclaration property = formatterClass.getAnnotation(PropertyDeclaration.class);
1.59 - if (property != null) {
1.60 - data.add(propertyDeclarationToRow(property));
1.61 - }
1.62 + });
1.63
1.64 List<Parameter> parameters = new ArrayList<>();
1.65 parameters.add(new NamedParameter("formatter", formatterName, SQLType.VARCHAR));
1.66
1.67 - printTable(formatter, header, "-- formatter properties", parameters, data);
1.68 + printTable(formatter, header, "-- formatter properties", parameters, new ArrayList<>(data.values()));
1.69 } catch (ClassNotFoundException e) {
1.70 throw new ConfigurationException("Unable to find class " + fd.getClassName() + " of formatter" + fd.getName(), e);
1.71 }