Optional < ? extends AttributeDescriptor > referencingAttribute ( AttributeDescriptor attribute , EntityDescriptor referenced ) { String referencedColumn = attribute . referencedColumn ( ) ; if ( Names . isEmpty ( referencedColumn ) ) { // using the id List < AttributeDescriptor > keys = referenced . attributes ( ) . stream ( ) . filter ( AttributeDescriptor :: isKey ) . collect ( Collectors . toList ( ) ) ; if ( keys . size ( ) == 1 ) { return Optional . of ( keys . get ( 0 ) ) ; } else { return keys . stream ( ) . filter ( other -> other . typeMirror ( ) . equals ( attribute . typeMirror ( ) ) ) . findFirst ( ) ; } } else { return referenced . attributes ( ) . stream ( ) . filter ( other -> other . name ( ) . equals ( referencedColumn ) ) . findFirst ( ) ; } }
Given an attribute in a given type finds the corresponding attribute that it is referencing in that referencing type .