@ Nullable private static JavaClass findCommonType ( Set < JavaClass > classes ) throws ClassNotFoundException { Set < JavaClass > possibleCommonTypes = new HashSet <> ( ) ; boolean populate = true ; for ( JavaClass cls : classes ) { if ( cls == null ) { return null ; } if ( Values . SLASHED_JAVA_LANG_OBJECT . equals ( cls . getClassName ( ) ) ) { continue ; } JavaClass [ ] infs = cls . getAllInterfaces ( ) ; JavaClass [ ] supers = cls . getSuperClasses ( ) ; if ( populate ) { possibleCommonTypes . addAll ( Arrays . asList ( infs ) ) ; possibleCommonTypes . addAll ( Arrays . asList ( supers ) ) ; possibleCommonTypes . remove ( Repository . lookupClass ( Values . SLASHED_JAVA_LANG_OBJECT ) ) ; populate = false ; } else { Set < JavaClass > retain = new HashSet <> ( ) ; retain . addAll ( Arrays . asList ( infs ) ) ; retain . addAll ( Arrays . asList ( supers ) ) ; possibleCommonTypes . retainAll ( retain ) ; } } if ( possibleCommonTypes . isEmpty ( ) ) { return null ; } for ( JavaClass cls : possibleCommonTypes ) { if ( cls . isInterface ( ) ) { return cls ; } } return possibleCommonTypes . iterator ( ) . next ( ) ; }
looks for a common superclass or interface for all the passed in types