Custom rule invoked after compilation unit is checked

Hi there, I want to implement a custom rule to check the proper usage of java.util.Map . Some of my programmers use a map with the keys "name" and "birthday" to treat a person object instead of creating an own Person class like this:

public class Person {
    private String name;
    private LocalDate birthday;

So I want to implement a rule that visits all invocations of java.util.Map.add(Object key, Object value) and counts, how often a certain key has been used. And when the check of all classes has been completed, it should raise an issue in case the count for a key is greater than a certain threshold. But I don’t know how to make my custom rule get informed when the check of all classes has completed. Has anybody an idea?

Many thanks in advance!


I was hoping someone with more and more recent experience would answer, but…

I don’t think you’re going to be able to do this.

What you want is a rule based on a cross-file metric. I believe file-level merics are calculated/counted during CI-side analysis, and higher-level metrics are aggregated server side. But rules run before that, analysis side. So you have a chicken/egg problem here.

Yes, there are some (6, to be precise) rules based on metrics. Those special rules run server side. They’re hard-coded into the server and I doubt the APIs are open to add more. Aaand, we’re talking internally about deprecating them soon and dropping them in 10.0.


Hi Ann, thanks for these informations. I was fearing something like that…