Completed
Push — master ( 3231d7...5d3bab )
by Filip
06:31
created

methodAnnotatedClients(String)   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
dl 0
loc 5
rs 10
1
package com.hltech.pact.gen.domain.client.jaxrs;
2
3
import org.reflections.Reflections;
4
import org.reflections.scanners.MethodAnnotationsScanner;
5
6
import javax.ws.rs.Path;
7
import java.lang.reflect.Method;
8
import java.util.HashSet;
9
import java.util.Set;
10
import java.util.stream.Collectors;
11
12
public class JaxRsClientsFinder {
13
14
    public Set<Class<?>> findJaxRsClients(String packageRoot) {
15
        Set<Class<?>> jaxRsClients = new HashSet<>();
16
        jaxRsClients.addAll(classAnnotatedClients(packageRoot));
17
        jaxRsClients.addAll(methodAnnotatedClients(packageRoot));
18
19
        return jaxRsClients;
20
    }
21
22
    private Set<Class<?>> classAnnotatedClients(String packageRoot) {
23
        return new Reflections(packageRoot)
24
            .getTypesAnnotatedWith(Path.class);
25
    }
26
27
    private Set<Class<?>> methodAnnotatedClients(String packageRoot) {
28
        return new Reflections(packageRoot, new MethodAnnotationsScanner())
29
            .getMethodsAnnotatedWith(Path.class).stream()
30
            .map(Method::getDeclaringClass)
31
            .collect(Collectors.toSet());
32
    }
33
}
34