protected void processMavenClass()

in maven-resolver-tools/src/main/java/org/eclipse/aether/tools/CollectConfiguration.java [152:242]


    protected void processMavenClass(Path path, List<Map<String, String>> discoveredKeys) {
        try {
            ClassReader classReader = new ClassReader(Files.newInputStream(path));
            classReader.accept(
                    new ClassVisitor(Opcodes.ASM9) {
                        @Override
                        public FieldVisitor visitField(
                                int fieldAccess,
                                String fieldName,
                                String fieldDescriptor,
                                String fieldSignature,
                                Object fieldValue) {
                            return new FieldVisitor(Opcodes.ASM9) {
                                @Override
                                public AnnotationVisitor visitAnnotation(
                                        String annotationDescriptor, boolean annotationVisible) {
                                    if (annotationDescriptor.equals("Lorg/apache/maven/api/annotations/Config;")) {
                                        return new AnnotationVisitor(Opcodes.ASM9) {
                                            final Map<String, Object> values = new HashMap<>();

                                            @Override
                                            public void visit(String name, Object value) {
                                                values.put(name, value);
                                            }

                                            @Override
                                            public void visitEnum(String name, String descriptor, String value) {
                                                values.put(name, value);
                                            }

                                            @Override
                                            public void visitEnd() {
                                                JavaType<?> jtype = parse(Paths.get(path.toString()
                                                        .replace("/target/classes/", "/src/main/java/")
                                                        .replace(".class", ".java")));
                                                FieldSource<JavaClassSource> f =
                                                        ((JavaClassSource) jtype).getField(fieldName);

                                                String fqName = null;
                                                String desc = cloneJavadoc(f.getJavaDoc())
                                                        .removeAllTags()
                                                        .getFullText()
                                                        .replace("*", "\\*");
                                                String since = getSince(f);
                                                String source = (values.get("source") != null
                                                                ? (String) values.get("source")
                                                                : "USER_PROPERTIES") // TODO: enum
                                                        .toLowerCase();
                                                source = switch (source) {
                                                    case "model" -> "Model properties";
                                                    case "user_properties" -> "User properties";
                                                    default -> source;};
                                                String type = (values.get("type") != null
                                                        ? (String) values.get("type")
                                                        : "java.lang.String");
                                                if (type.startsWith("java.lang.")) {
                                                    type = type.substring("java.lang.".length());
                                                } else if (type.startsWith("java.util.")) {
                                                    type = type.substring("java.util.".length());
                                                }
                                                discoveredKeys.add(Map.of(
                                                        KEY,
                                                        fieldValue.toString(),
                                                        "defaultValue",
                                                        values.get("defaultValue") != null
                                                                ? values.get("defaultValue")
                                                                        .toString()
                                                                : "",
                                                        "fqName",
                                                        nvl(fqName, ""),
                                                        "description",
                                                        desc,
                                                        "since",
                                                        nvl(since, ""),
                                                        "configurationSource",
                                                        source,
                                                        "configurationType",
                                                        type));
                                            }
                                        };
                                    }
                                    return null;
                                }
                            };
                        }
                    },
                    0);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }