View Javadoc

    1   package net.sourceforge.pmd.lang.java.rule.strings;
    2
    3   import net.sourceforge.pmd.lang.ast.Node;
    4   import net.sourceforge.pmd.lang.java.ast.ASTLiteral;
    5   import net.sourceforge.pmd.lang.java.rule.AbstractPoorMethodCall;
    6
    7   /**
    8    */
    9   public class UseIndexOfCharRule extends AbstractPoorMethodCall {
    10
    11      private static final String TARGET_TYPE_NAME = "String";
    12      private static final String[] METHOD_NAMES = new String[] { "indexOf", "lastIndexOf" };
    13
    14      /**
    15       * Method targetTypeName.
    16       * @return String
    17       */
    18      @Override
    19      protected String targetTypename() {
    20          return TARGET_TYPE_NAME;
    21      }
    22
    23      /**
    24       * Method methodNames.
    25       * @return String[]
    26       */
    27      @Override
    28      protected String[] methodNames() {
    29          return METHOD_NAMES;
    30      }
    31
    32      /**
    33       * {@inheritDoc}
    34       */
    35      protected boolean isViolationArgument(Node arg) {
    36          return ((ASTLiteral) arg).isSingleCharacterStringLiteral();
    37      }
    38
    39  }