public AssignmentTestable.TestResult testAssignment(String keyspace, ColumnSpecification receiver) { // Note: Functions.get() will return null if the function doesn't exist, or throw is no function matching // the arguments can be found. We may get one of those if an undefined/wrong function is used as argument // of another, existing, function. In that case, we return true here because we'll throw a proper exception // later with a more helpful error message that if we were to return false here. try { Function fun = FunctionResolver.get(keyspace, name, terms, receiver.ksName, receiver.cfName, receiver.type); // Because fromJson() can return whatever type the receiver is, we'll always get EXACT_MATCH. To // handle potentially ambiguous function calls with fromJson() as an argument, always return // WEAKLY_ASSIGNABLE to force the user to typecast if necessary if (fun != null && fun.name().equals(FromJsonFct.NAME)) return TestResult.WEAKLY_ASSIGNABLE; if (fun != null && receiver.type.equals(fun.returnType())) return AssignmentTestable.TestResult.EXACT_MATCH; else if (fun == null || receiver.type.isValueCompatibleWith(fun.returnType())) return AssignmentTestable.TestResult.WEAKLY_ASSIGNABLE; else return AssignmentTestable.TestResult.NOT_ASSIGNABLE; } catch (InvalidRequestException e) { return AssignmentTestable.TestResult.WEAKLY_ASSIGNABLE; } }
public AssignmentTestable.TestResult testAssignment(String keyspace, ColumnSpecification receiver) { // Note: Functions.get() will return null if the function doesn't exist, or throw is no function matching // the arguments can be found. We may get one of those if an undefined/wrong function is used as argument // of another, existing, function. In that case, we return true here because we'll throw a proper exception // later with a more helpful error message that if we were to return false here. try { Function fun = FunctionResolver.get(keyspace, name, terms, receiver.ksName, receiver.cfName, receiver.type); // Because fromJson() can return whatever type the receiver is, we'll always get EXACT_MATCH. To // handle potentially ambiguous function calls with fromJson() as an argument, always return // WEAKLY_ASSIGNABLE to force the user to typecast if necessary if (fun != null && fun.name().equals(FromJsonFct.NAME)) return TestResult.WEAKLY_ASSIGNABLE; if (fun != null && receiver.type.equals(fun.returnType())) return AssignmentTestable.TestResult.EXACT_MATCH; else if (fun == null || receiver.type.isValueCompatibleWith(fun.returnType())) return AssignmentTestable.TestResult.WEAKLY_ASSIGNABLE; else return AssignmentTestable.TestResult.NOT_ASSIGNABLE; } catch (InvalidRequestException e) { return AssignmentTestable.TestResult.WEAKLY_ASSIGNABLE; } }
public AssignmentTestable.TestResult testAssignment(String keyspace, ColumnSpecification receiver) { // Note: Functions.get() will return null if the function doesn't exist, or throw is no function matching // the arguments can be found. We may get one of those if an undefined/wrong function is used as argument // of another, existing, function. In that case, we return true here because we'll throw a proper exception // later with a more helpful error message that if we were to return false here. try { Function fun = FunctionResolver.get(keyspace, name, terms, receiver.ksName, receiver.cfName, receiver.type); // Because fromJson() can return whatever type the receiver is, we'll always get EXACT_MATCH. To // handle potentially ambiguous function calls with fromJson() as an argument, always return // WEAKLY_ASSIGNABLE to force the user to typecast if necessary if (fun != null && fun.name().equals(FromJsonFct.NAME)) return TestResult.WEAKLY_ASSIGNABLE; if (fun != null && receiver.type.equals(fun.returnType())) return AssignmentTestable.TestResult.EXACT_MATCH; else if (fun == null || receiver.type.isValueCompatibleWith(fun.returnType())) return AssignmentTestable.TestResult.WEAKLY_ASSIGNABLE; else return AssignmentTestable.TestResult.NOT_ASSIGNABLE; } catch (InvalidRequestException e) { return AssignmentTestable.TestResult.WEAKLY_ASSIGNABLE; } }