JavaParser Source Viewer

Home|JavaParser/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParameterValueProvider.java
1/*
2 * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser.
3 * Copyright (C) 2011, 2013-2020 The JavaParser Team.
4 *
5 * This file is part of JavaParser.
6 *
7 * JavaParser can be used either under the terms of
8 * a) the GNU Lesser General Public License as published by
9 *     the Free Software Foundation, either version 3 of the License, or
10 *     (at your option) any later version.
11 * b) the terms of the Apache License
12 *
13 * You should have received a copy of both licenses in LICENCE.LGPL and
14 * LICENCE.APACHE. Please refer to those files for details.
15 *
16 * JavaParser is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU Lesser General Public License for more details.
20 */
21
22package com.github.javaparser.resolution.types.parametrization;
23
24import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration;
25import com.github.javaparser.resolution.types.ResolvedType;
26import com.github.javaparser.resolution.types.ResolvedWildcard;
27
28import java.util.Optional;
29
30/**
31 * @author Federico Tomassetti
32 */
33public interface ResolvedTypeParameterValueProvider {
34
35    /**
36     * Calculate the value for the given type parameter.
37     * It could be inherited.
38     */
39    Optional<ResolvedTypetypeParamValue(ResolvedTypeParameterDeclaration typeParameterDeclaration);
40
41    /**
42     * Replace the type typeParametersValues present in the given type with the ones for which this type
43     * has a value.
44     */
45    default ResolvedType useThisTypeParametersOnTheGivenType(ResolvedType type) {
46        if (type.isTypeVariable()) {
47            ResolvedTypeParameterDeclaration typeParameter = type.asTypeParameter();
48            if (typeParameter.declaredOnType()) {
49                Optional<ResolvedTypetypeParam = typeParamValue(typeParameter);
50                if (typeParam.isPresent()) {
51                    type = typeParam.get();
52                }
53            }
54        }
55
56        if (type.isWildcard() && type.asWildcard().isBounded()) {
57            if (type.asWildcard().isExtends()) {
58                return ResolvedWildcard.extendsBound(useThisTypeParametersOnTheGivenType(type.asWildcard().getBoundedType()));
59            } else {
60                return ResolvedWildcard.superBound(useThisTypeParametersOnTheGivenType(type.asWildcard().getBoundedType()));
61            }
62        }
63
64        if (type.isReferenceType()) {
65            type = type.asReferenceType().transformTypeParameters(this::useThisTypeParametersOnTheGivenType);
66        }
67
68        return type;
69    }
70
71    Optional<ResolvedTypegetGenericParameterByName(String name);
72}
73
MembersX
ResolvedTypeParameterValueProvider:typeParamValue
ResolvedTypeParameterValueProvider:useThisTypeParametersOnTheGivenType
ResolvedTypeParameterValueProvider:useThisTypeParametersOnTheGivenType:Block:Block:typeParameter
ResolvedTypeParameterValueProvider:getGenericParameterByName
ResolvedTypeParameterValueProvider:useThisTypeParametersOnTheGivenType:Block:Block:Block:typeParam
Members
X