[Fb-contrib-commit] SF.net SVN: fb-contrib: [500] trunk/fb-contrib/etc
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-04-23 02:00:40
|
Revision: 500 Author: dbrosius Date: 2006-04-22 19:00:31 -0700 (Sat, 22 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=500&view=rev Log Message: ----------- add setSize checks for Windows Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2006-04-23 01:39:07 UTC (rev 499) +++ trunk/fb-contrib/etc/findbugs.xml 2006-04-23 02:00:31 UTC (rev 500) @@ -185,7 +185,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.Section508Compliance" speed="fast" - reports="S508C_NULL_LAYOUT,S508C_NO_SETLABELFOR" /> + reports="S508C_NULL_LAYOUT,S508C_NO_SETLABELFOR,S508C_NO_SETSIZE" /> <!-- BugPattern --> @@ -233,4 +233,5 @@ <BugPattern abbrev="NRTL" type="NRTL_NON_RECYCLEABLE_TAG_LIB" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="S508C" type="S508C_NULL_LAYOUT" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="S508C" type="S508C_NO_SETLABELFOR" category="CORRECTNESS" experimental="true" /> + <BugPattern abbrev="S508C" type="S508C_NO_SETSIZE" category="CORRECTNESS" experimental="true" /> </FindbugsPlugin> \ No newline at end of file Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2006-04-23 01:39:07 UTC (rev 499) +++ trunk/fb-contrib/etc/messages.xml 2006-04-23 02:00:31 UTC (rev 500) @@ -1117,6 +1117,18 @@ </Details> </BugPattern> + <BugPattern type="S508C_NO_SETSIZE"> + <ShortDescription>Window sets size manually, and doesn't use pack</ShortDescription> + <LongDescription>Window sets size manually, and doesn't use pack</LongDescription> + <Details> + <![CDATA[ + <p>This class creates a window, and sizes the window using setSize. It is better + to handle font size changes to use the pack method. + </p> + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2006-04-23 01:39:07 UTC (rev 499) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2006-04-23 02:00:31 UTC (rev 500) @@ -5,8 +5,11 @@ import java.util.Map; import java.util.Set; +import org.apache.bcel.Repository; import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.Field; +import org.apache.bcel.classfile.JavaClass; +import org.apache.bcel.generic.Type; import com.mebigfatguy.fbcontrib.utils.RegisterUtils; @@ -24,6 +27,14 @@ */ public class Section508Compliance extends BytecodeScanningDetector { + private static JavaClass windowClass; + static { + try { + windowClass = Repository.lookupClass("java/awt/Window"); + } catch (ClassNotFoundException cnfe) { + windowClass = null; + } + } private BugReporter bugReporter; private OpcodeStack stack; private Set<FieldAnnotation> fieldLabels; @@ -144,8 +155,24 @@ } } } + } else if ("java/awt/Component".equals(className)) { + if ("setSize".equals(methodName)) { + int argCount = Type.getArgumentTypes(getSigConstantOperand()).length; + if ((windowClass != null) && (stack.getStackDepth() > argCount)) { + OpcodeStack.Item item = stack.getStackItem(argCount); + JavaClass cls = item.getJavaClass(); + if (cls.instanceOf(windowClass)) { + bugReporter.reportBug(new BugInstance(this, "S508C_NO_SETSIZE", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + } } } + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); } finally { stack.sawOpcode(this, seen); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |