1 package com.puppycrawl.tools.checkstyle.checks.j2ee; 20 21 import java.util.HashSet ; 22 import java.util.Iterator ; 23 import java.util.Set ; 24 25 import com.puppycrawl.tools.checkstyle.api.DetailAST; 26 import com.puppycrawl.tools.checkstyle.api.TokenTypes; 27 28 32 public class EntityBeanMethodChecker 33 extends BeanMethodChecker 34 { 35 36 private final Set mEjbCreates = new HashSet (); 37 38 39 private final Set mEjbPostCreates = new HashSet (); 40 41 45 public EntityBeanMethodChecker(EntityBeanCheck aCheck) 46 { 47 super(aCheck); 48 } 49 50 53 public void checkMethods(DetailAST aAST) 54 { 55 mEjbCreates.clear(); 56 mEjbPostCreates.clear(); 57 58 super.checkMethods(aAST); 59 60 checkCreateMatch(); 61 } 62 63 66 protected void checkCreateMatch() 67 { 68 final Iterator it = mEjbCreates.iterator(); 69 while (it.hasNext()) { 70 final DetailAST createMethod = (DetailAST) it.next(); 71 final DetailAST nameAST = 72 createMethod.findFirstToken(TokenTypes.IDENT); 73 final String name = nameAST.getText(); 74 final String method = name.substring("ejbCreate".length()); 75 76 boolean match = false; 78 final Iterator itPostCreate = mEjbPostCreates.iterator(); 79 while (!match && itPostCreate.hasNext()) { 80 final DetailAST postCreateMethod = 81 (DetailAST) itPostCreate.next(); 82 final DetailAST postCreateNameAST = 83 postCreateMethod.findFirstToken(TokenTypes.IDENT); 84 final String postCreateName = postCreateNameAST.getText(); 85 if (!postCreateName.equals("ejbPostCreate" + method)) { 86 continue; 87 } 88 match = 89 Utils.sameParameters(createMethod, postCreateMethod); 90 } 91 if (!match) { 92 final String suffix = name.substring("ejbCreate".length()); 93 final String postCreateName = "ejbPostCreate" + suffix; 94 logName(createMethod, "unmatchedejbcreate.bean", 95 new Object [] {postCreateName}); 96 } 97 } 98 } 99 100 103 public void checkMethod(DetailAST aMethodAST) 104 { 105 super.checkMethod(aMethodAST); 106 107 final DetailAST nameAST = aMethodAST.findFirstToken(TokenTypes.IDENT); 108 final String name = nameAST.getText(); 109 110 if (name.startsWith("ejbHome")) { 111 checkHomeMethod(aMethodAST); 112 } 113 else if (name.startsWith("ejbPostCreate")) { 114 checkPostCreateMethod(aMethodAST); 115 } 116 } 117 118 121 protected void checkCreateMethod(DetailAST aMethodAST) 122 { 123 super.checkCreateMethod(aMethodAST); 124 125 mEjbCreates.add(aMethodAST); 126 127 if (Utils.isVoid(aMethodAST)) { 129 logName(aMethodAST, "voidmethod.bean", new Object [] {}); 130 } 131 } 132 133 134 139 protected void checkHomeMethod(DetailAST aMethodAST) 140 { 141 checkMethod(aMethodAST, true); 143 144 checkNotThrows(aMethodAST, "java.rmi.RemoteException"); 147 } 148 149 154 protected void checkPostCreateMethod(DetailAST aMethodAST) 155 { 156 checkMethod(aMethodAST, false); 158 159 mEjbPostCreates.add(aMethodAST); 160 161 if (!Utils.isVoid(aMethodAST)) { 163 logName(aMethodAST, "nonvoidmethod.bean", new Object [] {}); 164 } 165 } 166 } 167 | Popular Tags |