[Fb-contrib-commit] SF.net SVN: fb-contrib: [509] trunk/fb-contrib/etc
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-04-29 23:22:26
|
Revision: 509 Author: dbrosius Date: 2006-04-29 16:22:15 -0700 (Sat, 29 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=509&view=rev Log Message: ----------- new S508C bugpattern for setting explicit colors for controls Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml trunk/fb-contrib/samples/S508C_Sample.java 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-29 04:17:26 UTC (rev 508) +++ trunk/fb-contrib/etc/findbugs.xml 2006-04-29 23:22:15 UTC (rev 509) @@ -185,7 +185,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.Section508Compliance" speed="fast" - reports="S508C_NULL_LAYOUT,S508C_NO_SETLABELFOR,S508C_NO_SETSIZE,S508C_NON_ACCESSIBLE_JCOMPONENT" /> + reports="S508C_NULL_LAYOUT,S508C_NO_SETLABELFOR,S508C_NO_SETSIZE,S508C_NON_ACCESSIBLE_JCOMPONENT,S508C_SET_COMP_COLOR" /> <Detector class="com.mebigfatguy.fbcontrib.detect.UseEnumCollections" speed="fast" @@ -239,5 +239,6 @@ <BugPattern abbrev="S508C" type="S508C_NO_SETLABELFOR" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="S508C" type="S508C_NO_SETSIZE" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="S508C" type="S508C_NON_ACCESSIBLE_JCOMPONENT" category="CORRECTNESS" experimental="true"/> + <BugPattern abbrev="S508C" type="S508C_SET_COMP_COLOR" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="UEC" type="UEC_USE_ENUM_COLLECTIONS" category="PERFORMANCE" experimental="true" /> </FindbugsPlugin> \ No newline at end of file Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2006-04-29 04:17:26 UTC (rev 508) +++ trunk/fb-contrib/etc/messages.xml 2006-04-29 23:22:15 UTC (rev 509) @@ -1150,6 +1150,18 @@ </Details> </BugPattern> + <BugPattern type="S508C_SET_COMP_COLOR"> + <ShortDescription>Method explicitly sets the color of a Component</ShortDescription> + <LongDescription>Method {1} Method explicitly sets the color of a Component</LongDescription> + <Details> + <![CDATA[ + <p>This method sets a Components explicitly foreground or background color which may + cause difficulty with people with visions problems from using this application. + Colors should be allowed to be set from the operating system.</p> + ]]> + </Details> + </BugPattern> + <BugPattern type="UEC_USE_ENUM_COLLECTIONS"> <ShortDescription>Class uses an ordinary set or map with an enum class as the key</ShortDescription> <LongDescription>Class {0} uses an ordinary set or map with an enum class as the key</LongDescription> Modified: trunk/fb-contrib/samples/S508C_Sample.java =================================================================== --- trunk/fb-contrib/samples/S508C_Sample.java 2006-04-29 04:17:26 UTC (rev 508) +++ trunk/fb-contrib/samples/S508C_Sample.java 2006-04-29 23:22:15 UTC (rev 509) @@ -1,3 +1,4 @@ +import java.awt.Color; import java.awt.Container; import javax.swing.JComponent; @@ -15,6 +16,8 @@ cp.add(fLabel); JLabel lLabel = new JLabel("there"); + lLabel.setBackground(new Color(255, 0, 0)); + lLabel.setForeground(new Color(255, 255, 100)); cp.add(lLabel); cp.add(c); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2006-04-29 04:17:26 UTC (rev 508) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2006-04-29 23:22:15 UTC (rev 509) @@ -28,6 +28,7 @@ public class Section508Compliance extends BytecodeScanningDetector { private static JavaClass windowClass; + private static JavaClass componentClass; private static JavaClass jcomponentClass; private static JavaClass accessibleClass; static { @@ -37,6 +38,11 @@ windowClass = null; } try { + componentClass = Repository.lookupClass("javax/awt/Component"); + } catch (ClassNotFoundException cnfe) { + componentClass = null; + } + try { jcomponentClass = Repository.lookupClass("javax/swing/JComponent"); } catch (ClassNotFoundException cnfe) { jcomponentClass = null; @@ -191,6 +197,22 @@ .addSourceLine(this)); } } + } + + if ("setBackground".equals(methodName) + || "setForeground".equals(methodName)) { + int argCount = Type.getArgumentTypes(getSigConstantOperand()).length; + if (stack.getStackDepth() > argCount) { + OpcodeStack.Item item = stack.getStackItem(argCount); + JavaClass cls = item.getJavaClass(); + if (((jcomponentClass != null) && cls.instanceOf(jcomponentClass)) + || ((componentClass != null) && cls.instanceOf(componentClass))) { + bugReporter.reportBug(new BugInstance(this, "S508C_SET_COMP_COLOR", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } } } } catch (ClassNotFoundException cnfe) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |