use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class OverlyConcreteParameter method buildParameterDefiners.
/**
* builds a map of method information for each method of each interface that each parameter implements of this method
*
* @return a map by parameter id of all the method signatures that interfaces of that parameter implements
*
* @throws ClassNotFoundException
* if the class can't be loaded
*/
private boolean buildParameterDefiners() throws ClassNotFoundException {
Method m = getMethod();
Type[] parms = m.getArgumentTypes();
if (parms.length == 0) {
return false;
}
ParameterAnnotationEntry[] annotations = m.getParameterAnnotationEntries();
boolean hasPossiblyOverlyConcreteParm = false;
for (int i = 0; i < parms.length; i++) {
if ((annotations.length <= i) || (annotations[i] == null) || (annotations[i].getAnnotationEntries().length == 0)) {
String parm = parms[i].getSignature();
if (parm.startsWith(Values.SIG_QUALIFIED_CLASS_PREFIX)) {
String clsName = SignatureUtils.stripSignature(parm);
if (clsName.startsWith("java.lang.")) {
continue;
}
JavaClass clz = Repository.lookupClass(clsName);
if (clz.isClass() && (!clz.isAbstract())) {
Map<JavaClass, List<MethodInfo>> definers = getClassDefiners(clz);
if (!definers.isEmpty()) {
parameterDefiners.put(Integer.valueOf(i + (methodIsStatic ? 0 : 1)), definers);
hasPossiblyOverlyConcreteParm = true;
}
}
}
}
}
return hasPossiblyOverlyConcreteParm;
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class OverlyConcreteParameter method hasOverloadedMethod.
/**
* looks to see if this method has an overloaded method in actuality, this isn't precise and returns true for methods that are named the same, and have same
* number of args This will miss some cases, but in practicality doesn't matter.
*/
private boolean hasOverloadedMethod() {
Method thisMethod = getMethod();
String name = thisMethod.getName();
String sig = thisMethod.getSignature();
int numArgs = SignatureUtils.getNumParameters(sig);
for (Method m : cls.getMethods()) {
if (m.getName().equals(name)) {
if (!m.getSignature().equals(sig) && (numArgs == SignatureUtils.getNumParameters(m.getSignature()))) {
return true;
}
}
}
return false;
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class OverlyPermissiveMethod method visitCode.
@Override
public void visitCode(Code obj) {
Method m = getMethod();
String methodName = m.getName();
String sig = m.getSignature();
if (isAssumedPublic(methodName)) {
MethodInfo mi = Statistics.getStatistics().getMethodStatistics(cls.getClassName(), methodName, sig);
mi.addCallingAccess(Const.ACC_PUBLIC);
} else {
if (!hasRuntimeAnnotations(m) && !isGetterSetter(methodName, sig)) {
MethodInfo mi = Statistics.getStatistics().getMethodStatistics(cls.getClassName(), methodName, sig);
mi.addCallingAccess(Const.ACC_PUBLIC);
}
stack.resetForMethodEntry(this);
super.visitCode(obj);
}
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class PartiallyConstructedObjectAccess method visitCode.
@Override
public void visitCode(final Code obj) {
stack.resetForMethodEntry(this);
String methodName = getMethodName();
isCtor = Values.CONSTRUCTOR.equals(methodName);
if (!Values.STATIC_INITIALIZER.equals(methodName)) {
Method m = getMethod();
methodToCalledMethods.put(m, new HashMap<Method, SourceLineAnnotation>());
try {
super.visitCode(obj);
if (methodToCalledMethods.get(m).isEmpty()) {
methodToCalledMethods.remove(getMethod());
}
} catch (StopOpcodeParsingException e) {
methodToCalledMethods.remove(getMethod());
}
}
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class PartiallyConstructedObjectAccess method foundPrivateInChain.
@Nullable
private Deque<SourceLineAnnotation> foundPrivateInChain(Method m, Set<Method> checkedMethods) {
Map<Method, SourceLineAnnotation> calledMethods = methodToCalledMethods.get(m);
if (calledMethods != null) {
for (Map.Entry<Method, SourceLineAnnotation> entry : calledMethods.entrySet()) {
Method cm = entry.getKey();
if (checkedMethods.contains(cm)) {
continue;
}
if (!cm.isPrivate() && !cm.isFinal()) {
Deque<SourceLineAnnotation> slas = new ArrayDeque<>();
slas.addLast(entry.getValue());
return slas;
}
checkedMethods.add(cm);
Deque<SourceLineAnnotation> slas = foundPrivateInChain(cm, checkedMethods);
if (slas != null) {
slas.addFirst(entry.getValue());
return slas;
}
}
}
return null;
}
Aggregations