001: /*
002: * Hammurapi
003: * Automated Java code review system.
004: * Copyright (C) 2004 Hammurapi Group
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * URL: http://www.hammurapi.org
021: * e-Mail: support@hammurapi.biz
022: */
023: package org.hammurapi.inspectors;
024:
025: import org.hammurapi.InspectorBase;
026:
027: import com.pavelvlasov.jsel.Method;
028: import com.pavelvlasov.jsel.Parameter;
029: import com.pavelvlasov.jsel.TypeDefinition;
030: import com.pavelvlasov.jsel.VariableDefinition;
031:
032: /**
033: * Classes, methods and variables should be named according to Sun's naming convention.
034: *
035: * @author Pavel Vlasov
036: * @version $Revision: 1.4 $
037: */
038: public class NamingStandardRule extends InspectorBase {
039:
040: /**
041: * Reviews the name of the classes.
042: *
043: * @param typeDefinition the typedefinition to be reviewed.
044: */
045: public void visit(TypeDefinition typeDefinition) {
046: if (typeDefinition.getName().indexOf('_') != -1
047: || !Character.isUpperCase(typeDefinition.getName()
048: .charAt(0))) {
049: context.reportViolation(typeDefinition);
050: }
051: }
052:
053: /**
054: * Reviews the name of the methods.
055: *
056: * @param method the method to be reviewed
057: */
058: public void visit(Method method) {
059: if (method.getName().indexOf('_') != -1
060: || !Character.isLowerCase(method.getName().charAt(0))) {
061: context.reportViolation(method);
062: }
063: }
064:
065: /**
066: * Reviews the name of the attributes.
067: *
068: * @param variableDefinition the variable definition to be reviewed.
069: */
070: public void visit(VariableDefinition variableDefinition) {
071: if (variableDefinition.getModifiers().contains("static")
072: && variableDefinition.getModifiers().contains("final")) {
073: if (!"serialVersionUID"
074: .equals(variableDefinition.getName())
075: && !variableDefinition.getName().toUpperCase()
076: .equals(variableDefinition.getName())) {
077: context.reportViolation(variableDefinition);
078: }
079: } else if (variableDefinition.getName().indexOf('_') != -1
080: || !Character.isLowerCase(variableDefinition.getName()
081: .charAt(0))) {
082: context.reportViolation(variableDefinition);
083: } else if ("enum".equals(variableDefinition.getName())) {
084: context.reportViolation(variableDefinition);
085: }
086: }
087:
088: /**
089: * Reviews the name of the parameters.
090: *
091: * @param parameter the parameter declaration to be reviewed.
092: */
093: public void visit(Parameter parameter) {
094: if (parameter.getName().indexOf('_') != -1
095: || !Character
096: .isLowerCase(parameter.getName().charAt(0))) {
097: context.reportViolation(parameter);
098: } else if ("enum".equals(parameter.getName())) {
099: context.reportViolation(parameter);
100: }
101: }
102:
103: public void visit(com.pavelvlasov.jsel.Package pkg) {
104: if (pkg.getName().toLowerCase() != pkg.getName()) {
105: context.reportViolation(null,
106: "Package name shall be in lower case: "
107: + pkg.getName());
108: }
109:
110: if (pkg.getName().indexOf('_') != -1) {
111: context.reportViolation(null,
112: "Packages name shall not contain underscore character: "
113: + pkg.getName());
114: }
115: }
116: }
|