KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > pmd > rules > strings > StringToStringRule


1 /**
2  * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3  */

4 package net.sourceforge.pmd.rules.strings;
5
6 import net.sourceforge.pmd.AbstractRule;
7 import net.sourceforge.pmd.ast.ASTVariableDeclaratorId;
8 import net.sourceforge.pmd.symboltable.NameOccurrence;
9
10 import java.util.Iterator JavaDoc;
11
12 public class StringToStringRule extends AbstractRule {
13
14     public Object JavaDoc visit(ASTVariableDeclaratorId node, Object JavaDoc data) {
15         if (!node.getNameDeclaration().getTypeImage().equals("String")) {
16             return data;
17         }
18         for (Iterator JavaDoc i = node.getUsages().iterator(); i.hasNext();) {
19             NameOccurrence occ = (NameOccurrence) i.next();
20             if (occ.getNameForWhichThisIsAQualifier() != null && occ.getNameForWhichThisIsAQualifier().getImage().indexOf("toString") != -1) {
21                 addViolation(data, occ.getLocation());
22             }
23         }
24         return data;
25     }
26 }
27
Popular Tags