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.Check; 25 import com.puppycrawl.tools.checkstyle.api.DetailAST; 26 import com.puppycrawl.tools.checkstyle.api.TokenTypes; 27 28 55 public class IllegalTokenCheck 56 extends Check 57 { 58 61 public int[] getDefaultTokens() 62 { 63 return new int[] { 64 TokenTypes.LITERAL_SWITCH, 65 TokenTypes.POST_INC, 66 TokenTypes.POST_DEC, 67 }; 68 } 69 70 73 public int[] getAcceptableTokens() 74 { 75 int[] tokensToCopy = getDefaultTokens(); 77 final Set tokenNames = getTokenNames(); 78 if (!tokenNames.isEmpty()) { 79 tokensToCopy = new int[tokenNames.size()]; 80 int i = 0; 81 final Iterator it = tokenNames.iterator(); 82 while (it.hasNext()) { 83 final String name = (String ) it.next(); 84 tokensToCopy[i] = TokenTypes.getTokenId(name); 85 i++; 86 } 87 } 88 final int[] copy = new int[tokensToCopy.length]; 89 System.arraycopy(tokensToCopy, 0, copy, 0, tokensToCopy.length); 90 return copy; 91 } 92 93 96 public void visitToken(DetailAST aAST) 97 { 98 log( 99 aAST.getLineNo(), 100 aAST.getColumnNo(), 101 "illegal.token", 102 aAST.getText()); 103 } 104 105 } 106 | Popular Tags |