Thread: [Fb-contrib-commit] SF.net SVN: fb-contrib:[1167] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2009-04-17 08:49:45
|
Revision: 1167
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1167&view=rev
Author: dbrosius
Date: 2009-04-17 08:49:44 +0000 (Fri, 17 Apr 2009)
Log Message:
-----------
UNNC
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2009-04-17 08:45:31 UTC (rev 1166)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2009-04-17 08:49:44 UTC (rev 1167)
@@ -74,7 +74,7 @@
accessibleClass = null;
}
}
- private BugReporter bugReporter;
+ private final BugReporter bugReporter;
private OpcodeStack stack;
private Set<XField> fieldLabels;
private Map<Integer, SourceLineAnnotation> localLabels;
@@ -184,8 +184,7 @@
OpcodeStack.Item item = stack.getStackItem(0);
if (item.getUserValue() == null) {
FieldAnnotation fa = new FieldAnnotation(getClassName(), getNameConstantOperand(), getSigConstantOperand(), false);
- if (fa != null)
- fieldLabels.remove(XFactory.createXField(fa));
+ fieldLabels.remove(XFactory.createXField(fa));
}
}
} else if (seen == INVOKESPECIAL) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2009-07-30 04:32:21
|
Revision: 1237
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1237&view=rev
Author: dbrosius
Date: 2009-07-30 04:32:09 +0000 (Thu, 30 Jul 2009)
Log Message:
-----------
FieldAnnotation constructor needs dotted classname
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2009-07-30 04:23:23 UTC (rev 1236)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2009-07-30 04:32:09 UTC (rev 1237)
@@ -44,9 +44,9 @@
/**
* looks for interfaces that ignore 508 compliance, including not using JLabel.setLabelFor,
- * Using null layouts,
+ * Using null layouts,
*/
-public class Section508Compliance extends BytecodeScanningDetector
+public class Section508Compliance extends BytecodeScanningDetector
{
private static JavaClass windowClass;
private static JavaClass componentClass;
@@ -78,15 +78,15 @@
private OpcodeStack stack;
private Set<XField> fieldLabels;
private Map<Integer, SourceLineAnnotation> localLabels;
-
+
/**
- * constructs a S508C detector given the reporter to report bugs on
- * @param bugReporter the sync of bug reports
+ * 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;
}
-
+
/**
* implements the visitor to create and clear the stack
*
@@ -100,19 +100,19 @@
if (cls.instanceOf(jcomponentClass)) {
if (!cls.implementationOf(accessibleClass)) {
bugReporter.reportBug(new BugInstance(this, "S508C_NON_ACCESSIBLE_JCOMPONENT", NORMAL_PRIORITY)
- .addClass(cls));
+ .addClass(cls));
}
}
}
-
+
stack = new OpcodeStack();
fieldLabels = new HashSet<XField>();
localLabels = new HashMap<Integer, SourceLineAnnotation>();
super.visitClassContext(classContext);
for (XField fa : fieldLabels) {
bugReporter.reportBug(new BugInstance(this, "S508C_NO_SETLABELFOR", NORMAL_PRIORITY)
- .addClass(this)
- .addField(fa));
+ .addClass(this)
+ .addField(fa));
}
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
@@ -122,7 +122,7 @@
localLabels = null;
}
}
-
+
/**
* looks for fields that are JLabels and stores them in a set
*
@@ -137,7 +137,7 @@
fieldLabels.add(XFactory.createXField(fa));
}
}
-
+
/**
* implements the visitor to reset the stack
*
@@ -150,16 +150,17 @@
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)
+ .addClass(this)
+ .addMethod(this);
+
+ if (sla != null) {
bug.addSourceLine(sla);
-
+ }
+
bugReporter.reportBug(bug);
}
}
-
+
/**
* implements the visitor to find 508 compliance concerns
*
@@ -167,49 +168,50 @@
*/
@Override
public void sawOpcode(int seen) {
- boolean sawTextLabel = false;
+ boolean sawTextLabel = false;
try {
stack.mergeJumps(this);
if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) {
if (stack.getStackDepth() > 0) {
OpcodeStack.Item item = stack.getStackItem(0);
if ("Ljavax/swing/JLabel;".equals(item.getSignature())
- && (item.getUserValue() != null)) {
+ && (item.getUserValue() != null)) {
int reg = RegisterUtils.getAStoreReg(this, seen);
localLabels.put(Integer14.valueOf(reg), SourceLineAnnotation.fromVisitedInstruction(this));
}
}
- } else if (seen == PUTFIELD) {
- if (stack.getStackDepth() > 0) {
- OpcodeStack.Item item = stack.getStackItem(0);
- if (item.getUserValue() == null) {
- FieldAnnotation fa = new FieldAnnotation(getClassName(), getNameConstantOperand(), getSigConstantOperand(), false);
- fieldLabels.remove(XFactory.createXField(fa));
- }
- }
- } else if (seen == INVOKESPECIAL) {
- String className = getClassConstantOperand();
- String methodName = getNameConstantOperand();
- if ("javax/swing/JLabel".equals(className)
- && "<init>".equals(methodName)) {
- String signature = getSigConstantOperand();
- if (signature.indexOf("Ljava/lang/String;") >= 0) {
- sawTextLabel = true;
- }
- }
+ } else if (seen == PUTFIELD) {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ if (item.getUserValue() == null) {
+ FieldAnnotation fa = new FieldAnnotation(getDottedClassName(), getNameConstantOperand(), getSigConstantOperand(), false);
+ fieldLabels.remove(XFactory.createXField(fa));
+ }
+ }
+ } else if (seen == INVOKESPECIAL) {
+ String className = getClassConstantOperand();
+ String methodName = getNameConstantOperand();
+ if ("javax/swing/JLabel".equals(className)
+ && "<init>".equals(methodName)) {
+ String signature = getSigConstantOperand();
+ if (signature.indexOf("Ljava/lang/String;") >= 0) {
+ sawTextLabel = true;
+ }
+ }
} 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())
+ if (item.isNull()) {
bugReporter.reportBug(new BugInstance(this, "S508C_NULL_LAYOUT", NORMAL_PRIORITY)
- .addClass(this)
- .addMethod(this)
- .addSourceLine(this));
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
}
}
} else if ("javax/swing/JLabel".equals(className)) {
@@ -217,9 +219,9 @@
if (stack.getStackDepth() > 1) {
OpcodeStack.Item item = stack.getStackItem(1);
XField field = item.getXField();
- if (field != null)
+ if (field != null) {
fieldLabels.remove(field);
- else {
+ } else {
int reg = item.getRegisterNumber();
if (reg >= 0) {
localLabels.remove(Integer14.valueOf(reg));
@@ -234,39 +236,39 @@
JavaClass cls = item.getJavaClass();
if (cls.instanceOf(windowClass)) {
bugReporter.reportBug(new BugInstance(this, "S508C_NO_SETSIZE", NORMAL_PRIORITY)
- .addClass(this)
- .addMethod(this)
- .addSourceLine(this));
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
}
}
- }
-
+ }
+
if ("setBackground".equals(methodName)
- || "setForeground".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))) {
+ 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));
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
}
- }
+ }
}
}
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
} finally {
stack.sawOpcode(this, seen);
- if (sawTextLabel) {
- if (stack.getStackDepth() > 0) {
- OpcodeStack.Item item = stack.getStackItem(0);
- item.setUserValue(Boolean.TRUE);
- }
- }
+ if (sawTextLabel) {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ item.setUserValue(Boolean.TRUE);
+ }
+ }
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-01-24 16:49:05
|
Revision: 1509
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1509&view=rev
Author: dbrosius
Date: 2010-01-24 16:48:56 +0000 (Sun, 24 Jan 2010)
Log Message:
-----------
report cnfe's
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2010-01-24 00:34:52 UTC (rev 1508)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2010-01-24 16:48:56 UTC (rev 1509)
@@ -51,26 +51,31 @@
private static JavaClass componentClass;
private static JavaClass jcomponentClass;
private static JavaClass accessibleClass;
+ private static ClassNotFoundException clsNFException;
static {
try {
windowClass = Repository.lookupClass("java/awt/Window");
} catch (ClassNotFoundException cnfe) {
windowClass = null;
+ clsNFException = cnfe;
}
try {
componentClass = Repository.lookupClass("javax/awt/Component");
} catch (ClassNotFoundException cnfe) {
componentClass = null;
+ clsNFException = cnfe;
}
try {
jcomponentClass = Repository.lookupClass("javax/swing/JComponent");
} catch (ClassNotFoundException cnfe) {
jcomponentClass = null;
+ clsNFException = cnfe;
}
try {
accessibleClass = Repository.lookupClass("javax.accessibility.Accessible");
} catch (ClassNotFoundException cnfe) {
accessibleClass = null;
+ clsNFException = cnfe;
}
}
private final BugReporter bugReporter;
@@ -84,6 +89,8 @@
*/
public Section508Compliance(BugReporter bugReporter) {
this.bugReporter = bugReporter;
+ if (clsNFException != null)
+ bugReporter.reportMissingClass(clsNFException);
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-01-25 02:09:04
|
Revision: 1511
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1511&view=rev
Author: dbrosius
Date: 2010-01-25 02:08:58 +0000 (Mon, 25 Jan 2010)
Log Message:
-----------
add more translation patterns
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2010-01-25 02:01:27 UTC (rev 1510)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2010-01-25 02:08:58 UTC (rev 1511)
@@ -88,6 +88,14 @@
displayTextMethods.put("javax/swing/JButton#<init>(Ljava/lang/String;Ljavax/swing/Icon;)", Integer.valueOf(1));
displayTextMethods.put("javax/swing/JFrame#<init>(Ljava/lang/String;)", Integer.valueOf(0));
displayTextMethods.put("javax/swing/JFrame#<init>(Ljava/lang/String;Ljava/awt/GraphicsConfiguration;)", Integer.valueOf(1));
+ displayTextMethods.put("javax/swing/JDialog#<init>(Ljava/awt/Dialog;Ljava/lang/String;)", Integer.valueOf(0));
+ displayTextMethods.put("javax/swing/JDialog#<init>(Ljava/awt/Dialog;Ljava/lang/String;Z)", Integer.valueOf(1));
+ displayTextMethods.put("javax/swing/JDialog#<init>(Ljava/awt/Dialog;Ljava/lang/String;ZLjava/awt/GraphicsConfiguration;)", Integer.valueOf(2));
+ displayTextMethods.put("javax/swing/JDialog#<init>(Ljava/awt/Frame;Ljava/lang/String;)", Integer.valueOf(0));
+ displayTextMethods.put("javax/swing/JDialog#<init>(Ljava/awt/Frame;Ljava/lang/String;Z)", Integer.valueOf(1));
+ displayTextMethods.put("javax/swing/JDialog#<init>(Ljava/awt/Frame;Ljava/lang/String;ZLjava/awt/GraphicsConfiguration;)", Integer.valueOf(2));
+ displayTextMethods.put("java/awt/Dialog#setTitle(Ljava/lang/String;)", Integer.valueOf(0));
+ displayTextMethods.put("java/awt/Frame#setTitle(Ljava/lang/String;)", Integer.valueOf(0));
}
private final BugReporter bugReporter;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-01-25 02:13:14
|
Revision: 1512
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1512&view=rev
Author: dbrosius
Date: 2010-01-25 02:13:06 +0000 (Mon, 25 Jan 2010)
Log Message:
-----------
more translation patterns
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2010-01-25 02:08:58 UTC (rev 1511)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2010-01-25 02:13:06 UTC (rev 1512)
@@ -96,6 +96,11 @@
displayTextMethods.put("javax/swing/JDialog#<init>(Ljava/awt/Frame;Ljava/lang/String;ZLjava/awt/GraphicsConfiguration;)", Integer.valueOf(2));
displayTextMethods.put("java/awt/Dialog#setTitle(Ljava/lang/String;)", Integer.valueOf(0));
displayTextMethods.put("java/awt/Frame#setTitle(Ljava/lang/String;)", Integer.valueOf(0));
+ displayTextMethods.put("javax/swing/JMenu#<init>(Ljava/lang/String;)", Integer.valueOf(0));
+ displayTextMethods.put("javax/swing/JMenu#<init>(Ljava/lang/String;Z)", Integer.valueOf(1));
+ displayTextMethods.put("javax/swing/JMenuItem#<init>(Ljava/lang/String;)", Integer.valueOf(0));
+ displayTextMethods.put("javax/swing/JMenuItem#<init>(Ljava/lang/String;Ljavax/swing/Icon;)", Integer.valueOf(1));
+ displayTextMethods.put("javax/swing/JMenuItem#<init>(Ljava/lang/String;I)", Integer.valueOf(1));
}
private final BugReporter bugReporter;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-04-24 01:53:17
|
Revision: 1544
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1544&view=rev
Author: dbrosius
Date: 2010-04-24 01:53:11 +0000 (Sat, 24 Apr 2010)
Log Message:
-----------
typo s/b java/awt/Component
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2010-04-04 16:34:42 UTC (rev 1543)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2010-04-24 01:53:11 UTC (rev 1544)
@@ -60,7 +60,7 @@
clsNFException = cnfe;
}
try {
- componentClass = Repository.lookupClass("javax/awt/Component");
+ componentClass = Repository.lookupClass("java/awt/Component");
} catch (ClassNotFoundException cnfe) {
componentClass = null;
clsNFException = cnfe;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2011-07-03 05:37:57
|
Revision: 1696
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1696&view=rev
Author: dbrosius
Date: 2011-07-03 05:37:51 +0000 (Sun, 03 Jul 2011)
Log Message:
-----------
don't report S508C for colors that come from UIManager
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2011-07-02 03:48:25 UTC (rev 1695)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2011-07-03 05:37:51 UTC (rev 1696)
@@ -47,6 +47,9 @@
*/
public class Section508Compliance extends BytecodeScanningDetector
{
+ private static final String SAW_TEXT_LABEL = "SAW_TEXT_LABEL";
+ private static final String FROM_UIMANAGER = "FROM_UIMANAGER";
+
private static JavaClass windowClass;
private static JavaClass componentClass;
private static JavaClass jcomponentClass;
@@ -200,13 +203,14 @@
@Override
public void sawOpcode(int seen) {
boolean sawTextLabel = false;
+ boolean sawUIManager = false;
try {
stack.mergeJumps(this);
if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) {
if (stack.getStackDepth() > 0) {
OpcodeStack.Item item = stack.getStackItem(0);
if ("Ljavax/swing/JLabel;".equals(item.getSignature())
- && (item.getUserValue() != null)) {
+ && (SAW_TEXT_LABEL.equals(item.getUserValue()))) {
int reg = RegisterUtils.getAStoreReg(this, seen);
localLabels.put(Integer.valueOf(reg), SourceLineAnnotation.fromVisitedInstruction(this));
}
@@ -214,7 +218,7 @@
} else if (seen == PUTFIELD) {
if (stack.getStackDepth() > 0) {
OpcodeStack.Item item = stack.getStackItem(0);
- if (item.getUserValue() == null) {
+ if (!SAW_TEXT_LABEL.equals(item.getUserValue())) {
FieldAnnotation fa = new FieldAnnotation(getDottedClassName(), getNameConstantOperand(), getSigConstantOperand(), false);
fieldLabels.remove(XFactory.createXField(fa));
}
@@ -278,17 +282,24 @@
|| "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));
- }
+ OpcodeStack.Item item = stack.getStackItem(0);
+ if (!FROM_UIMANAGER.equals(item.getUserValue())) {
+ 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));
+ }
+ }
}
}
+ } else if (seen == INVOKESTATIC) {
+ if ("javax/swing/UIManager".equals(getClassConstantOperand())) {
+ sawUIManager = true;
+ }
}
if ((seen == INVOKEVIRTUAL) || (seen == INVOKESPECIAL) || (seen == INVOKEINTERFACE)) {
@@ -319,8 +330,13 @@
if (sawTextLabel) {
if (stack.getStackDepth() > 0) {
OpcodeStack.Item item = stack.getStackItem(0);
- item.setUserValue(Boolean.TRUE);
+ item.setUserValue(SAW_TEXT_LABEL);
}
+ } else if (sawUIManager) {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ item.setUserValue(FROM_UIMANAGER);
+ }
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2011-07-04 23:47:40
|
Revision: 1698
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1698&view=rev
Author: dbrosius
Date: 2011-07-04 23:47:34 +0000 (Mon, 04 Jul 2011)
Log Message:
-----------
refactor sawOpcode by pulling out methods to simplify
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2011-07-04 02:41:38 UTC (rev 1697)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2011-07-04 23:47:34 UTC (rev 1698)
@@ -236,20 +236,8 @@
} 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));
- }
- }
- }
- } else if ("javax/swing/JLabel".equals(className)) {
+
+ if ("javax/swing/JLabel".equals(className)) {
if ("setLabelFor".equals(methodName)) {
if (stack.getStackDepth() > 1) {
OpcodeStack.Item item = stack.getStackItem(1);
@@ -264,38 +252,11 @@
}
}
}
- } else 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 != null) && cls.instanceOf(windowClass)) {
- bugReporter.reportBug(new BugInstance(this, "S508C_NO_SETSIZE", NORMAL_PRIORITY)
- .addClass(this)
- .addMethod(this)
- .addSourceLine(this));
- }
- }
}
-
- if ("setBackground".equals(methodName)
- || "setForeground".equals(methodName)) {
- int argCount = Type.getArgumentTypes(getSigConstantOperand()).length;
- if (stack.getStackDepth() > argCount) {
- OpcodeStack.Item item = stack.getStackItem(0);
- if (!FROM_UIMANAGER.equals(item.getUserValue())) {
- 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));
- }
- }
- }
- }
+
+ processSetSizeOps(methodName);
+ processNullLayouts(className, methodName);
+ processSetColorOps(methodName);
} else if (seen == INVOKESTATIC) {
if ("javax/swing/UIManager".equals(getClassConstantOperand())) {
sawUIManager = true;
@@ -303,25 +264,7 @@
}
if ((seen == INVOKEVIRTUAL) || (seen == INVOKESPECIAL) || (seen == INVOKEINTERFACE)) {
- StringBuilder methodInfo = new StringBuilder();
- methodInfo.append(getClassConstantOperand());
- methodInfo.append("#");
- methodInfo.append(getNameConstantOperand());
- String signature = getSigConstantOperand();
- signature = signature.substring(0, signature.indexOf(')') + 1);
- methodInfo.append(signature);
- Integer parmIndex = displayTextMethods.get(methodInfo.toString());
- if (parmIndex != null) {
- if (stack.getStackDepth() >= parmIndex.intValue()) {
- OpcodeStack.Item item = stack.getStackItem(parmIndex.intValue());
- if (item.getConstant() != null) {
- bugReporter.reportBug(new BugInstance(this, "S508C_NON_TRANSLATABLE_STRING", NORMAL_PRIORITY)
- .addClass(this)
- .addMethod(this)
- .addSourceLine(this));
- }
- }
- }
+ processUntranslatableStrings();
}
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
@@ -340,4 +283,102 @@
}
}
}
+
+ /**
+ * looks for calls to set a readable string that is generated from a static constant.
+ */
+ private void processUntranslatableStrings() {
+ StringBuilder methodInfo = new StringBuilder();
+ methodInfo.append(getClassConstantOperand());
+ methodInfo.append("#");
+ methodInfo.append(getNameConstantOperand());
+ String signature = getSigConstantOperand();
+ signature = signature.substring(0, signature.indexOf(')') + 1);
+ methodInfo.append(signature);
+ Integer parmIndex = displayTextMethods.get(methodInfo.toString());
+ if (parmIndex != null) {
+ if (stack.getStackDepth() >= parmIndex.intValue()) {
+ OpcodeStack.Item item = stack.getStackItem(parmIndex.intValue());
+ if (item.getConstant() != null) {
+ bugReporter.reportBug(new BugInstance(this, "S508C_NON_TRANSLATABLE_STRING", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ }
+ }
+ }
+
+ /**
+ * looks for containers where a null layout is installed
+ *
+ * @param className class that a method call is made on
+ * @param methodName name of the method that is called
+ */
+ private void processNullLayouts(String className, String methodName) {
+ 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));
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * looks for calls to set the color of components where the color isn't from UIManager
+ *
+ * @param methodName the method that is called
+ *
+ * @throws ClassNotFoundException if the gui component class can't be found
+ */
+ private void processSetColorOps(String methodName) throws ClassNotFoundException {
+ if ("setBackground".equals(methodName)
+ || "setForeground".equals(methodName)) {
+ int argCount = Type.getArgumentTypes(getSigConstantOperand()).length;
+ if (stack.getStackDepth() > argCount) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ if (!FROM_UIMANAGER.equals(item.getUserValue())) {
+ 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));
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * looks for calls to setSize on components, rather than letting the layout manager set them
+ *
+ * @param methodName the method that was called on a component
+ *
+ * @throws ClassNotFoundException if the gui class wasn't found
+ */
+ private void processSetSizeOps(String methodName) throws ClassNotFoundException {
+ 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 != null) && cls.instanceOf(windowClass)) {
+ bugReporter.reportBug(new BugInstance(this, "S508C_NO_SETSIZE", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ }
+ }
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2011-07-23 04:27:34
|
Revision: 1702
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1702&view=rev
Author: dbrosius
Date: 2011-07-23 04:27:27 +0000 (Sat, 23 Jul 2011)
Log Message:
-----------
oi
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2011-07-08 18:50:42 UTC (rev 1701)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2011-07-23 04:27:27 UTC (rev 1702)
@@ -25,7 +25,6 @@
import org.apache.bcel.Repository;
import org.apache.bcel.classfile.Code;
-import org.apache.bcel.classfile.ConstantString;
import org.apache.bcel.classfile.Field;
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.generic.Type;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|