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


(Braedan) #1

I am looking to write a custom java rule to enforce that a test class name follows a regex pattern, but also contains a valid class name from the main scope. For example, the class in main scope:
package com.test;

public class ABC {


And the rule file:

public class RandomTest { // Noncompliant


public class ABCTest { // Compliant

(All test class files ending with must match Files that don’t end in wouldn’t be matched and don’t need this restriction)

I’ve been playing around and I am able to run rules on test scope, but I am unable to check or access semantic information from the main scope. Any help or insight will be greatly appreciated. Thanks!