com.hltech.pact.gen.domain.client.util.TypeExtractor   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 13
dl 0
loc 21
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A TypeExtractor() 0 1 1
A extractParameterTypesFromType(Type) 0 17 4
1
package com.hltech.pact.gen.domain.client.util;
2
3
import com.google.common.collect.Lists;
4
5
import java.lang.reflect.ParameterizedType;
6
import java.lang.reflect.Type;
7
import java.util.ArrayList;
8
import java.util.Arrays;
9
import java.util.List;
10
import java.util.stream.Collectors;
11
12
public class TypeExtractor {
13
14
    private TypeExtractor() {}
15
16
    public static List<Class<?>> extractParameterTypesFromType(Type type) {
17
        if (type == null) {
18
            return new ArrayList<>();
19
        }
20
21
        if (type instanceof ParameterizedType) {
22
            ParameterizedType paramType = (ParameterizedType)type;
23
            return Arrays.stream(paramType.getActualTypeArguments())
24
                .map(a -> (Class<?>)a)
25
                .collect(Collectors.toList());
26
        }
27
28
        if (((Class<?>)type).isArray()) {
29
            return Lists.newArrayList(((Class<?>)type).getComponentType());
30
        }
31
32
        return Lists.newArrayList();
33
    }
34
}
35