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

com.hltech.pact.gen.domain.client.jaxrs.JaxRsClientsFinder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 20
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A classAnnotatedClients(String) 0 3 1
A findJaxRsClients(String) 0 6 1
A methodAnnotatedClients(String) 0 5 1
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