Class GenericClassCounterRule

  • All Implemented Interfaces:
    JavaParserVisitor, net.sourceforge.pmd.lang.rule.ImmutableLanguage, net.sourceforge.pmd.properties.PropertySource, net.sourceforge.pmd.Rule

    public class GenericClassCounterRule
    extends AbstractJavaRule

    A generic rule that can be configured to "count" classes of certain type based on either their name (full name, prefix, suffixes anything can be matched with a regex), and/or their type.

    Example of configurations:

         <!-- Property order is MANDATORY !!! -->
         <!-- Several regexes may be provided to ensure a match... -->
         <property name="nameMatch" description="a regex on which to match"
             value="^Abstract.*Bean*$,^*EJB*$"/>
         <!-- An operand to refine match strategy TODO: Not implemented yet !!! -->
         <property name"operand" description=""
             value="and"/> <!-- possible values are and/or -->
         <!-- Must be a full name to ensure type control !!! -->
         <property name="typeMatch" description="a regex to match on implements/extends classname"
             value="javax.servlet.Filter"/>
         <!-- Define after how many occurences one should log a violation -->
         <property name="threshold" description="Defines how many occurences are legal"
             value="2"/>
         <!-- TODO: Add a parameter to allow "ignore" pattern based on name -->
     
    Author:
    Ryan Gutafson, [email protected], Romain PELISSE, [email protected]
    • Constructor Detail

      • GenericClassCounterRule

        public GenericClassCounterRule()
    • Method Detail

      • init

        protected void init()
      • start

        public void start​(net.sourceforge.pmd.RuleContext ctx)
        Specified by:
        start in interface net.sourceforge.pmd.Rule
        Overrides:
        start in class net.sourceforge.pmd.lang.rule.AbstractRule
      • end

        public void end​(net.sourceforge.pmd.RuleContext ctx)
        Specified by:
        end in interface net.sourceforge.pmd.Rule
        Overrides:
        end in class net.sourceforge.pmd.lang.rule.AbstractRule