use of edu.umd.cs.findbugs.OpcodeStack in project fb-contrib by mebigfatguy.
the class PoorMansEnum method visitClassContext.
@Override
public void visitClassContext(ClassContext classContext) {
try {
JavaClass cls = classContext.getJavaClass();
if (cls.getMajor() >= Const.MAJOR_1_5) {
fieldValues = new HashMap<>();
nameToField = new HashMap<>();
for (Field f : cls.getFields()) {
if (f.isPrivate() && !f.isSynthetic()) {
String fieldName = f.getName();
// preallocating a set per field is just a waste, so just insert the empty set as a place holder
fieldValues.put(fieldName, Collections.emptySet());
nameToField.put(fieldName, f);
}
}
if (!fieldValues.isEmpty()) {
stack = new OpcodeStack();
firstFieldUse = new HashMap<>();
try {
super.visitClassContext(classContext);
for (Map.Entry<String, Set<Object>> fieldInfo : fieldValues.entrySet()) {
Set<Object> values = fieldInfo.getValue();
if (values.size() >= 3) {
String fieldName = fieldInfo.getKey();
bugReporter.reportBug(new BugInstance(this, BugType.PME_POOR_MANS_ENUM.name(), NORMAL_PRIORITY).addClass(this).addField(XFactory.createXField(cls, nameToField.get(fieldName))).addSourceLine(firstFieldUse.get(fieldName)));
}
}
} catch (StopOpcodeParsingException e) {
// no fields left
}
}
}
} finally {
fieldValues = null;
nameToField = null;
firstFieldUse = null;
stack = null;
}
}
use of edu.umd.cs.findbugs.OpcodeStack in project fb-contrib by mebigfatguy.
the class LocalTypeDetector method visitClassContext.
/**
* implements the visitor to create and clear the stack and suspectLocals
*
* @param classContext
* the context object of the currently parsed class
*/
@Override
public void visitClassContext(ClassContext classContext) {
try {
stack = new OpcodeStack();
suspectLocals = new HashMap<>();
classVersion = classContext.getJavaClass().getMajor();
super.visitClassContext(classContext);
} finally {
stack = null;
suspectLocals = null;
}
}
use of edu.umd.cs.findbugs.OpcodeStack in project fb-contrib by mebigfatguy.
the class LoggerOddities method visitClassContext.
/**
* implements the visitor to discover what the class name is if it is a normal class, or the owning class, if the class is an anonymous class.
*
* @param classContext
* the context object of the currently parsed class
*/
@Override
public void visitClassContext(ClassContext classContext) {
try {
stack = new OpcodeStack();
nameOfThisClass = SignatureUtils.getNonAnonymousPortion(classContext.getJavaClass().getClassName());
formatterLoggers = new HashSet<>();
super.visitClassContext(classContext);
} finally {
formatterLoggers = null;
stack = null;
}
}
use of edu.umd.cs.findbugs.OpcodeStack in project fb-contrib by mebigfatguy.
the class LostExceptionStackTrace method visitClassContext.
/**
* implements the visitor to make sure the jdk is 1.4 or better
*
* @param classContext
* the context object of the currently parsed class
*/
@Override
public void visitClassContext(ClassContext classContext) {
try {
if ((throwableClass != null) && !isPre14Class(classContext.getJavaClass())) {
stack = new OpcodeStack();
catchInfos = new HashSet<>();
exReg = new HashMap<>();
super.visitClassContext(classContext);
}
} finally {
stack = null;
catchInfos = null;
exceptions = null;
exReg = null;
}
}
use of edu.umd.cs.findbugs.OpcodeStack in project fb-contrib by mebigfatguy.
the class MethodReturnsConstant method visitClassContext.
/**
* implements the visitor to collect all methods that are overloads. These methods should be ignored, as you may differentiate Const based on parameter
* type, or value.
*
* @param classContext
* the currently parsed class object
*/
@Override
public void visitClassContext(ClassContext classContext) {
try {
stack = new OpcodeStack();
registerConstants = new HashMap<>();
overloadedMethods = collectOverloadedMethods(classContext.getJavaClass());
super.visitClassContext(classContext);
} finally {
stack = null;
registerConstants = null;
overloadedMethods = null;
}
}
Aggregations