public static MethodNode findSAM ( ClassNode type ) { if ( ! Modifier . isAbstract ( type . getModifiers ( ) ) ) return null ; if ( type . isInterface ( ) ) { List < MethodNode > methods = type . getMethods ( ) ; MethodNode found = null ; for ( MethodNode mi : methods ) { // ignore methods, that are not abstract and from Object if ( ! Modifier . isAbstract ( mi . getModifiers ( ) ) ) continue ; // ignore trait methods which have a default implementation if ( Traits . hasDefaultImplementation ( mi ) ) continue ; if ( mi . getDeclaringClass ( ) . equals ( OBJECT_TYPE ) ) continue ; if ( OBJECT_TYPE . getDeclaredMethod ( mi . getName ( ) , mi . getParameters ( ) ) != null ) continue ; // we have two methods, so no SAM if ( found != null ) return null ; found = mi ; } return found ; } else { List < MethodNode > methods = type . getAbstractMethods ( ) ; MethodNode found = null ; if ( methods != null ) { for ( MethodNode mi : methods ) { if ( ! hasUsableImplementation ( type , mi ) ) { if ( found != null ) return null ; found = mi ; } } } return found ; } }
Returns the single abstract method of a class node if it is a SAM type or null otherwise .