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 38 public abstract class AbstractBeanCheck 39 extends AbstractJ2eeCheck 40 { 41 44 public int[] getDefaultTokens() 45 { 46 return new int[] {TokenTypes.CLASS_DEF}; 47 } 48 49 52 public int[] getRequiredTokens() 53 { 54 return getDefaultTokens(); 55 } 56 57 68 protected void checkBean( 69 DetailAST aAST, 70 String aBeanType, 71 boolean aAllowAbstract) 72 { 73 final DetailAST nameAST = aAST.findFirstToken(TokenTypes.IDENT); 74 final String name = nameAST.getText(); 75 final String arg = aBeanType + " '" + name + "'"; 76 77 if (!Utils.isPublic(aAST)) { 78 log(nameAST.getLineNo(), nameAST.getColumnNo(), 79 "nonpublic.bean", arg); 80 } 81 if (Utils.isFinal(aAST)) { 82 log(nameAST.getLineNo(), nameAST.getColumnNo(), 83 "illegalmodifier.bean", 84 new Object [] {arg, "final"}); 85 } 86 if (!aAllowAbstract && Utils.isAbstract(aAST)) { 87 log(nameAST.getLineNo(), nameAST.getColumnNo(), 88 "illegalmodifier.bean", 89 new Object [] {arg, "abstract"}); 90 } 91 if (!Utils.hasPublicConstructor(aAST, 0)) { 92 log(nameAST.getLineNo(), nameAST.getColumnNo(), 93 "nonpublicconstructor.bean", arg); 94 } 95 if (Utils.hasPublicMethod(aAST, "finalize", true, 0)) { 96 log( 97 nameAST.getLineNo(), 98 nameAST.getColumnNo(), 99 "hasfinalize.bean", 100 arg); 101 } 102 } 103 } 104 | Popular Tags |