@@ -33,12 +33,14 @@ public JavaExecutable(Resolver aResolver, DeclType aType, JavaClass aDeclaringCl
3333
3434 // Get VarArgs
3535 _varArgs = anExecutable .isVarArgs ();
36+ }
3637
37- // Get TypeVariables
38- TypeVariable <?>[] typeVars = anExecutable .getTypeParameters ();
39- _typeVars = new JavaTypeVariable [typeVars .length ];
40- for (int i = 0 , iMax = typeVars .length ; i < iMax ; i ++)
41- _typeVars [i ] = new JavaTypeVariable (_resolver , this , typeVars [i ]);
38+ /**
39+ * Returns the executable.
40+ */
41+ private Executable getExecutable ()
42+ {
43+ return this instanceof JavaMethod ? ((JavaMethod ) this ).getMethod () : ((JavaConstructor ) this ).getConstructor ();
4244 }
4345
4446 /**
@@ -49,14 +51,28 @@ public JavaExecutable(Resolver aResolver, DeclType aType, JavaClass aDeclaringCl
4951 /**
5052 * Returns the TypeVars.
5153 */
52- public JavaTypeVariable [] getTypeVars () { return _typeVars ; }
54+ public JavaTypeVariable [] getTypeVars ()
55+ {
56+ if (_typeVars != null ) return _typeVars ;
57+
58+ // Get TypeVariables
59+ Executable executable = getExecutable ();
60+ TypeVariable <?>[] typeVars = executable .getTypeParameters ();
61+ JavaTypeVariable [] javaTypeVars = new JavaTypeVariable [typeVars .length ];
62+ for (int i = 0 , iMax = typeVars .length ; i < iMax ; i ++)
63+ javaTypeVars [i ] = new JavaTypeVariable (_resolver , this , typeVars [i ]);
64+
65+ // Set and return
66+ return _typeVars = javaTypeVars ;
67+ }
5368
5469 /**
5570 * Returns the TypeVar with given name.
5671 */
5772 public JavaTypeVariable getTypeVarForName (String aName )
5873 {
59- return ArrayUtils .findMatch (_typeVars , tvar -> tvar .getName ().equals (aName ));
74+ JavaTypeVariable [] typeVars = getTypeVars ();
75+ return ArrayUtils .findMatch (typeVars , tvar -> tvar .getName ().equals (aName ));
6076 }
6177
6278 /**
@@ -85,10 +101,10 @@ public JavaType[] getParameterTypes()
85101 if (_parameterTypes != null ) return _parameterTypes ;
86102
87103 // Get GenericParameterTypes (this can fail https://bugs.openjdk.java.net/browse/JDK-8075483))
88- Executable exec = this instanceof JavaMethod ? (( JavaMethod ) this ). getMethod () : (( JavaConstructor ) this ). getConstructor ();
89- Type [] paramTypesReal = exec .getGenericParameterTypes ();
90- if (paramTypesReal .length < exec .getParameterCount ())
91- paramTypesReal = exec .getParameterTypes ();
104+ Executable executable = getExecutable ();
105+ Type [] paramTypesReal = executable .getGenericParameterTypes ();
106+ if (paramTypesReal .length < executable .getParameterCount ())
107+ paramTypesReal = executable .getParameterTypes ();
92108
93109 JavaType [] parameterTypes = _resolver .getJavaTypesForTypes (paramTypesReal );
94110
0 commit comments