private static void convertProtocolToAsciidocTable(Properties props, Class<Protocol> clazz) throws Exception { boolean isUnsupported = clazz.isAnnotationPresent(Unsupported.class); if (isUnsupported) return; Map<String, String> nameToDescription = new TreeMap<>(); Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { if (field.isAnnotationPresent(Property.class)) { String property = field.getName(); Property annotation = field.getAnnotation(Property.class); String desc = annotation.description(); nameToDescription.put(property, desc); } } // iterate methods Method[] methods = clazz.getDeclaredMethods(); for (Method method : methods) { if (method.isAnnotationPresent(Property.class)) { Property annotation = method.getAnnotation(Property.class); String desc = annotation.description(); if (desc == null || desc.isEmpty()) desc = "n/a"; String name = annotation.name(); if (name.length() < 1) { name = Util.methodNameToAttributeName(method.getName()); } nameToDescription.put(name, desc); } } // do we have more than one property (superclass Protocol has only one property (stats)) if (nameToDescription.isEmpty()) return; List<String[]> rows = new ArrayList<>(nameToDescription.size() + 1); rows.add(new String[] {"Name", "Description"}); for (Map.Entry<String, String> entry : nameToDescription.entrySet()) rows.add(new String[] {entry.getKey(), entry.getValue()}); String tmp = createAsciidocTable( rows, clazz.getSimpleName(), "[align=\"left\",width=\"90%\",cols=\"2,10\",options=\"header\"]"); props.put(clazz.getSimpleName(), tmp); }
private static void _testMethodNameToAttributeName(String input, String expected_output) { String atttr_name = Util.methodNameToAttributeName(input); System.out.println( "method name=" + input + ", attrname=" + atttr_name + ", expected output=" + expected_output); assert atttr_name.equals(expected_output) : "method name=" + input + ", attrname=" + atttr_name + ", expected output=" + expected_output; }