[Fb-contrib-commit] SF.net SVN: fb-contrib: [922] trunk/fb-contrib
Brought to you by:
dbrosius
From: <dbr...@us...> - 2007-10-01 03:27:44
|
Revision: 922 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=922&view=rev Author: dbrosius Date: 2007-09-30 20:27:47 -0700 (Sun, 30 Sep 2007) Log Message: ----------- initial checkin, new MOM detector Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml Added Paths: ----------- trunk/fb-contrib/samples/MOM_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MisleadingOverloadModel.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2007-09-30 03:06:51 UTC (rev 921) +++ trunk/fb-contrib/etc/findbugs.xml 2007-10-01 03:27:47 UTC (rev 922) @@ -291,6 +291,10 @@ speed="fast" reports="NCS_NEEDLESS_CUSTOM_SERIALIZATION" /> + <Detector class="com.mebigfatguy.fbcontrib.detect.MisleadingOverloadModel" + speed="fast" + reports="MOM_MISLEADING_OVERLOAD_MODEL" /> + <!-- BugPattern --> <BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" /> @@ -382,4 +386,5 @@ <BugPattern abbrev="UAA" type="UAA_USE_ADD_ALL" category="STYLE" experimental="true" /> <BugPattern abbrev="MRC" type="MRC_METHOD_RETURNS_CONSTANT" category="STYLE" experimental="true" /> <BugPattern abbrev="NCS" type="NCS_NEEDLESS_CUSTOM_SERIALIZATION" category="CORRECTNESS" experimental="true" /> + <BugPattern abbrev="MOM" type="MOM_MISLEADING_OVERLOAD_MODEL" category="STYLE" experimental="true" /> </FindbugsPlugin> \ No newline at end of file Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2007-09-30 03:06:51 UTC (rev 921) +++ trunk/fb-contrib/etc/messages.xml 2007-10-01 03:27:47 UTC (rev 922) @@ -790,6 +790,17 @@ </Details> </Detector> + <Detector class="com.mebigfatguy.fbcontrib.detect.MisleadingOverloadModel"> + <Details> + <![CDATA[ + <p>looks for classes that define both static and instance methods with the same name. + As each type represents a different use model, it doesn't make sense that this name + would be overloaded, and will confuse users of the class.</p> + <p>It is a fast detector</p> + ]]> + </Details> + </Detector> + <!-- BugPattern --> <BugPattern type="ISB_INEFFICIENT_STRING_BUFFERING"> @@ -1969,6 +1980,17 @@ </Details> </BugPattern> + <BugPattern type="MOM_MISLEADING_OVERLOAD_MODEL"> + <ShortDescription>class 'overloads' a method with both instance and static versions</ShortDescription> + <LongDescription>class {0} 'overloads' a method with both instance and static versions</LongDescription> + <Details> + <![CDATA[ + <p>This class 'overloads' the same method with both an instance and static version. As the use + of these two models is different, it will be confusing to the users of these methods.</p> + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> @@ -2036,4 +2058,5 @@ <BugCode abbrev="UAA">Use Add All</BugCode> <BugCode abbrev="MRC">Method Returns Constant</BugCode> <BugCode abbrev="NCS">Needless Custom Serialization</BugCode> + <BugCode abbrev="MOM">Misleading Overload Model</BugCode> </MessageCollection> \ No newline at end of file Added: trunk/fb-contrib/samples/MOM_Sample.java =================================================================== --- trunk/fb-contrib/samples/MOM_Sample.java (rev 0) +++ trunk/fb-contrib/samples/MOM_Sample.java 2007-10-01 03:27:47 UTC (rev 922) @@ -0,0 +1,11 @@ + +public class MOM_Sample +{ + public void test(int i) + { + } + + public static void test(int i, int j) + { + } +} Property changes on: trunk/fb-contrib/samples/MOM_Sample.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MisleadingOverloadModel.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MisleadingOverloadModel.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MisleadingOverloadModel.java 2007-10-01 03:27:47 UTC (rev 922) @@ -0,0 +1,69 @@ +package com.mebigfatguy.fbcontrib.detect; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.bcel.classfile.JavaClass; +import org.apache.bcel.classfile.Method; + +import edu.umd.cs.findbugs.BugInstance; +import edu.umd.cs.findbugs.BugReporter; +import edu.umd.cs.findbugs.Detector; +import edu.umd.cs.findbugs.ba.ClassContext; +import edu.umd.cs.findbugs.ba.XFactory; +import edu.umd.cs.findbugs.visitclass.PreorderVisitor; + +/** looks for classes that define both static and instance methods with the same name. + * This 'overloading' is confusing as one method is instance based the other class based, + * and points to a confusion in implementation. + */ +public class MisleadingOverloadModel extends PreorderVisitor implements Detector +{ + private static enum MethodType { INSTANCE, STATIC, BOTH }; + private BugReporter bugReporter; + + /** + * constructs a MOM detector given the reporter to report bugs on + * @param bugReporter the sync of bug reports + */ + public MisleadingOverloadModel(BugReporter bugReporter) { + this.bugReporter = bugReporter; + } + + public void visitClassContext(ClassContext classContext) { + Map<String, MethodType> declMethods = new HashMap<String, MethodType>(); + JavaClass cls = classContext.getJavaClass(); + String clsName = cls.getClassName(); + Method[] methods = cls.getMethods(); + for (Method m : methods) { + String methodName = m.getName(); + boolean report = false; + MethodType newType; + if (m.isStatic()) { + report = declMethods.get(methodName) == MethodType.INSTANCE; + if (report) + newType = MethodType.BOTH; + else + newType = MethodType.STATIC; + } else { + report = declMethods.get(m.getName()) == MethodType.STATIC; + if (report) + newType = MethodType.BOTH; + else + newType = MethodType.INSTANCE; + } + + declMethods.put(methodName, newType); + if (report) { + bugReporter.reportBug(new BugInstance(this, "MOM_MISLEADING_OVERLOAD_MODEL", NORMAL_PRIORITY) + .addClass(cls) + .addMethod(XFactory.createXMethod(clsName, m)) + .addString(methodName)); + } + } + } + + /** implements the visitor to do nothing */ + public void report() { + } +} Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MisleadingOverloadModel.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |