# HG changeset patch # User František Kučera # Date 1439639923 -7200 # Node ID 1fb3c7953d8aecb2f317a8da9b34514ee1a02616 # Parent 39d154429f7ab17bc01f5ff58fd43635a05df71b property annotations: first woking version of --list-formatter-properties diff -r 39d154429f7a -r 1fb3c7953d8a java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java --- 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 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 data = new ArrayList<>(); + Map data = new HashMap<>(); Class formatterClass = (Class) 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> 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 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); }