KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hammurapi > inspectors > InterfaceMethodModifiersRule


1 /*
2  * Hammurapi
3  * Automated Java code review system.
4  * Copyright (C) 2004 Hammurapi Group
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (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 /**
34  * ER-115
35  * No need to provide (public, abstract, ) modifiers for interface methods
36  * @author Janos Czako
37  * @version $Revision: 1.3 $
38  */

39 public class InterfaceMethodModifiersRule
40     extends InspectorBase implements Parameterizable {
41     
42     /**
43      * Reviews the interface definition, if it has a declaration with
44      * not allowed modifier(s).
45      * The list of the allowed modifiers is configurable.
46      *
47      * @param element the interface declaration to be reviewed.
48      */

49     public void visit(Interface element) {
50         java.util.Iterator JavaDoc fields = element.getFields().iterator();
51         
52         while (fields.hasNext()) {
53             Modifiable item = (Modifiable) fields.next();
54             
55             if (! allowedModifiers.containsAll(item.getModifiers())) {
56                 context.reportViolation(item);
57             }
58         }
59     }
60
61     /**
62      * Stores the setting form the configuration for the not allowed
63      * modifiers for the operations of the interface definitions.
64      */

65     private java.util.Set JavaDoc allowedModifiers = new java.util.HashSet JavaDoc();
66     
67     
68     /**
69      * Configures the rule. Reads in the values of the parameters operation-max-complexity and
70      * class-max-complexity.
71      *
72      * @param name the name of the parameter being loaded from Hammurapi configuration
73      * @param value the value of the parameter being loaded from Hammurapi configuration
74      * @exception ConfigurationException in case of a not supported parameter
75      */

76     public boolean setParameter(String JavaDoc name, Object JavaDoc parameter) throws ConfigurationException {
77         if ("allowed-modifier".equals(name)) {
78             allowedModifiers.add(parameter.toString());
79             return true;
80         } else {
81             throw new ConfigurationException("Parameter '"+name+"' is not supported");
82         }
83     }
84     
85     /**
86      * Gives back the preconfigured values.
87      */

88     public String JavaDoc getConfigInfo() {
89         StringBuffer JavaDoc ret=new StringBuffer JavaDoc("Allowed modifiers in the interface declarations:\n");
90         java.util.Iterator JavaDoc iter = allowedModifiers.iterator();
91         while (iter.hasNext()) {
92             ret.append("allowed-modifier: " + (String JavaDoc) iter.next() + "\t");
93         }
94         ret.append("\n");
95         return ret.toString();
96     }
97 }
98
Popular Tags