2424import com .arangodb .velocypack .annotations .VPackPOJOBuilder ;
2525
2626import java .lang .annotation .Annotation ;
27- import java .lang .reflect .AnnotatedElement ;
28- import java .lang .reflect .Method ;
29- import java .lang .reflect .Type ;
27+ import java .lang .reflect .*;
3028import java .util .Map ;
3129import java .util .Objects ;
3230import java .util .concurrent .ConcurrentHashMap ;
@@ -84,7 +82,18 @@ public VPackBuilderUtils() {
8482 }
8583
8684 public BuilderInfo getBuilderInfo (Type type , AnnotatedElement referencingElement ) {
87- final CacheKey key = new CacheKey (type , referencingElement );
85+ if (type instanceof ParameterizedType )
86+ return getBuilderInfo (((ParameterizedType ) type ).getRawType (), referencingElement );
87+
88+ if (type instanceof WildcardType )
89+ return getBuilderInfo (((WildcardType ) type ).getUpperBounds ()[0 ], referencingElement );
90+
91+ if (!(type instanceof Class <?>))
92+ return null ;
93+
94+ final Class <?> clazz = (Class <?>) type ;
95+
96+ final CacheKey key = new CacheKey (clazz , referencingElement );
8897 BuilderInfo fromCache = cache .get (key );
8998 if (fromCache != null )
9099 return fromCache ;
@@ -93,13 +102,13 @@ public BuilderInfo getBuilderInfo(Type type, AnnotatedElement referencingElement
93102
94103 builderInfo = getReferencingElementInfo (referencingElement );
95104 if (builderInfo == null ) {
96- builderInfo = getDeserializeClassInfo (type );
105+ builderInfo = getDeserializeClassInfo (clazz );
97106 }
98107 if (builderInfo == null ) {
99- builderInfo = getBuilderMethodInfo (type );
108+ builderInfo = getBuilderMethodInfo (clazz );
100109 }
101110 if (builderInfo == null ) {
102- builderInfo = getInnerBuilderInfo (type );
111+ builderInfo = getInnerBuilderInfo (clazz );
103112 }
104113
105114 if (builderInfo == null ) {
@@ -126,11 +135,7 @@ public BuilderInfo getBuilderInfo(Type type, AnnotatedElement referencingElement
126135 return builderInfo ;
127136 }
128137
129- private BuilderInfo getBuilderMethodInfo (Type type ) {
130- if (!(type instanceof Class <?>))
131- return null ;
132-
133- Class <?> clazz = (Class <?>) type ;
138+ private BuilderInfo getBuilderMethodInfo (final Class <?> clazz ) {
134139 for (final Method method : clazz .getDeclaredMethods ()) {
135140 for (final Annotation annotation : method .getDeclaredAnnotations ()) {
136141 if (annotation instanceof VPackPOJOBuilder ) {
@@ -147,11 +152,7 @@ public Object createBuilder() throws ReflectiveOperationException {
147152 return null ;
148153 }
149154
150- private BuilderInfo getInnerBuilderInfo (Type type ) {
151- if (!(type instanceof Class <?>))
152- return null ;
153-
154- Class <?> clazz = (Class <?>) type ;
155+ private BuilderInfo getInnerBuilderInfo (final Class <?> clazz ) {
155156 for (final Class <?> innerClass : clazz .getDeclaredClasses ()) {
156157 for (final Annotation annotation : innerClass .getDeclaredAnnotations ()) {
157158 if (annotation instanceof VPackPOJOBuilder ) {
@@ -168,11 +169,7 @@ public Object createBuilder() throws ReflectiveOperationException {
168169 return null ;
169170 }
170171
171- private BuilderInfo getBuilderInfo (Type type ) {
172- if (!(type instanceof Class <?>))
173- return null ;
174-
175- Class <?> clazz = (Class <?>) type ;
172+ private BuilderInfo getBuilderInfo (final Class <?> clazz ) {
176173 for (final Annotation annotation : clazz .getDeclaredAnnotations ()) {
177174 if (annotation instanceof VPackPOJOBuilder ) {
178175 return new BuilderInfo (clazz , mapVPackPOJOBuilder ((VPackPOJOBuilder ) annotation )) {
@@ -187,11 +184,7 @@ public Object createBuilder() throws ReflectiveOperationException {
187184 return null ;
188185 }
189186
190- private BuilderInfo getDeserializeClassInfo (Type type ) {
191- if (!(type instanceof Class <?>))
192- return null ;
193-
194- Class <?> clazz = (Class <?>) type ;
187+ private BuilderInfo getDeserializeClassInfo (final Class <?> clazz ) {
195188 for (final Annotation annotation : clazz .getDeclaredAnnotations ()) {
196189 if (annotation instanceof VPackDeserialize ) {
197190 final VPackDeserialize vPackDeserialize = (VPackDeserialize ) annotation ;
0 commit comments