use of edu.umd.cs.findbugs.FieldAnnotation in project fb-contrib by mebigfatguy.
the class Section508Compliance method sawOpcode.
/**
* implements the visitor to find 508 compliance concerns
*
* @param seen
* the opcode of the currently parsed instruction
*/
@Override
public void sawOpcode(int seen) {
boolean sawTextLabel = false;
boolean sawUIManager = false;
boolean sawAppend = false;
try {
stack.precomputation(this);
if (OpcodeUtils.isAStore(seen)) {
if (stack.getStackDepth() > 0) {
OpcodeStack.Item item = stack.getStackItem(0);
if ("Ljavax/swing/JLabel;".equals(item.getSignature()) && (S508UserValue.SAW_TEXT_LABEL == item.getUserValue())) {
int reg = RegisterUtils.getAStoreReg(this, seen);
localLabels.put(Integer.valueOf(reg), SourceLineAnnotation.fromVisitedInstruction(this));
}
}
} else if (seen == PUTFIELD) {
if (stack.getStackDepth() > 0) {
OpcodeStack.Item item = stack.getStackItem(0);
if (S508UserValue.SAW_TEXT_LABEL != item.getUserValue()) {
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) && Values.CONSTRUCTOR.equals(methodName)) {
String signature = getSigConstantOperand();
if (signature.indexOf(Values.SIG_JAVA_LANG_STRING) >= 0) {
sawTextLabel = true;
}
}
} else if (seen == INVOKEVIRTUAL) {
String className = getClassConstantOperand();
String methodName = getNameConstantOperand();
if ("javax/swing/JLabel".equals(className)) {
if ("setLabelFor".equals(methodName) && (stack.getStackDepth() > 1)) {
OpcodeStack.Item item = stack.getStackItem(1);
XField field = item.getXField();
if (field != null) {
fieldLabels.remove(field);
} else {
int reg = item.getRegisterNumber();
if (reg >= 0) {
localLabels.remove(Integer.valueOf(reg));
}
}
}
} else if (SignatureUtils.isPlainStringConvertableClass(className)) {
if ("append".equals(methodName)) {
if (stack.getStackDepth() > 0) {
OpcodeStack.Item item = stack.getStackItem(0);
Object con = item.getConstant();
if (con instanceof String) {
String literal = (String) con;
sawAppend = !literal.startsWith("<");
} else {
sawAppend = true;
}
}
} else if (Values.TOSTRING.equals(methodName) && (stack.getStackDepth() > 0)) {
OpcodeStack.Item item = stack.getStackItem(0);
if (S508UserValue.APPENDED_STRING == item.getUserValue()) {
sawAppend = true;
}
}
}
processSetSizeOps(methodName);
processNullLayouts(className, methodName);
processSetColorOps(methodName);
} else if ((seen == INVOKESTATIC) && "javax/swing/UIManager".equals(getClassConstantOperand())) {
sawUIManager = true;
}
if ((seen == INVOKEVIRTUAL) || (seen == INVOKESPECIAL) || (seen == INVOKEINTERFACE)) {
processFaultyGuiStrings();
}
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
} finally {
TernaryPatcher.pre(stack, seen);
stack.sawOpcode(this, seen);
TernaryPatcher.post(stack, seen);
if (sawTextLabel) {
if (stack.getStackDepth() > 0) {
OpcodeStack.Item item = stack.getStackItem(0);
item.setUserValue(S508UserValue.SAW_TEXT_LABEL);
}
} else if (sawUIManager) {
if (stack.getStackDepth() > 0) {
OpcodeStack.Item item = stack.getStackItem(0);
item.setUserValue(S508UserValue.FROM_UIMANAGER);
}
} else if (sawAppend && (stack.getStackDepth() > 0)) {
OpcodeStack.Item item = stack.getStackItem(0);
item.setUserValue(S508UserValue.APPENDED_STRING);
}
}
}
use of edu.umd.cs.findbugs.FieldAnnotation in project fb-contrib by mebigfatguy.
the class WiringIssues method visitClassContext.
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "SF_SWITCH_NO_DEFAULT", justification = "Only a few cases need special handling")
@Override
public void visitClassContext(ClassContext classContext) {
try {
JavaClass cls = classContext.getJavaClass();
Field[] fields = cls.getFields();
if (fields.length > 0) {
Map<WiringType, FieldAnnotation> wiredFields = new HashMap<>();
boolean loadedParents = false;
for (Field field : fields) {
boolean hasAutowired = false;
String qualifier = "";
for (AnnotationEntry entry : field.getAnnotationEntries()) {
switch(entry.getAnnotationType()) {
case SPRING_AUTOWIRED:
if (!loadedParents) {
loadParentAutowireds(cls.getSuperClass(), wiredFields);
loadedParents = true;
}
hasAutowired = true;
break;
case SPRING_QUALIFIER:
qualifier = entry.getElementValuePairs()[0].getValue().stringifyValue();
break;
}
}
if (hasAutowired) {
WiringType wt = new WiringType(field.getSignature(), field.getGenericSignature(), qualifier);
FieldAnnotation existingAnnotation = wiredFields.get(wt);
if (existingAnnotation == null) {
wiredFields.put(wt, FieldAnnotation.fromBCELField(cls.getClassName(), field));
} else {
bugReporter.reportBug(new BugInstance(this, BugType.WI_DUPLICATE_WIRED_TYPES.name(), NORMAL_PRIORITY).addClass(cls).addField(FieldAnnotation.fromBCELField(cls, field)).addField(existingAnnotation));
wiredFields.remove(wt);
}
}
}
}
stack = new OpcodeStack();
super.visitClassContext(classContext);
} catch (ClassNotFoundException e) {
bugReporter.reportMissingClass(e);
} finally {
stack = null;
}
}
Aggregations