1 package com.puppycrawl.tools.checkstyle.api; 20 21 import java.util.HashSet ; 22 import java.util.Set ; 23 24 25 33 public abstract class Check extends AbstractViolationReporter 34 { 35 36 private static final int DEFAULT_TAB_WIDTH = 8; 37 38 39 private FileContents mFileContents; 40 41 42 private final Set mTokens = new HashSet (); 43 44 45 private LocalizedMessages mMessages; 46 47 48 private int mTabWidth = DEFAULT_TAB_WIDTH; 50 54 private ClassLoader mLoader; 55 56 62 public abstract int[] getDefaultTokens(); 63 64 72 public int[] getAcceptableTokens() 73 { 74 final int[] defaultTokens = getDefaultTokens(); 75 final int[] copy = new int[defaultTokens.length]; 76 System.arraycopy(defaultTokens, 0, copy, 0, defaultTokens.length); 77 return copy; 78 } 79 80 85 public int[] getRequiredTokens() 86 { 87 return new int[] {}; 88 } 89 90 94 public final void setTokens(String [] aStrRep) 95 { 96 for (int i = 0; i < aStrRep.length; i++) { 97 final String s = aStrRep[i]; 98 mTokens.add(s); 99 } 100 } 101 102 106 public final Set getTokenNames() 107 { 108 return mTokens; 109 } 110 111 115 public final void setMessages(LocalizedMessages aMessages) 116 { 117 mMessages = aMessages; 118 } 119 120 124 public void init() 125 { 126 } 127 128 131 public void destroy() 132 { 133 } 134 135 140 public void beginTree(DetailAST aRootAST) 141 { 142 } 143 144 149 public void finishTree(DetailAST aRootAST) 150 { 151 } 152 153 157 public void visitToken(DetailAST aAST) 158 { 159 } 160 161 165 public void leaveToken(DetailAST aAST) 166 { 167 } 168 169 173 public final String [] getLines() 174 { 175 return getFileContents().getLines(); 176 } 177 178 182 public final void setFileContents(FileContents aContents) 183 { 184 mFileContents = aContents; 185 } 186 187 191 public final FileContents getFileContents() 192 { 193 return mFileContents; 194 } 195 196 200 public final void setClassLoader(ClassLoader aLoader) 201 { 202 mLoader = aLoader; 203 } 204 205 209 public final ClassLoader getClassLoader() 210 { 211 return mLoader; 212 } 213 214 215 protected final int getTabWidth() 216 { 217 return mTabWidth; 218 } 219 220 224 public final void setTabWidth(int aTabWidth) 225 { 226 mTabWidth = aTabWidth; 227 } 228 229 238 protected final void log(int aLine, String aKey, Object aArgs[]) 239 { 240 mMessages.add( 241 new LocalizedMessage( 242 aLine, 243 getMessageBundle(), 244 aKey, 245 aArgs, 246 getSeverityLevel(), 247 getId(), 248 this.getClass())); 249 } 250 251 252 260 protected final void log(int aLineNo, int aColNo, 261 String aKey, Object [] aArgs) 262 { 263 final int col = 1 + Utils.lengthExpandedTabs( 264 getLines()[aLineNo - 1], aColNo, getTabWidth()); 265 mMessages.add( 266 new LocalizedMessage( 267 aLineNo, 268 col, 269 getMessageBundle(), 270 aKey, 271 aArgs, 272 getSeverityLevel(), 273 getId(), 274 this.getClass())); 275 } 276 } 277 | Popular Tags |