1 20 package com.puppycrawl.tools.checkstyle.checks.naming; 21 22 import com.puppycrawl.tools.checkstyle.api.DetailAST; 23 import com.puppycrawl.tools.checkstyle.api.ScopeUtils; 24 import com.puppycrawl.tools.checkstyle.api.TokenTypes; 25 26 57 public class ConstantNameCheck 58 extends AbstractNameCheck 59 { 60 61 public ConstantNameCheck() 62 { 63 super("^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$"); 64 } 65 66 67 public int[] getDefaultTokens() 68 { 69 return new int[] {TokenTypes.VARIABLE_DEF}; 70 } 71 72 73 protected final boolean mustCheckName(DetailAST aAST) 74 { 75 boolean retVal = false; 76 77 final DetailAST modifiersAST = 78 aAST.findFirstToken(TokenTypes.MODIFIERS); 79 final boolean isStatic = (modifiersAST != null) 80 && modifiersAST.branchContains(TokenTypes.LITERAL_STATIC); 81 final boolean isFinal = (modifiersAST != null) 82 && modifiersAST.branchContains(TokenTypes.FINAL); 83 84 if ((isStatic && isFinal) 85 || ScopeUtils.inInterfaceOrAnnotationBlock(aAST)) 86 { 87 final DetailAST nameAST = aAST.findFirstToken(TokenTypes.IDENT); 90 if ((nameAST != null) 91 && !("serialVersionUID".equals(nameAST.getText())) 92 && !("serialPersistentFields".equals(nameAST.getText()))) 93 { 94 retVal = true; 95 } 96 } 97 98 return retVal; 99 } 100 } 101 | Popular Tags |