/** Helper method of {@link #match(OpCandidate, Object[])}. */ private String typeClashMessage(final OpCandidate candidate, final Object[] args, final int index) { int i = 0; for (final ModuleItem<?> item : candidate.inputs()) { if (i++ == index) { final Object arg = args[index]; final String argType = arg == null ? "null" : arg.getClass().getName(); final Type inputType = item.getGenericType(); return index + ": cannot coerce " + argType + " -> " + inputType; } } throw new IllegalArgumentException("Invalid index: " + index); }
/** Helper method of {@link #match(OpCandidate, Object[])}. */ private boolean canAssign(final OpCandidate candidate, final Object arg, final ModuleItem<?> item) { if (arg == null) { if (item.isRequired()) { candidate.setStatus(StatusCode.REQUIRED_ARG_IS_NULL, null, item); return false; } return true; } final Type type = item.getGenericType(); if (!canConvert(arg, type)) { candidate.setStatus(StatusCode.CANNOT_CONVERT, arg.getClass().getName() + " => " + type, item); return false; } return true; }
/** Helper method of {@link #assignInputs}. */ private void assign(final Module module, final Object arg, final ModuleItem<?> item) { if (arg != null) { final Type type = item.getGenericType(); final Object value = convert(arg, type); module.setInput(item.getName(), value); } module.resolveInput(item.getName()); }
private boolean outputTypesMatch(final Type returnType, final OpCandidate candidate) { final List<Type> outTypes = new ArrayList<>(); for (final ModuleItem<?> output : candidate.outputs()) { outTypes.add(output.getGenericType()); } if (outTypes.size() == 0) return returnType == void.class; final Type baseType; if (outTypes.size() == 1) baseType = returnType; else { // multiple return types; so the method return type must be a list if (GenericUtils.getClass(returnType) != List.class) return false; // use the list's generic type parameter as the base type baseType = GenericUtils.getTypeParameter(returnType, List.class, 0); } for (final Type outType : outTypes) { if (!isSuperType(baseType, outType)) return false; } return true; }
/** Creates a new module item with the same values as the given item. */ public DefaultMutableModuleItem(final ModuleInfo info, final ModuleItem<T> item) { super(info); name = item.getName(); type = item.getType(); genericType = item.getGenericType(); ioType = item.getIOType(); visibility = item.getVisibility(); required = item.isRequired(); persisted = item.isPersisted(); persistKey = item.getPersistKey(); initializer = item.getInitializer(); validater = item.getValidater(); callback = item.getCallback(); widgetStyle = item.getWidgetStyle(); minimumValue = item.getMinimumValue(); maximumValue = item.getMaximumValue(); softMinimum = item.getSoftMinimum(); softMaximum = item.getSoftMaximum(); stepSize = item.getStepSize(); columnCount = item.getColumnCount(); final List<T> itemChoices = item.getChoices(); if (itemChoices != null) choices.addAll(itemChoices); label = item.getLabel(); description = item.getDescription(); }
/** Creates a new module item with the same values as the given item. */ public DefaultMutableModuleItem(final ModuleInfo info, final ModuleItem<T> item) { super(info); name = item.getName(); type = item.getType(); genericType = item.getGenericType(); ioType = item.getIOType(); visibility = item.getVisibility(); required = item.isRequired(); persisted = item.isPersisted(); persistKey = item.getPersistKey(); initializer = item.getInitializer(); validater = item.getValidater(); callback = item.getCallback(); widgetStyle = item.getWidgetStyle(); minimumValue = item.getMinimumValue(); maximumValue = item.getMaximumValue(); softMinimum = item.getSoftMinimum(); softMaximum = item.getSoftMaximum(); stepSize = item.getStepSize(); columnCount = item.getColumnCount(); final List<T> itemChoices = item.getChoices(); if (itemChoices != null) choices.addAll(itemChoices); label = item.getLabel(); description = item.getDescription(); }