public ConsList<Binding> matches(TypeHierarchy types, Method method,
TACInstruction instr) {
if (!(instr instanceof ReturnInstruction))
return null;
ReturnInstruction invoke = (ReturnInstruction) instr;
IMethodBinding binding = method.getBinding();
if (methodName != null && !(methodName.equals(binding.getName())))
return null;
if (thisType != null && !types.existsCommonSubtype(thisType, binding.getDeclaringClass().getQualifiedName()))
return null;
//it should match if the op is static and the method we are in is not, but not
//the other way around.
if (method.getThisVar() == null && !isStatic)
return null;
if (resType != null) {
if (invoke.getReturnedVariable() == null)
return null;
String resVarType = invoke.getReturnedVariable().resolveType().getQualifiedName();
if (!types.existsCommonSubtype(resType, resVarType))
return null;
}
ConsList<Binding> vars = ConsList.empty();
Variable[] params = method.getParams();
if (paramTypes != null) {
if (binding.getParameterTypes().length != paramTypes.length)
return null;
for (int ndx = 0; ndx < paramTypes.length; ndx++) {
if (!types.existsCommonSubtype(paramTypes[ndx], binding.getParameterTypes()[ndx].getQualifiedName()))
return null;
vars = ConsList.cons(new Binding(paramNames[ndx], params[ndx]), vars);
}
}
if (invoke.getReturnedVariable() != null && resType != null)
vars = ConsList.cons(new Binding(Constraint.RESULT, invoke.getReturnedVariable()), vars);
if (!isStatic)
vars = ConsList.cons(new Binding(Constraint.RECEIVER, method.getThisVar()), vars);
return vars;
}