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