View Javadoc

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