1 package com.puppycrawl.tools.checkstyle.checks; 20 21 import java.util.Iterator ; 22 import java.util.List ; 23 import java.util.Map ; 24 25 import com.puppycrawl.tools.checkstyle.api.TextBlock; 26 import com.puppycrawl.tools.checkstyle.api.DetailAST; 27 import com.puppycrawl.tools.checkstyle.api.FileContents; 28 29 54 public class TodoCommentCheck 55 extends AbstractFormatCheck 56 { 57 60 public TodoCommentCheck() 61 { 62 super("TODO:"); } 64 65 66 public int[] getDefaultTokens() 67 { 68 return new int[0]; 69 } 70 71 72 public void beginTree(DetailAST aRootAST) 73 { 74 final FileContents contents = getFileContents(); 75 checkCppComments(contents); 76 checkBadComments(contents); 77 } 78 79 83 private void checkCppComments(FileContents aContents) 84 { 85 final Map comments = aContents.getCppComments(); 86 for (final Iterator it = comments.keySet().iterator(); it.hasNext();) { 87 final Integer key = (Integer ) it.next(); 88 final String cmt = ((TextBlock) comments.get(key)).getText()[0]; 89 if (getRegexp().matcher(cmt).find()) { 90 log(key.intValue(), "todo.match", getFormat()); 91 } 92 } 93 } 94 95 99 private void checkBadComments(FileContents aContents) 100 { 101 final Map allComments = aContents.getCComments(); 102 final Iterator allIter = allComments.keySet().iterator(); 103 while (allIter.hasNext()) { 104 final Integer key = (Integer ) allIter.next(); 105 final List lineComments = (List ) allComments.get(key); 106 final Iterator lineIter = lineComments.iterator(); 107 while (lineIter.hasNext()) { 108 final String [] cmt = ((TextBlock) lineIter.next()).getText(); 109 for (int i = 0; i < cmt.length; i++) { 110 if (getRegexp().matcher(cmt[i]).find()) { 111 log(key.intValue() + i, "todo.match", getFormat()); 112 } 113 } 114 } 115 } 116 } 117 } 118 | Popular Tags |