Class AbstractInefficientZeroCheck

  • All Implemented Interfaces:
    JavaParserVisitor, net.sourceforge.pmd.lang.rule.ImmutableLanguage, net.sourceforge.pmd.properties.PropertySource, net.sourceforge.pmd.Rule
    Direct Known Subclasses:
    InefficientEmptyStringCheckRule, UseCollectionIsEmptyRule

    public abstract class AbstractInefficientZeroCheck
    extends AbstractJavaRule
    This is an abstract rule for patterns which compare a method invocation to 0. It could be further abstracted to find code that compares something to another definable pattern
    Author:
    acaplan
    • Constructor Detail

      • AbstractInefficientZeroCheck

        public AbstractInefficientZeroCheck()
    • Method Detail

      • appliesToClassName

        public abstract boolean appliesToClassName​(java.lang.String name)
      • getComparisonTargets

        public java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getComparisonTargets()
        For each relation/equality operator, comparison targets need to define.
        Returns:
        map
      • checkNodeAndReport

        protected void checkNodeAndReport​(java.lang.Object data,
                                          net.sourceforge.pmd.lang.ast.Node location,
                                          net.sourceforge.pmd.lang.ast.Node expr)
        Checks whether the given expression is a equality/relation expression that compares with a size() call.
        Parameters:
        data - the rule context
        location - the node location to report
        expr - the ==, <, > expression