Class[] types = new Class[args.length];
for(int i=0; i<args.length; i++) {
types[i] = args[i].getType();
if(types[i] == null) {
if(!(args[i] instanceof Reference)){
throw new QueryResolverException("ERR.015.008.0035", QueryPlugin.Util.getString("ERR.015.008.0035", new Object[] {args[i], function})); //$NON-NLS-1$ //$NON-NLS-2$
}
hasArgWithoutType = true;
}
}
//special case handling for convert of an untyped reference
if (FunctionLibrary.isConvert(function) && hasArgWithoutType) {
Constant constant = (Constant)function.getArg(1);
Class<?> type = DataTypeManager.getDataTypeClass((String)constant.getValue());
setDesiredType(function.getArg(0), type, function);
types[0] = type;
hasArgWithoutType = false;
}
// Attempt to get exact match of function for this signature
FunctionDescriptor fd = findWithImplicitConversions(library, function, args, types, hasArgWithoutType);
// Function did not resolve - determine reason and throw exception
if(fd == null) {
FunctionForm form = library.findFunctionForm(function.getName(), args.length);
if(form == null) {
// Unknown function form
throw new QueryResolverException("ERR.015.008.0039", QueryPlugin.Util.getString("ERR.015.008.0039", function)); //$NON-NLS-1$ //$NON-NLS-2$
}
// Known function form - but without type information
if (hasArgWithoutType) {
throw new QueryResolverException("ERR.015.008.0036", QueryPlugin.Util.getString("ERR.015.008.0036", function)); //$NON-NLS-1$ //$NON-NLS-2$
}
// Known function form - unable to find implicit conversions
throw new QueryResolverException("ERR.015.008.0040", QueryPlugin.Util.getString("ERR.015.008.0040", function)); //$NON-NLS-1$ //$NON-NLS-2$
}
if(fd.getName().equalsIgnoreCase(FunctionLibrary.CONVERT) || fd.getName().equalsIgnoreCase(FunctionLibrary.CAST)) {
String dataType = (String) ((Constant)args[1]).getValue();
Class dataTypeClass = DataTypeManager.getDataTypeClass(dataType);
fd = library.findTypedConversionFunction(args[0].getType(), dataTypeClass);
// Verify that the type conversion from src to type is even valid
Class srcTypeClass = args[0].getType();
if(srcTypeClass != null && dataTypeClass != null &&
!srcTypeClass.equals(dataTypeClass) &&
!DataTypeManager.isTransformable(srcTypeClass, dataTypeClass)) {
throw new QueryResolverException("ERR.015.008.0037", QueryPlugin.Util.getString("ERR.015.008.0037", new Object[] {DataTypeManager.getDataTypeName(srcTypeClass), dataType})); //$NON-NLS-1$ //$NON-NLS-2$
}
} else if(fd.getName().equalsIgnoreCase(FunctionLibrary.LOOKUP)) {
ResolverUtil.ResolvedLookup lookup = ResolverUtil.resolveLookup(function, metadata);
fd = library.copyFunctionChangeReturnType(fd, lookup.getReturnElement().getType());
}