15
15
16
16
import com .strobel .core .Comparer ;
17
17
import com .strobel .core .HashUtilities ;
18
+ import com .strobel .reflection .emit .TypeBuilder ;
18
19
import com .strobel .util .TypeUtils ;
19
20
20
21
import java .util .LinkedHashMap ;
@@ -36,20 +37,19 @@ public Key key(final Type<?> type, final TypeList typeArguments) {
36
37
return new Key (type .isGenericType () ? type .getGenericTypeDefinition () : type , typeArguments );
37
38
}
38
39
39
- public Type find (final Key key ) {
40
+ public Type <?> find (final Key key ) {
40
41
return _map .get (key );
41
42
}
42
43
43
44
public <T > Type <T []> getArrayType (final Type <T > elementType ) {
45
+ add (elementType );
46
+
44
47
Type <T []> arrayType = (Type <T []>) _arrayMap .get (elementType );
45
48
46
- if (arrayType ! = null ) {
47
- return arrayType ;
49
+ if (arrayType = = null ) {
50
+ _arrayMap . put ( elementType , arrayType = elementType . createArrayType ()) ;
48
51
}
49
52
50
- arrayType = elementType .createArrayType ();
51
- add (arrayType );
52
-
53
53
return arrayType ;
54
54
}
55
55
@@ -59,15 +59,15 @@ public <T> Type<T> getGenericType(final Type<T> type, final TypeList typeArgumen
59
59
typeArguments
60
60
);
61
61
62
- Type genericType = _map .get (key );
62
+ Type < T > genericType = ( Type < T >) _map .get (key );
63
63
64
64
if (genericType == null ) {
65
- genericType = new GenericType (
65
+ genericType = new GenericType <> (
66
66
type .getGenericTypeDefinition (),
67
67
typeArguments
68
68
);
69
69
70
- final Type existing = _map .put (key , genericType );
70
+ final Type < T > existing = ( Type < T >) _map .put (key , genericType );
71
71
72
72
if (existing != null ) {
73
73
return existing ;
@@ -85,7 +85,7 @@ public int size() {
85
85
return _map .size ();
86
86
}
87
87
88
- public void put (final Key key , final Type type ) {
88
+ void put (final Key key , final Type <?> type ) {
89
89
final String descriptor = key .descriptor ;
90
90
91
91
if (!_definitionMap .containsKey (descriptor )) {
@@ -102,26 +102,29 @@ public void put(final Key key, final Type type) {
102
102
}
103
103
104
104
_map .put (key , type );
105
+ }
105
106
106
- if (type .isArray ()) {
107
- final Type elementType = type .getElementType ();
108
- if (!_arrayMap .containsKey (elementType )) {
109
- _arrayMap .put (elementType , type );
110
- }
107
+ public void add (final Type <?> type ) {
108
+ Type <?> coreType = type ;
109
+
110
+ while (coreType .isArray ()) {
111
+ coreType = coreType .getElementType ();
112
+ }
113
+
114
+ if (coreType .isWildcardType () || coreType .isGenericParameter () || coreType instanceof TypeBuilder <?>) {
115
+ return ;
111
116
}
112
- }
113
117
114
- public void add (final Type type ) {
115
118
final TypeList typeArguments ;
116
119
117
- if (type .isGenericType ()) {
118
- typeArguments = type .getTypeBindings ().getBoundTypes ();
120
+ if (coreType .isGenericType ()) {
121
+ typeArguments = coreType .getTypeBindings ().getBoundTypes ();
119
122
}
120
123
else {
121
124
typeArguments = TypeList .empty ();
122
125
}
123
126
124
- put (key (type , typeArguments ), type );
127
+ put (key (coreType , typeArguments ), coreType );
125
128
}
126
129
127
130
final static class Key {
@@ -181,8 +184,8 @@ public final boolean equals(final Object o) {
181
184
}
182
185
183
186
for (int i = 0 , n = typeArguments .size (); i < n ; ++i ) {
184
- final Type argument = typeArguments .get (i );
185
- final Type otherArgument = otherArguments .get (i );
187
+ final Type <?> argument = typeArguments .get (i );
188
+ final Type <?> otherArgument = otherArguments .get (i );
186
189
187
190
if (!Comparer .equals (argument , otherArgument )) {
188
191
return false ;
0 commit comments