View Javadoc

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