use of edu.umd.cs.findbugs.SourceLineAnnotation in project fb-contrib by mebigfatguy.
the class FieldCouldBeLocal method visitClassContext.
/**
* overrides the visitor to collect localizable fields, and then report those that survive all method checks.
*
* @param classContext
* the context object that holds the JavaClass parsed
*/
@Override
public void visitClassContext(ClassContext classContext) {
try {
localizableFields = new HashMap<>();
visitedBlocks = new BitSet();
clsContext = classContext;
clsName = clsContext.getJavaClass().getClassName();
clsSig = SignatureUtils.classToSignature(clsName);
JavaClass cls = classContext.getJavaClass();
Field[] fields = cls.getFields();
ConstantPool cp = classContext.getConstantPoolGen().getConstantPool();
for (Field f : fields) {
if (!f.isStatic() && !f.isVolatile() && (f.getName().indexOf(Values.SYNTHETIC_MEMBER_CHAR) < 0) && f.isPrivate()) {
FieldAnnotation fa = new FieldAnnotation(cls.getClassName(), f.getName(), f.getSignature(), false);
boolean hasExternalAnnotation = false;
for (AnnotationEntry entry : f.getAnnotationEntries()) {
ConstantUtf8 cutf = (ConstantUtf8) cp.getConstant(entry.getTypeIndex());
if (!cutf.getBytes().startsWith(Values.JAVA)) {
hasExternalAnnotation = true;
break;
}
}
localizableFields.put(f.getName(), new FieldInfo(fa, hasExternalAnnotation));
}
}
if (!localizableFields.isEmpty()) {
buildMethodFieldModifiers(classContext);
super.visitClassContext(classContext);
for (FieldInfo fi : localizableFields.values()) {
FieldAnnotation fa = fi.getFieldAnnotation();
SourceLineAnnotation sla = fi.getSrcLineAnnotation();
BugInstance bug = new BugInstance(this, BugType.FCBL_FIELD_COULD_BE_LOCAL.name(), NORMAL_PRIORITY).addClass(this).addField(fa);
if (sla != null) {
bug.addSourceLine(sla);
}
bugReporter.reportBug(bug);
}
}
} finally {
localizableFields = null;
visitedBlocks = null;
clsContext = null;
methodFieldModifiers = null;
}
}
use of edu.umd.cs.findbugs.SourceLineAnnotation in project fb-contrib by mebigfatguy.
the class Section508Compliance method visitCode.
/**
* implements the visitor to reset the stack
*
* @param obj
* the context object for the currently visited code block
*/
@Override
public void visitCode(Code obj) {
stack.resetForMethodEntry(this);
localLabels.clear();
super.visitCode(obj);
for (SourceLineAnnotation sla : localLabels.values()) {
BugInstance bug = new BugInstance(this, BugType.S508C_NO_SETLABELFOR.name(), NORMAL_PRIORITY).addClass(this).addMethod(this);
if (sla != null) {
bug.addSourceLine(sla);
}
bugReporter.reportBug(bug);
}
}
use of edu.umd.cs.findbugs.SourceLineAnnotation in project fb-contrib by mebigfatguy.
the class UnrelatedCollectionContents method checkAdd.
/**
* processes an add into a collection, by processing all the super classes/interfaces of an object and removing the possible set of parent classes that have
* been seen so far, by doing what amounts to a intersection of what has been seen before, and this occurance.
*
* @param colItm
* the collection that is being added to
* @param addItm
* the added item
* @throws ClassNotFoundException
* if a super class is not found
*/
private void checkAdd(final OpcodeStack.Item colItm, final OpcodeStack.Item addItm) throws ClassNotFoundException {
int reg = colItm.getRegisterNumber();
if (reg == -1) {
XField field = colItm.getXField();
if (field == null) {
return;
}
Set<SourceLineAnnotation> sla = memberSourceLineAnnotations.get(field.getName());
if (sla == null) {
sla = new HashSet<>();
memberSourceLineAnnotations.put(field.getName(), sla);
}
sla.add(SourceLineAnnotation.fromVisitedInstruction(this));
FQField fqField = new FQField(field.getClassName(), field.getName(), field.getSignature());
Set<String> commonSupers = memberCollections.get(fqField);
if (commonSupers == null) {
commonSupers = new HashSet<>();
memberCollections.put(fqField, commonSupers);
addNewItem(commonSupers, addItm);
} else {
mergeItem(commonSupers, sla, addItm);
}
} else {
Integer regNumber = Integer.valueOf(reg);
Set<SourceLineAnnotation> pcs = localSourceLineAnnotations.get(regNumber);
if (pcs == null) {
pcs = new HashSet<>();
localSourceLineAnnotations.put(regNumber, pcs);
}
pcs.add(SourceLineAnnotation.fromVisitedInstruction(this, getPC()));
Set<String> commonSupers = localCollections.get(regNumber);
if (commonSupers == null) {
commonSupers = new HashSet<>();
localCollections.put(Integer.valueOf(reg), commonSupers);
addNewItem(commonSupers, addItm);
Integer scopeEnd = Integer.valueOf(RegisterUtils.getLocalVariableEndRange(getMethod().getLocalVariableTable(), reg, getNextPC()));
BitSet regs = localScopeEnds.get(scopeEnd);
if (regs == null) {
regs = new BitSet();
localScopeEnds.put(scopeEnd, regs);
}
regs.set(regNumber);
} else {
mergeItem(commonSupers, pcs, addItm);
}
}
}
use of edu.umd.cs.findbugs.SourceLineAnnotation in project fb-contrib by mebigfatguy.
the class NonRecycleableTaglibs method sawOpcode.
/**
* implements the visitor to record storing of fields, and where they occur
*
* @param seen
* the currently parsed opcode
*/
@Override
public void sawOpcode(int seen) {
if (seen == PUTFIELD) {
QMethod methodInfo = new QMethod(getMethodName(), getMethodSig());
Map<Map.Entry<String, String>, SourceLineAnnotation> fields = methodWrites.get(methodInfo);
if (fields == null) {
fields = new HashMap<>();
methodWrites.put(methodInfo, fields);
}
String fieldName = getNameConstantOperand();
String fieldSig = getSigConstantOperand();
FieldAnnotation fa = new FieldAnnotation(getDottedClassName(), fieldName, fieldSig, false);
fieldAnnotations.put(fieldName, fa);
fields.put(new AbstractMap.SimpleImmutableEntry(fieldName, fieldSig), SourceLineAnnotation.fromVisitedInstruction(this));
}
}
use of edu.umd.cs.findbugs.SourceLineAnnotation in project fb-contrib by mebigfatguy.
the class NonRecycleableTaglibs method reportBugs.
/**
* generates all the bug reports for attributes that are not recycleable
*/
private void reportBugs() {
for (Map.Entry<QMethod, String> attEntry : attributes.entrySet()) {
QMethod methodInfo = attEntry.getKey();
String attType = attEntry.getValue();
Map<Map.Entry<String, String>, SourceLineAnnotation> fields = methodWrites.get(methodInfo);
if ((fields == null) || (fields.size() != 1)) {
continue;
}
Map.Entry<String, String> fieldInfo = fields.keySet().iterator().next();
String fieldType = fieldInfo.getValue();
if (!attType.equals(fieldType)) {
continue;
}
String fieldName = fieldInfo.getKey();
for (Map.Entry<QMethod, Map<Map.Entry<String, String>, SourceLineAnnotation>> fwEntry : methodWrites.entrySet()) {
if (fwEntry.getKey().equals(methodInfo)) {
continue;
}
SourceLineAnnotation sla = fwEntry.getValue().get(fieldInfo);
if (sla != null) {
bugReporter.reportBug(new BugInstance(this, BugType.NRTL_NON_RECYCLEABLE_TAG_LIB.name(), NORMAL_PRIORITY).addClass(this).addField(fieldAnnotations.get(fieldName)).addSourceLine(sla));
break;
}
}
}
}
Aggregations