[Fb-contrib-commit] SF.net SVN: fb-contrib:[1237] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/
Brought to you by:
dbrosius
|
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.
|