1 /*** 2 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html 3 */ 4 package net.sourceforge.pmd.rules; 5 6 import net.sourceforge.pmd.AbstractRule; 7 import net.sourceforge.pmd.RuleContext; 8 import net.sourceforge.pmd.ast.ASTMethodDeclarator; 9 10 public class MethodNamingConventions extends AbstractRule { 11 12 public Object visit(ASTMethodDeclarator node, Object data) { 13 if (Character.isUpperCase(node.getImage().charAt(0))) { 14 RuleContext ctx = (RuleContext) data; 15 ctx.getReport().addRuleViolation(createRuleViolation(ctx, node, getMessage())); 16 } 17 18 if (node.getImage().indexOf("_") >= 0) { 19 String msg = "Method names should not contain underscores"; 20 RuleContext ctx = (RuleContext) data; 21 ctx.getReport().addRuleViolation(createRuleViolation(ctx, node, msg)); 22 23 } 24 return data; 25 } 26 27 }