[Fb-contrib-commit] SF.net SVN: fb-contrib: [499] trunk/fb-contrib/etc
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-04-23 01:39:16
|
Revision: 499 Author: dbrosius Date: 2006-04-22 18:39:07 -0700 (Sat, 22 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=499&view=rev Log Message: ----------- more checks - far from complete 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-23 00:22:03 UTC (rev 498) +++ trunk/fb-contrib/etc/findbugs.xml 2006-04-23 01:39:07 UTC (rev 499) @@ -185,7 +185,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.Section508Compliance" speed="fast" - reports="S508C_NULL_LAYOUT" /> + reports="S508C_NULL_LAYOUT,S508C_NO_SETLABELFOR" /> <!-- BugPattern --> @@ -232,4 +232,5 @@ <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" /> + <BugPattern abbrev="S508C" type="S508C_NO_SETLABELFOR" 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 00:22:03 UTC (rev 498) +++ trunk/fb-contrib/etc/messages.xml 2006-04-23 01:39:07 UTC (rev 499) @@ -1105,6 +1105,18 @@ </Details> </BugPattern> + <BugPattern type="S508C_NO_SETLABELFOR"> + <ShortDescription>JLabel doesn't specify what it's labeling</ShortDescription> + <LongDescription>JLabel doesn't specify what it's labeling</LongDescription> + <Details> + <![CDATA[ + <p>This class uses JLabels that do not specify what fields are being labeled. + This hampers screen readers from given appropriate feed back to users. + </p> + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> Modified: trunk/fb-contrib/samples/S508C_Sample.java =================================================================== --- trunk/fb-contrib/samples/S508C_Sample.java 2006-04-23 00:22:03 UTC (rev 498) +++ trunk/fb-contrib/samples/S508C_Sample.java 2006-04-23 01:39:07 UTC (rev 499) @@ -1,11 +1,20 @@ import java.awt.Container; import javax.swing.JFrame; +import javax.swing.JLabel; public class S508C_Sample extends JFrame { + private JLabel fLabel = new JLabel("Hello"); + public S508C_Sample() { Container cp = getContentPane(); cp.setLayout(null); + + cp.add(fLabel); + JLabel lLabel = new JLabel("there"); + cp.add(lLabel); + + setSize(300, 200); } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2006-04-23 00:22:03 UTC (rev 498) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2006-04-23 01:39:07 UTC (rev 499) @@ -1,6 +1,8 @@ package com.mebigfatguy.fbcontrib.detect; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; import org.apache.bcel.classfile.Code; @@ -11,7 +13,9 @@ import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; +import edu.umd.cs.findbugs.FieldAnnotation; import edu.umd.cs.findbugs.OpcodeStack; +import edu.umd.cs.findbugs.SourceLineAnnotation; import edu.umd.cs.findbugs.ba.ClassContext; /** @@ -22,8 +26,8 @@ { private BugReporter bugReporter; private OpcodeStack stack; - private Set<String> fieldLabels; - private Set<Integer> localLabels; + private Set<FieldAnnotation> fieldLabels; + private Map<Integer, SourceLineAnnotation> localLabels; /** * constructs a S508C detector given the reporter to report bugs on @@ -33,14 +37,6 @@ 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 * @@ -50,9 +46,14 @@ public void visitClassContext(ClassContext classContext) { try { stack = new OpcodeStack(); - fieldLabels = new HashSet<String>(); - localLabels = new HashSet<Integer>(); + fieldLabels = new HashSet<FieldAnnotation>(); + localLabels = new HashMap<Integer, SourceLineAnnotation>(); super.visitClassContext(classContext); + for (FieldAnnotation fa : fieldLabels) { + bugReporter.reportBug(new BugInstance(this, "S508C_NO_SETLABELFOR", NORMAL_PRIORITY) + .addClass(this) + .addField(fa)); + } } finally { stack = null; fieldLabels = null; @@ -61,6 +62,20 @@ } /** + * looks for fields that are JLabels and stores them in a set + * + * @param obj the field object of the current field + */ + @Override + public void visitField(Field obj) { + String fieldSig = obj.getSignature(); + if ("Ljavax/swing/JLabel;".equals(fieldSig)) { + FieldAnnotation fa = FieldAnnotation.fromVisitedField(this); + fieldLabels.add(fa); + } + } + + /** * implements the visitor to reset the stack * * @param obj the context object for the currently visited code block @@ -70,6 +85,16 @@ stack.resetForMethodEntry(this); localLabels.clear(); super.visitCode(obj); + for (SourceLineAnnotation sla : localLabels.values()) { + BugInstance bug = new BugInstance(this, "S508C_NO_SETLABELFOR", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this); + + if (sla != null) + bug.addSourceLine(sla); + + bugReporter.reportBug(bug); + } } /** @@ -82,7 +107,13 @@ try { stack.mergeJumps(this); if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { - int reg = RegisterUtils.getAStoreReg(this, seen); + if (stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + if ("Ljavax/swing/JLabel;".equals(item.getSignature())) { + int reg = RegisterUtils.getAStoreReg(this, seen); + localLabels.put(new Integer(reg), SourceLineAnnotation.fromVisitedInstruction(this)); + } + } } else if (seen == INVOKEVIRTUAL) { String className = getClassConstantOperand(); String methodName = getNameConstantOperand(); @@ -98,6 +129,21 @@ .addSourceLine(this)); } } + } else if ("javax/swing/JLabel".equals(className)) { + if ("setLabelFor".equals(methodName)) { + if (stack.getStackDepth() > 1) { + OpcodeStack.Item item = stack.getStackItem(1); + FieldAnnotation fa = item.getField(); + if (fa != null) + fieldLabels.remove(fa.getFieldName()); + else { + int reg = item.getRegisterNumber(); + if (reg >= 0) { + localLabels.remove(new Integer(reg)); + } + } + } + } } } } finally { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |