urfreespace commented on code in PR #16627:
URL: https://github.com/apache/pulsar/pull/16627#discussion_r928448702


##########
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/BaseGenerateDocumentation.java:
##########
@@ -80,50 +82,107 @@ public boolean run(String[] args) throws Exception {
 
     protected abstract String generateDocumentByClassName(String className) 
throws Exception;
 
+    protected Predicate<Field> isRequired = field -> {
+        FieldContext fieldContext = field.getAnnotation(FieldContext.class);
+        return fieldContext.required();
+    };
+
+    protected Predicate<Field> isOptional = field -> {
+        FieldContext fieldContext = field.getAnnotation(FieldContext.class);
+        return !fieldContext.deprecated() && !fieldContext.required();
+    };
+
+    protected Predicate<Field> isDeprecated = field -> {
+        FieldContext fieldContext = field.getAnnotation(FieldContext.class);
+        return fieldContext.deprecated();
+    };
+
+    protected void writeDocListByFieldContext(List<Field> fieldList, 
StringBuilder sb, Object obj) throws Exception {
+        for (Field field : fieldList) {
+            FieldContext fieldContext = 
field.getAnnotation(FieldContext.class);
+            field.setAccessible(true);
+
+            sb.append("### ").append(field.getName()).append("\n");
+            sb.append(fieldContext.doc().replace(">", "\\>")).append("\n\n");
+            sb.append("**Default**: `").append(field.get(obj)).append("`\n\n");
+            sb.append("**Dynamic**: 
`").append(fieldContext.dynamic()).append("`\n\n");
+            sb.append("**Category**: 
").append(fieldContext.category()).append("\n\n");
+        }
+    }
+
+    protected static class CategoryComparator implements Comparator<Field> {
+        @Override
+        public int compare(Field o1, Field o2) {
+            FieldContext o1Context = o1.getAnnotation(FieldContext.class);
+            FieldContext o2Context = o2.getAnnotation(FieldContext.class);
+
+            if (o1Context.category().equals(o2Context.category())) {
+                return o1.getName().compareTo(o2.getName());
+            }
+            return o1Context.category().compareTo(o2Context.category());
+        }
+    }
+
+    protected String prefix = """
+            :::note
+
+            This page is automatically generated from code files.
+            If you find something inaccurate, feel free to update `""";
+    protected String suffix = """
+            `. Do NOT edit this markdown file manually. Manual changes will be 
overwritten by automatic generation.
+
+            :::
+            """;
+
     protected String generateDocByFieldContext(String className, String type, 
StringBuilder sb) throws Exception {
         Class<?> clazz = Class.forName(className);
         Object obj = clazz.getDeclaredConstructor().newInstance();
         Field[] fields = clazz.getDeclaredFields();
+        ArrayList<Field> fieldList = new ArrayList<>(Arrays.asList(fields));
+
+        fieldList.removeIf(f -> f.getAnnotation(FieldContext.class) == null);
+        fieldList.sort(new CategoryComparator());
+        List<Field> requiredFields = 
fieldList.stream().filter(isRequired).toList();
+        List<Field> optionalFields = 
fieldList.stream().filter(isOptional).toList();
+        List<Field> deprecatedFields = 
fieldList.stream().filter(isDeprecated).toList();
 
         sb.append("# ").append(type).append("\n");
-        sb.append("|Name|Description|Default|Dynamic|Category|\n");
-        sb.append("|---|---|---|---|---|\n");
-        for (Field field : fields) {
-            FieldContext fieldContext = 
field.getAnnotation(FieldContext.class);
-            if (fieldContext == null) {
-                continue;
-            }
-            field.setAccessible(true);
-            sb.append("| ").append(field.getName()).append(" | ");
-            sb.append(fieldContext.doc().replace("\n", "<br>")).append(" | ");
-            sb.append(field.get(obj)).append(" | ");
-            sb.append(fieldContext.dynamic()).append(" | ");
-            sb.append(fieldContext.category()).append(" | ");
-            sb.append("\n");
-        }

Review Comment:
   Won't these changes affect the generation of other documents? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to