All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hltech.pact.gen.domain.client.jaxrs.JaxRsClientsFinder Maven / Gradle / Ivy

The newest version!
package com.hltech.pact.gen.domain.client.jaxrs;

import org.reflections.Reflections;
import org.reflections.scanners.MethodAnnotationsScanner;

import javax.ws.rs.Path;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;

public class JaxRsClientsFinder {

    public Set> findJaxRsClients(String packageRoot) {
        Set> jaxRsClients = new HashSet<>();
        jaxRsClients.addAll(classAnnotatedClients(packageRoot));
        jaxRsClients.addAll(methodAnnotatedClients(packageRoot));

        return jaxRsClients;
    }

    private Set> classAnnotatedClients(String packageRoot) {
        return new Reflections(packageRoot)
            .getTypesAnnotatedWith(Path.class);
    }

    private Set> methodAnnotatedClients(String packageRoot) {
        return new Reflections(packageRoot, new MethodAnnotationsScanner())
            .getMethodsAnnotatedWith(Path.class).stream()
            .map(Method::getDeclaringClass)
            .collect(Collectors.toSet());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy