1 2 import java.util.ArrayList ; 3 import java.util.Collections ; 4 import java.util.Iterator ; 5 6 import com.puppycrawl.tools.checkstyle.api.Check; 7 import com.puppycrawl.tools.checkstyle.api.TokenTypes; 8 9 14 public class JavadocCheckDefault 15 { 16 17 private static void usage() 18 { 19 System.out.println("Usage: java JavadocCheckDefault check element"); 20 System.exit(0); 21 } 22 23 public static void main(String [] args) 24 { 25 if (args.length < 2) { 26 usage(); 27 } 28 final String header = 29 " * <p> By default the check will check the following " 30 + args[1] + ":\n"; 31 final String footer = ".\n * </p>\n"; 32 final String prefix = " * {@link TokenTypes#"; 33 34 try { 35 final Class clazz = Class.forName(args[0]); 36 final Check check = (Check) clazz.newInstance(); 37 final int[] defaultTokens = check.getDefaultTokens(); 38 if (defaultTokens.length > 0) { 39 final StringBuffer buf = new StringBuffer (); 40 buf.append(header); 41 final ArrayList tokenNames = new ArrayList (); 42 for (int i = 0; i < defaultTokens.length; i++) { 43 tokenNames.add(TokenTypes.getTokenName(defaultTokens[i])); 44 } 45 Collections.sort(tokenNames); 46 final Iterator it = tokenNames.iterator(); 47 String token = (String ) it.next(); 48 buf.append(prefix + token + " " + token + "}"); 49 while (it.hasNext()) { 50 token = (String ) it.next(); 51 buf.append(",\n" + prefix + token + " " + token + "}"); 52 } 53 buf.append(footer); 54 System.out.println(buf); 55 } 56 } 57 catch (Exception ex) { 58 ex.printStackTrace(); 59 System.exit(0); 60 } 61 } 62 } 63 | Popular Tags |