Custom java rule to match a test class name to a class name in main scope

In short : what you are trying to achieve is not easily doable as per design of analyzer on a “by file” basis as of today.

One workaround you could imagine would be to list files in your main directory and infer class name from that (or from the compiled directory as well) : but this is more of a dirty hack than a clever solution.