GitHub PullRequestReviewCommentEvent at 2014-04-18 12:05:01
Repository: sevntu.checkstyle
Actor: isopov
Payload: {"comment":{"url":"https://api.github.com/repos/sevntu-checkstyle/sevntu.checkstyle/pulls/comments/11770042","id":11770042,"diff_hunk":"@@ -0,0 +1,264 @@\n+////////////////////////////////////////////////////////////////////////////////\n+// checkstyle: Checks Java source code for adherence to a set of rules.\n+// Copyright (C) 2001-2013  Oliver Burn\n+//\n+// This library is free software; you can redistribute it and/or\n+// modify it under the terms of the GNU Lesser General Public\n+// License as published by the Free Software Foundation; either\n+// version 2.1 of the License, or (at your option) any later version.\n+//\n+// This library is distributed in the hope that it will be useful,\n+// but WITHOUT ANY WARRANTY; without even the implied warranty of\n+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+// Lesser General Public License for more details.\n+//\n+// You should have received a copy of the GNU Lesser General Public\n+// License along with this library; if not, write to the Free Software\n+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n+////////////////////////////////////////////////////////////////////////////////\n+package com.github.sevntu.checkstyle.checks.naming;\n+\n+import java.util.Collection;\n+import java.util.List;\n+import java.util.regex.Pattern;\n+\n+import com.google.common.collect.Lists;\n+import com.puppycrawl.tools.checkstyle.api.Check;\n+import com.puppycrawl.tools.checkstyle.api.DetailAST;\n+import com.puppycrawl.tools.checkstyle.api.TokenTypes;\n+import com.puppycrawl.tools.checkstyle.api.Utils;\n+\n+/**\n+ * Check forces enum values to match the specific pattern. According to\n+ * \"Java Coding Style\" by Achut Reddy p 3.3 constants include\n+ * \"all static final object reference types that are never followed by \"\n+ * .\" (dot).\", i.e. enums, which are followed by dot while used in the code are\n+ * to be treated as static object references, while enums, that are not used\n+ * with following dot, should be treated as constants.\n+ * <p>\n+ * Enums are defined to be used as class have some own methods. This condition\n+ * is used to distinguish between Values Enumeration and Class Enumeration.\n+ * Values Enumeration looks like the following: <code>\n+ * enum SimpleErrorEnum\n+ *   {\n+ *       FIRST_SIMPLE, SECOND_SIMPLE, THIRD_SIMPLE;\n+ *   }\n+ * </code>\n+ * <p>\n+ * While Class Enumeration has some methods, for example: <code>\n+ * enum SimpleErrorEnum\n+ *   {\n+ *       FIRST_SIMPLE, SECOND_SIMPLE, THIRD_SIMPLE;\n+ * \n+ *       public String toString() {\n+ *           return Integer.toString(ordinal() + 10);\n+ *       }\n+ *   }\n+ * </code>\n+ * <p>\n+ * Name format for Class Enumeration values is specified with\n+ * {@link #setObjFormat(String)} , while format for enum constants - with\n+ * {@link #setConstFormat(String)}\n+ * <p>\n+ * To avoid assuming enum as static object reference, while using some specific\n+ * methods, {@link #setExcludes(List)} can be used. For example to make enum in\n+ * the previous example a constant set Excludes property to a value\n+ * <code>toString</code>\n+ * <p>\n+ * By default <code>toString</code> is used as an exclusion.\n+ *\n+ * @see <a\n+ *      href=\" http://www.scribd.com/doc/15884743/Java-Coding-Style-by-Achut-Reddy\">\"Java Coding Style\"\n+ *      by Achut Reddy</a>\n+ *\n+ * @author Pavel Baranchikov\n+ */\n+public class EnumValueNameCheck extends Check\n+{\n+    public static final String MSG_CONST = \"enum.name.const.invalidPattern\";\n+    public static final String MSG_OBJ = \"enum.name.obj.invalidPattern\";\n+\n+    /**\n+     * Default pattern for Values Enumeration names.\n+     */\n+    public static final String DEFAULT_CONST_PATTERN =\n+            \"^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$\";\n+\n+    /**\n+     * Default pattern for Class Enumeration names.\n+     */\n+    public static final String DEFAULT_OBJ_PATTERN = \"^[A-Z][a-zA-Z0-9]*$\";\n+\n+    /**\n+     * Default exclusions value.\n+     */\n+    public static final String[] DEFAULT_EXCLUSION = { \"toString\" };\n+\n+    /**\n+     * Regular expression to test Class Enumeration names against.\n+     */\n+    private Pattern mObjRegexp;\n+\n+    /**\n+     * Format for Class Enumeration names to check for. Compiled to\n+     * {@link #mObjRegexp}\n+     */\n+    private String mObjFormat;\n+\n+    /**\n+     * Regular expression to test Values Enumeration names against.\n+     */\n+    private Pattern mConstRegexp;\n+\n+    /**\n+     * Format for Values Enumeration names to check for. Compiled to\n+     * {@link #mConstRegexp}\n+     */\n+    private String mConstFormat;\n+\n+    /**\n+     * Method and field names to exclude from check.\n+     */\n+    private final List<Pattern> mExcludes;\n+\n+    /**\n+     * Constructs check with the default pattern.\n+     */\n+    public EnumValueNameCheck()\n+    {\n+        setConstFormat(DEFAULT_CONST_PATTERN);\n+        setObjFormat(DEFAULT_OBJ_PATTERN);\n+        mExcludes = Lists.newArrayList();\n+        setExcludes(DEFAULT_EXCLUSION);\n+    }\n+\n+    /**\n+     * Method sets format to match Class Enumeration names.\n+     * @param aObjectRegexp format to check against","path":"sevntu-checks/src/main/java/com/github/sevntu/checkstyle/checks/naming/EnumValueNameCheck.java","position":137,"original_position":137,"commit_id":"3fe1bcb19374b08228f9afb704847f186d5085e3","original_commit_id":"3fe1bcb19374b08228f9afb704847f186d5085e3","user":{"login":"isopov","id":462800,"avatar_url":"https://avatars.githubusercontent.com/u/462800?","gravatar_id":"f3ae04bec62bd04a3e35d3b9b74f9668","url":"https://api.github.com/users/isopov","html_url":"https://github.com/isopov","followers_url":"https://api.github.com/users/isopov/followers","following_url":"https://api.github.com/users/isopov/following{/other_user}","gists_url":"https://api.github.com/users/isopov/gists{/gist_id}","starred_url":"https://api.github.com/users/isopov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/isopov/subscriptions","organizations_url":"https://api.github.com/users/isopov/orgs","repos_url":"https://api.github.com/users/isopov/repos","events_url":"https://api.github.com/users/isopov/events{/privacy}","received_events_url":"https://api.github.com/users/isopov/received_events","type":"User","site_admin":false},"body":"In method argument is called \"aConstRegexp\" but in javadoc - \"aObjectRegexp\" - please use the same value. (I hate such javadocs and prefer deleting them all together, but ...)","created_at":"2014-04-18T12:05:01Z","updated_at":"2014-04-18T12:05:01Z","html_url":"https://github.com/sevntu-checkstyle/sevntu.checkstyle/pull/185#discussion_r11770042","pull_request_url":"https://api.github.com/repos/sevntu-checkstyle/sevntu.checkstyle/pulls/185","_links":{"self":{"href":"https://api.github.com/repos/sevntu-checkstyle/sevntu.checkstyle/pulls/comments/11770042"},"html":{"href":"https://github.com/sevntu-checkstyle/sevntu.checkstyle/pull/185#discussion_r11770042"},"pull_request":{"href":"https://api.github.com/repos/sevntu-checkstyle/sevntu.checkstyle/pulls/185"}}}}