private static Type transformOwner ( Type givenOwner , Class < ? > clazz ) { if ( givenOwner == null ) { // be lenient: if this is an inner class but no owner was specified, assume a raw owner type // (or if there is no owner just return null) return clazz . getDeclaringClass ( ) ; } else { // If the specified owner is not of the declaring class' type, but instead a subtype, // transform it into the declaring class with the exact type parameters. // For example with "class StringOuter extends GenericOuter<String>", transform // "StringOuter.Inner" into "GenericOuter<String>.Inner", just like the Java compiler does. Type transformedOwner = GenericTypeReflector . getExactSuperType ( givenOwner , clazz . getDeclaringClass ( ) ) ; if ( transformedOwner == null ) { // null means it's not a supertype throw new IllegalArgumentException ( "Given owner type [" + givenOwner + "] is not appropriate for [" + clazz + "]: it should be a subtype of " + clazz . getDeclaringClass ( ) ) ; } if ( Modifier . isStatic ( clazz . getModifiers ( ) ) ) { // for a static inner class, the owner shouldn't have type parameters return GenericTypeReflector . erase ( transformedOwner ) ; } else { return transformedOwner ; } } }
Transforms the given owner type into an appropriate one when constructing a parameterized type .