1 package com.puppycrawl.tools.checkstyle.checks.coding; 20 21 import java.util.Iterator ; 22 import java.util.Set ; 23 24 import com.puppycrawl.tools.checkstyle.api.DetailAST; 25 import com.puppycrawl.tools.checkstyle.api.TokenTypes; 26 import com.puppycrawl.tools.checkstyle.checks.GenericIllegalRegexpCheck; 27 28 53 public class IllegalTokenTextCheck 54 extends GenericIllegalRegexpCheck 55 { 56 57 public void beginTree(DetailAST aRootAST) 58 { 59 } 60 61 62 public int[] getAcceptableTokens() 63 { 64 final Set tokenNames = getTokenNames(); 66 final int[] result = new int[tokenNames.size()]; 67 int i = 0; 68 final Iterator it = tokenNames.iterator(); 69 while (it.hasNext()) { 70 final String name = (String ) it.next(); 71 result[i] = TokenTypes.getTokenId(name); 72 i++; 73 } 74 return result; 75 } 76 79 public void visitToken(DetailAST aAST) 80 { 81 final String text = aAST.getText(); 82 if (getRegexp().matcher(text).find()) { 83 String message = getMessage(); 84 if ("".equals(message)) { 85 message = "illegal.token.text"; 86 } 87 log( 88 aAST.getLineNo(), 89 aAST.getColumnNo(), 90 message, 91 getFormat()); 92 } 93 } 94 } 95 | Popular Tags |