[Fb-contrib-commit] SF.net SVN: fb-contrib: [498] trunk/fb-contrib/etc
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-04-23 00:22:18
|
Revision: 498 Author: dbrosius Date: 2006-04-22 17:22:03 -0700 (Sat, 22 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=498&view=rev Log Message: ----------- Initial checkin - S508C detector - very premature Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml Added Paths: ----------- 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-22 19:20:11 UTC (rev 497) +++ trunk/fb-contrib/etc/findbugs.xml 2006-04-23 00:22:03 UTC (rev 498) @@ -183,6 +183,10 @@ speed="fast" reports="NRTL_NON_RECYCLEABLE_TAG_LIBS" /> + <Detector class="com.mebigfatguy.fbcontrib.detect.Section508Compliance" + speed="fast" + reports="S508C_NULL_LAYOUT" /> + <!-- BugPattern --> <BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" /> @@ -227,4 +231,5 @@ <BugPattern abbrev="FCBL" type="FCBL_FIELD_COULD_BE_LOCAL" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="NOS" type="NOS_NON_OWNED_SYNCHRONIZATION" category="STYLE" experimental="true" /> <BugPattern abbrev="NRTL" type="NRTL_NON_RECYCLEABLE_TAG_LIB" category="CORRECTNESS" experimental="true" /> + <BugPattern abbrev="S508C" type="S508C_NULL_LAYOUT" 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-22 19:20:11 UTC (rev 497) +++ trunk/fb-contrib/etc/messages.xml 2006-04-23 00:22:03 UTC (rev 498) @@ -527,6 +527,16 @@ ]]> </Details> </Detector> + + <Detector class="com.mebigfatguy.fbcontrib.detect.Section508Compliance"> + <Details> + <![CDATA[ + <p>looks for violation of Section 508, Accessibility for People with disabilities Act. + </p> + <p>It is a fast detector</p> + ]]> + </Details> + </Detector> <!-- BugPattern --> @@ -1082,6 +1092,19 @@ </Details> </BugPattern> + <BugPattern type="S508C_NULL_LAYOUT"> + <ShortDescription>Gui uses absolute layout</ShortDescription> + <LongDescription>Gui {0} uses absolute layout</LongDescription> + <Details> + <![CDATA[ + <p>This class passes null to setLayout, which specifies that components are + to be laid out using absolute coordinates. This makes making changes for + font sizes, etc, difficult as items will not reposition + </p> + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> @@ -1126,4 +1149,5 @@ <BugCode abbrev="FCBL">Field Could Be Local</BugCode> <BugCode abbrev="NOS">Non Owned Synchronization</BugCode> <BugCode abbrev="NRTL">Non Recycleable Taglib</BugCode> + <BugCode abbrev="S508C">Section 508 Compliance Violations</BugCode> </MessageCollection> \ No newline at end of file Added: trunk/fb-contrib/samples/S508C_Sample.java =================================================================== --- trunk/fb-contrib/samples/S508C_Sample.java (rev 0) +++ trunk/fb-contrib/samples/S508C_Sample.java 2006-04-23 00:22:03 UTC (rev 498) @@ -0,0 +1,11 @@ +import java.awt.Container; + +import javax.swing.JFrame; + +public class S508C_Sample extends JFrame +{ + public S508C_Sample() { + Container cp = getContentPane(); + cp.setLayout(null); + } +} Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2006-04-23 00:22:03 UTC (rev 498) @@ -0,0 +1,107 @@ +package com.mebigfatguy.fbcontrib.detect; + +import java.util.HashSet; +import java.util.Set; + +import org.apache.bcel.classfile.Code; +import org.apache.bcel.classfile.Field; + +import com.mebigfatguy.fbcontrib.utils.RegisterUtils; + +import edu.umd.cs.findbugs.BugInstance; +import edu.umd.cs.findbugs.BugReporter; +import edu.umd.cs.findbugs.BytecodeScanningDetector; +import edu.umd.cs.findbugs.OpcodeStack; +import edu.umd.cs.findbugs.ba.ClassContext; + +/** + * looks for interfaces that ignore 508 compliance, including not using JLabel.setLabelFor, + * Using null layouts, + */ +public class Section508Compliance extends BytecodeScanningDetector +{ + private BugReporter bugReporter; + private OpcodeStack stack; + private Set<String> fieldLabels; + private Set<Integer> localLabels; + + /** + * constructs a S508C detector given the reporter to report bugs on + * @param bugReporter the sync of bug reports + */ + public Section508Compliance(BugReporter bugReporter) { + this.bugReporter = bugReporter; + } + + @Override + public void visitField(Field obj) { + String fieldSig = obj.getSignature(); + if ("java/awt/Label".equals(fieldSig) || "javax/swing/JLabel".equals(fieldSig)) { + fieldLabels.add(obj.getName()); + } + } + + /** + * implements the visitor to create and clear the stack + * + * @param classContext the context object of the currently visited class + */ + @Override + public void visitClassContext(ClassContext classContext) { + try { + stack = new OpcodeStack(); + fieldLabels = new HashSet<String>(); + localLabels = new HashSet<Integer>(); + super.visitClassContext(classContext); + } finally { + stack = null; + fieldLabels = null; + localLabels = null; + } + } + + /** + * implements the visitor to reset the stack + * + * @param obj the context object for the currently visited code block + */ + @Override + public void visitCode(Code obj) { + stack.resetForMethodEntry(this); + localLabels.clear(); + super.visitCode(obj); + } + + /** + * implements the visitor to find 508 compliance concerns + * + * @param seen the opcode of the currently parsed instruction + */ + @Override + public void sawOpcode(int seen) { + try { + stack.mergeJumps(this); + if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { + int reg = RegisterUtils.getAStoreReg(this, seen); + } else if (seen == INVOKEVIRTUAL) { + String className = getClassConstantOperand(); + String methodName = getNameConstantOperand(); + + if ("java/awt/Container".equals(className)) { + if ("setLayout".equals(methodName)) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + if (item.isNull()) + bugReporter.reportBug(new BugInstance(this, "S508C_NULL_LAYOUT", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + } + } + } finally { + stack.sawOpcode(this, seen); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |