private static ClassNode buildTypeWithInterfaces ( ClassNode baseType1 , ClassNode baseType2 , Collection < ClassNode > interfaces ) { boolean noInterface = interfaces . isEmpty ( ) ; if ( noInterface ) { if ( baseType1 . equals ( baseType2 ) ) return baseType1 ; if ( baseType1 . isDerivedFrom ( baseType2 ) ) return baseType2 ; if ( baseType2 . isDerivedFrom ( baseType1 ) ) return baseType1 ; } if ( OBJECT_TYPE . equals ( baseType1 ) && OBJECT_TYPE . equals ( baseType2 ) && interfaces . size ( ) == 1 ) { if ( interfaces instanceof List ) { return ( ( List < ClassNode > ) interfaces ) . get ( 0 ) ; } return interfaces . iterator ( ) . next ( ) ; } LowestUpperBoundClassNode type ; ClassNode superClass ; String name ; if ( baseType1 . equals ( baseType2 ) ) { if ( OBJECT_TYPE . equals ( baseType1 ) ) { superClass = baseType1 ; name = "Virtual$Object" ; } else { superClass = baseType1 ; name = "Virtual$" + baseType1 . getName ( ) ; } } else { superClass = OBJECT_TYPE ; if ( baseType1 . isDerivedFrom ( baseType2 ) ) { superClass = baseType2 ; } else if ( baseType2 . isDerivedFrom ( baseType1 ) ) { superClass = baseType1 ; } name = "CommonAssignOf$" + baseType1 . getName ( ) + "$" + baseType2 . getName ( ) ; } Iterator < ClassNode > itcn = interfaces . iterator ( ) ; while ( itcn . hasNext ( ) ) { ClassNode next = itcn . next ( ) ; if ( superClass . isDerivedFrom ( next ) || superClass . implementsInterface ( next ) ) { itcn . remove ( ) ; } } ClassNode [ ] interfaceArray = interfaces . toArray ( ClassNode . EMPTY_ARRAY ) ; Arrays . sort ( interfaceArray , INTERFACE_CLASSNODE_COMPARATOR ) ; type = new LowestUpperBoundClassNode ( name , superClass , interfaceArray ) ; return type ; }
Given two class nodes supposedly at the upper common level returns a class node which is able to represent their lowest upper bound .