 <p>You can do <a href="http://pmd.sourceforge.net/howtowritearule.html#I_want_to_implement_a_rule_that_analyse_more_than_the_class__" rel="nofollow noreferrer">cross-class analysis in PMD</a> (though I've never used it for this specific purpose). I think it's possible using this visitor pattern that they document, though I'll leave the specifics to you.</p>