From 3bd25d71c993420cfeb4782530882d1cdb620fca Mon Sep 17 00:00:00 2001
From: Baratali Izmailov
- * A check for TODO comments.
- * Actually it is a generic {@link java.util.regex.Pattern regular expression}
- * matcher on Java comments.
- * To check for other patterns in Java comments, set property format.
+ * A check for TODO comments. To check for other patterns in Java comments, set
+ * property format.
*
* An example of how to configure the check is:
*
* <module name="TodoComment"/>
*
@@ -41,72 +40,59 @@ import java.util.Map;
* An example of how to configure the check for comments that contain
* WARNING is:
*
* <module name="TodoComment"> * <property name="format" value="WARNING"/> * </module> ** @author Oliver Burn + * @author Baratali Izmailov * @version 1.0 */ public class TodoCommentCheck - extends AbstractFormatCheck + extends Check { /** - * Creates a new
TodoCommentCheck instance.
+ * Format of todo comment.
*/
- public TodoCommentCheck()
+ private String mFormat = "TODO:";
+
+ /**
+ * Regular expression pattern compiled from mFormat.
+ */
+ private Pattern mRegexp = Pattern.compile(mFormat);
+
+ @Override
+ public boolean isCommentNodesRequired()
{
- super("TODO:"); // the empty language
+ return true;
+ }
+
+ /**
+ * Setter for todo comment format.
+ * @param aFormat format of todo comment.
+ */
+ public void setFormat(String aFormat)
+ {
+ mFormat = aFormat;
+ mRegexp = Pattern.compile(aFormat);
}
@Override
public int[] getDefaultTokens()
{
- return new int[0];
+ return new int[] {TokenTypes.COMMENT_CONTENT };
}
@Override
- public void beginTree(DetailAST aRootAST)
+ public void visitToken(DetailAST aAST)
{
- final FileContents contents = getFileContents();
- checkCppComments(contents);
- checkBadComments(contents);
- }
+ final String[] lines = aAST.getText().split("\n");
- /**
- * Checks the C++ comments for todo expressions.
- * @param aContents the FileContents
- */
- private void checkCppComments(FileContents aContents)
- {
- final MapFileContents
- */
- private void checkBadComments(FileContents aContents)
- {
- final Map