use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class UnusedParameter method visitCode.
/**
* implements the visitor to clear the parm set, and check for potential methods
*
* @param obj
* the context object of the currently parsed code block
*/
@Override
public void visitCode(Code obj) {
unusedParms.clear();
regToParm.clear();
stack.resetForMethodEntry(this);
Method m = getMethod();
String methodName = m.getName();
if (IGNORE_METHODS.contains(methodName)) {
return;
}
int accessFlags = m.getAccessFlags();
if (((accessFlags & (Const.ACC_STATIC | Const.ACC_PRIVATE)) == 0) || ((accessFlags & Const.ACC_SYNTHETIC) != 0)) {
return;
}
List<String> parmTypes = SignatureUtils.getParameterSignatures(m.getSignature());
if (parmTypes.isEmpty()) {
return;
}
int firstReg = 0;
if ((accessFlags & Const.ACC_STATIC) == 0) {
++firstReg;
}
int reg = firstReg;
for (int i = 0; i < parmTypes.size(); ++i) {
unusedParms.set(reg);
regToParm.put(Integer.valueOf(reg), Integer.valueOf(i + 1));
String parmSig = parmTypes.get(i);
reg += SignatureUtils.getSignatureSize(parmSig);
}
try {
super.visitCode(obj);
if (!unusedParms.isEmpty()) {
LocalVariableTable lvt = m.getLocalVariableTable();
reg = unusedParms.nextSetBit(firstReg);
while (reg >= 0) {
LocalVariable lv = (lvt == null) ? null : lvt.getLocalVariable(reg, 0);
if (lv != null) {
String parmName = lv.getName();
bugReporter.reportBug(new BugInstance(this, BugType.UP_UNUSED_PARAMETER.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addString("Parameter " + regToParm.get(Integer.valueOf(reg)) + ": " + parmName));
}
reg = unusedParms.nextSetBit(reg + 1);
}
}
} catch (StopOpcodeParsingException e) {
// no unusedParms left
}
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class UseVarArgs method hasMethod.
/**
* looks to see if a class has a method with a specific name and signature
*
* @param c
* the class to check
* @param candidateMethod
* the method to look for
*
* @return whether this class has the exact method
*/
private static boolean hasMethod(JavaClass c, Method candidateMethod) {
String name = candidateMethod.getName();
String sig = candidateMethod.getSignature();
for (Method method : c.getMethods()) {
if (!method.isStatic() && method.getName().equals(name) && method.getSignature().equals(sig)) {
return true;
}
}
return false;
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class JPAIssues method catalogClass.
/**
* parses the current class for spring-tx and jpa annotations, as well as hashCode and equals methods.
*
* @param cls
* the currently parsed class
*/
private void catalogClass(JavaClass cls) {
transactionalMethods = new HashMap<>();
isEntity = false;
hasId = false;
hasGeneratedValue = false;
hasEagerOneToMany = false;
hasHCEquals = false;
for (AnnotationEntry entry : cls.getAnnotationEntries()) {
if ("Ljavax/persistence/Entity;".equals(entry.getAnnotationType())) {
isEntity = true;
break;
}
}
for (Method m : cls.getMethods()) {
catalogFieldOrMethod(m);
if (("equals".equals(m.getName()) && SignatureBuilder.SIG_OBJECT_TO_BOOLEAN.equals(m.getSignature())) || (Values.HASHCODE.equals(m.getName()) && SignatureBuilder.SIG_VOID_TO_INT.equals(m.getSignature()))) {
hasHCEquals = true;
}
}
for (Field f : cls.getFields()) {
catalogFieldOrMethod(f);
}
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class JPAIssues method visitCode.
/**
* implements the visitor to reset the opcode stack, Note that the synthetic check is done in both visitMethod and visitCode as visitMethod is not a proper
* listener stopping method. We don't want to report issues reported in visitMethod if it is synthetic, but we also don't want it to get into sawOpcode, so
* that is why it is done here as well.
*
* @param obj
* the currently parsed code block
*/
@Override
public void visitCode(Code obj) {
Method m = getMethod();
if (m.isSynthetic()) {
return;
}
isPublic = m.isPublic();
stack.resetForMethodEntry(this);
super.visitCode(obj);
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class ConfusingAutoboxedOverloading method populateMethodInfo.
/**
* fills out a set of method details for possibly confusing method signatures
*
* @param cls
* the current class being parsed
* @param methodInfo
* a collection to hold possibly confusing methods
*/
private void populateMethodInfo(JavaClass cls, Map<String, Set<String>> methodInfo) {
try {
if (Values.DOTTED_JAVA_LANG_OBJECT.equals(cls.getClassName())) {
return;
}
Method[] methods = cls.getMethods();
for (Method m : methods) {
String sig = m.getSignature();
if (isPossiblyConfusingSignature(sig)) {
String name = m.getName();
Set<String> sigs = methodInfo.get(name);
if (sigs == null) {
sigs = new HashSet<>(3);
methodInfo.put(name, sigs);
}
sigs.add(m.getSignature());
}
}
populateMethodInfo(cls.getSuperClass(), methodInfo);
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
}
}
Aggregations