1 package com.fasterxml.jackson.databind.introspect;
2
3 import java.lang.reflect.Type;
4
5 import com.fasterxml.jackson.databind.JavaType;
6 import com.fasterxml.jackson.databind.type.TypeBindings;
7 import com.fasterxml.jackson.databind.type.TypeFactory;
8
9 /**
10  * Interface that defines API used by members (like {@link AnnotatedMethod})
11  * to dynamically resolve types they have.
12  *
13  * @since 2.7
14  */

15 public interface TypeResolutionContext {
16     public JavaType resolveType(Type t);
17
18     public static class Basic
19         implements TypeResolutionContext
20     {
21         private final TypeFactory _typeFactory;
22         private final TypeBindings _bindings;
23
24         public Basic(TypeFactory tf, TypeBindings b) {
25             _typeFactory = tf;
26             _bindings = b;
27         }
28
29         @Override
30         public JavaType resolveType(Type type) {
31             // 15-Jun-2020, tatu: As a consequence of [databind#2796], need to
32             //    AVOID passing bindings for raw, type-erased cases, as otherwise
33             //    we seem to get odd "generic Long" cases (for Mr Bean module at least)
34             if (type instanceof Class<?>) {
35                 return _typeFactory.constructType(type);
36             }
37             return _typeFactory.constructType(type, _bindings);
38         }
39
40         /*// debugging
41         @Override
42         public String toString() {
43             return "[TRC.Basic, bindings: "+_bindings+"]";
44         }
45         */

46     }
47
48     /**
49      * Dummy implementation for case where there are no bindings available
50      * (for example, for static methods and fields)
51      *
52      * @since 2.11.3
53      */

54     public static class Empty
55         implements TypeResolutionContext
56     {
57         private final TypeFactory _typeFactory;
58
59         public Empty(TypeFactory tf) {
60             _typeFactory = tf;
61         }
62
63         @Override
64         public JavaType resolveType(Type type) {
65             return _typeFactory.constructType(type);
66         }
67     }
68 }
69