01: /*
02: * Hammurapi
03: * Automated Java code review system.
04: * Copyright (C) 2004 Hammurapi Group
05: *
06: * This program is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU General Public License as published by
08: * the Free Software Foundation; either version 2 of the License, or
09: * (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: *
20: * URL: http://www.hammurapi.org
21: * e-Mail: support@hammurapi.biz
22: */
23: package org.hammurapi.inspectors;
24:
25: import org.hammurapi.InspectorBase;
26:
27: import com.pavelvlasov.config.ConfigurationException;
28: import com.pavelvlasov.config.Parameterizable;
29: import com.pavelvlasov.jsel.Interface;
30: import com.pavelvlasov.jsel.Modifiable;
31:
32: /**
33: * ER-115
34: * No need to provide (public, abstract, ) modifiers for interface methods
35: * @author Janos Czako
36: * @version $Revision: 1.3 $
37: */
38: public class InterfaceMethodModifiersRule extends InspectorBase
39: implements Parameterizable {
40:
41: /**
42: * Reviews the interface definition, if it has a declaration with
43: * not allowed modifier(s).
44: * The list of the allowed modifiers is configurable.
45: *
46: * @param element the interface declaration to be reviewed.
47: */
48: public void visit(Interface element) {
49: java.util.Iterator fields = element.getFields().iterator();
50:
51: while (fields.hasNext()) {
52: Modifiable item = (Modifiable) fields.next();
53:
54: if (!allowedModifiers.containsAll(item.getModifiers())) {
55: context.reportViolation(item);
56: }
57: }
58: }
59:
60: /**
61: * Stores the setting form the configuration for the not allowed
62: * modifiers for the operations of the interface definitions.
63: */
64: private java.util.Set allowedModifiers = new java.util.HashSet();
65:
66: /**
67: * Configures the rule. Reads in the values of the parameters operation-max-complexity and
68: * class-max-complexity.
69: *
70: * @param name the name of the parameter being loaded from Hammurapi configuration
71: * @param value the value of the parameter being loaded from Hammurapi configuration
72: * @exception ConfigurationException in case of a not supported parameter
73: */
74: public boolean setParameter(String name, Object parameter)
75: throws ConfigurationException {
76: if ("allowed-modifier".equals(name)) {
77: allowedModifiers.add(parameter.toString());
78: return true;
79: } else {
80: throw new ConfigurationException("Parameter '" + name
81: + "' is not supported");
82: }
83: }
84:
85: /**
86: * Gives back the preconfigured values.
87: */
88: public String getConfigInfo() {
89: StringBuffer ret = new StringBuffer(
90: "Allowed modifiers in the interface declarations:\n");
91: java.util.Iterator iter = allowedModifiers.iterator();
92: while (iter.hasNext()) {
93: ret.append("allowed-modifier: " + (String) iter.next()
94: + "\t");
95: }
96: ret.append("\n");
97: return ret.toString();
98: }
99: }
|