1 package com.puppycrawl.tools.checkstyle.checks.j2ee; 20 21 import com.puppycrawl.tools.checkstyle.api.DetailAST; 22 import com.puppycrawl.tools.checkstyle.api.TokenTypes; 23 24 29 public class BeanManagedMethodChecker 30 extends EntityBeanMethodChecker 31 { 32 33 private boolean mHasEjbFindByPrimaryKey; 34 35 39 public BeanManagedMethodChecker(EntityBeanCheck aCheck) 40 { 41 super(aCheck); 42 } 43 44 47 public void checkMethods(DetailAST aAST) 48 { 49 mHasEjbFindByPrimaryKey = false; 50 super.checkMethods(aAST); 51 if (!mHasEjbFindByPrimaryKey) { 52 final DetailAST nameAST = aAST.findFirstToken(TokenTypes.IDENT); 53 final String name = nameAST.getText(); 54 final String arg = "Entity bean '" + name + "'"; 55 log(aAST, "missingmethod.bean", 56 new Object [] {arg, "ejbFindByPrimaryKey"}); 57 } 58 } 59 60 63 public void checkMethod(DetailAST aMethodAST) 64 { 65 super.checkMethod(aMethodAST); 66 67 final DetailAST nameAST = aMethodAST.findFirstToken(TokenTypes.IDENT); 68 final String name = nameAST.getText(); 69 70 if (name.startsWith("ejbFind")) { 71 if (name.equals("ejbFindByPrimaryKey")) { 72 mHasEjbFindByPrimaryKey = true; 73 final DetailAST paramAST = 75 aMethodAST.findFirstToken(TokenTypes.PARAMETERS); 76 final int paramCount = paramAST.getChildCount(); 77 if (paramCount != 1) { 78 logName(aMethodAST, "paramcount.bean", new Object [] {"1"}); 79 } 80 } 81 checkFindMethod(aMethodAST); 82 } 83 } 84 85 90 private void checkFindMethod(DetailAST aMethodAST) 91 { 92 super.checkMethod(aMethodAST, false); 94 95 if (Utils.isVoid(aMethodAST)) { 98 logName(aMethodAST, "voidmethod.bean", new Object [] {}); 99 } 100 } 101 } 102 | Popular Tags |