SelfConversion implies that if a class has the given static method named
that receive a String and that returns a instance of the
class, then it can serve for conversion purpose.
765151
private static Object selfConvert( String parsingMethod, String value, Class<?> type )
    {
        try
        {
            Method method = type.getMethod( parsingMethod, String.class );
            return method.invoke( null, value );
        }
        catch (InvocationTargetException e)
        {
            throw new IllegalArgumentException( "Can't convert " + value + " to " + type.getName(), e.getCause() );
        }
        catch (Exception e)
        {
            throw new IllegalArgumentException( "Can't convert " + value + " to " + type.getName(), e );
        }
    }
628256
private <T> StringConverter<T> findAnnotatedConverter(final Class<T> cls) {
        Method toString = findToStringMethod(cls);  // checks superclasses
        if (toString == null) {
            return null;
        }
        MethodConstructorStringConverter<T> con = findFromStringConstructor(cls, toString);
        MethodsStringConverter<T> mth = findFromStringMethod(cls, toString, con == null);  // optionally checks superclasses
        if (con == null && mth == null) {
            throw new IllegalStateException("Class annotated with @ToString but not with @FromString: " + cls.getName());
        }
        if (con != null && mth != null) {
            throw new IllegalStateException("Both method and constructor are annotated with @FromString: " + cls.getName());
        }
        return (con != null ? con : mth);
    }
484607
@SuppressWarnings("unchecked")
    public <T> T convert(Object source, String syntax, Class<T> toClass) {
        Object result = null;

        // What are we converting form
        Class<?> fromClass = source.getClass();

        // Deal with primitives
        Class<?> targetClass = toClass;
        if (toClass.isPrimitive()) {
            targetClass = primitiveTypeMap.get(toClass);
        }

        // Try to convert with any syntax we have been given
        Converter syntaxConverter = converters.get(makeConverterKey(fromClass, syntax, targetClass));
        if (syntaxConverter != null) {
            try {
                result = syntaxConverter.convert(source, targetClass);
            } catch (Exception e) {
                // Ignore as we may still be able to convert successfully
            }
        }

        // Do we actually need to do any conversion?
        if (result == null && targetClass.isAssignableFrom(fromClass)) {
            result = source;
        }

        // If we were given a syntax and we failed to convert drop back to any mapping
        // that will work from class -> to class
        if (result == null && syntax != null) {
            Converter nullSyntaxConverter = converters.get(makeConverterKey(fromClass, null, targetClass));
            if (nullSyntaxConverter != null) {
                try {
                    result = nullSyntaxConverter.convert(source, targetClass);
                } catch (Exception e) {
                    // Handled at the end of the method
                }
            }
        }

        if (result == null) {
            throw new ConverterException(String.format(
                    "Cannot convert %1$s of class %2$s via syntax %3$s to class %4$s", source, source.getClass(),
                    syntax, toClass));
        }

        // We cannot do the safe thing of doing a .cast as we need to rely on auto-unboxing to deal with primitives!
        return (T)result;
    }
1303210
@SuppressWarnings({ "unchecked", "rawtypes" })
    public static Object convert(Object source, Class<?> target) throws ConversionException {
        if (target == null) {
            throw new ConversionException("Unable to perform conversion, target was null");
        }
        if (source == null) {
            if (target.isPrimitive()) {
                throw new ConversionException(String.format("Unable to convert null to primitive value of %s", target));
            }
            return source;
        } else if ((source instanceof Float && ((Float) source).isNaN()) || (source instanceof Double && ((Double) source).isNaN())) {
            // Don't convert NaN values
            return source;
        }
        //		if (BaseConnection.class.isAssignableFrom(source.getClass()) && !target.equals(IConnection.class)) {
        //			log.debug("Conversion failure - source: {} target: {}", source.getClass(), target);
        //			throw new ConversionException("Source is not assignable and target is not equal to IConnection");
        //		}
        if (target.isInstance(source)) {
            return source;
        }
        if (target.isAssignableFrom(source.getClass())) {
            return source;
        }
        if (target.isArray()) {
            return convertToArray(source, target);
        }
        if (target.equals(String.class)) {
            return source.toString();
        }
        if (target.isPrimitive()) {
            return convertToWrappedPrimitive(source, primitiveMap.get(target));
        }
        if (wrapperMap.containsKey(target)) {
            return convertToWrappedPrimitive(source, target);
        }
        if (target.equals(Map.class)) {
            return convertBeanToMap(source);
        }
        if (target.equals(List.class) || target.equals(Collection.class)) {
            if (source.getClass().equals(LinkedHashMap.class)) {
                return convertMapToList((LinkedHashMap<?, ?>) source);
            } else if (source.getClass().isArray()) {
                return convertArrayToList((Object[]) source);
            }
        }
        if (target.equals(Set.class) && source.getClass().isArray()) {
            return convertArrayToSet((Object[]) source);
        }
        if (target.equals(Set.class) && source instanceof List) {
            return new HashSet((List) source);
        }
        if (source instanceof Map) {
            return convertMapToBean((Map) source, target);
        }
        throw new ConversionException(String.format("Unable to preform conversion from %s to %s", source, target));
    }
946489
static Converter createDefaultConverter() {
        List<NodeFactory> factories;
        String property = System.getProperty(LIBRARIES_PROPERTY_NAME);

        if (property != null && property.trim().length() > 0) {
            factories = createFactoriesSpecifiedInProperty(property);
        } else {
            factories = createDefaultFactories();
        }

        if (factories.isEmpty()) {
            throw new IllegalStateException("Please add either json.org, Jackson 1.x, Jackson 2.x or Gson to the classpath");
        }
        return new Converter(factories);
    }
1273058
function() {

		var resultClasses = this._static_classes.clone(),
			name,
			value;

		for (name in this._class_bindings) {

			// do not need to check or convert, cause join() will convert everything to string, and nulls to empty string
			resultClasses.push(
				this._class_bindings[name].getValue()
			);

		}

		value = resultClasses.join(' ');

		if (Lava.schema.view.VALIDATE_CLASS_NAMES) {
			this.assertClassStringValid(value);
		}

		return value;

	}
297641
public Object getInstance(String name) throws SshException {
		if (supported.containsKey(name)) {
			try {
				return createInstance(name, (Class<?>) supported.get(name));
			} catch (Throwable t) {
				throw new SshException(t.getMessage(),
						SshException.INTERNAL_ERROR);
			}
		}
		throw new SshException(name + " is not supported",
				SshException.UNSUPPORTED_ALGORITHM);
	}
620513
@SuppressWarnings("unchecked")
    public static <T> T newTypeInstance(String className, Class<T> returnClass) {
        try {
            Class<T> clazz = (Class<T>) Class.forName(className);
            return clazz.newInstance();
        } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
            throw new DeepGenericException(e);
        }
    }
734263
public Object convert(String rawString, Type type, Class<?> genericSubType) {

        Object converted = null;

        if (genericSubType == null && type instanceof ParameterizedType) {
            ParameterizedType pType = (ParameterizedType) type;
            Type[] aTypes = pType.getActualTypeArguments();
            Type genericTypeArg = aTypes.length == 1 ? aTypes[0] : null; //initially only support one type arg
            if (genericTypeArg instanceof Class) { //for the moment we only support a class ... so no type variables; e.g. List<String> is ok but List<T> is not
                Class<?> genericClassArg = (Class<?>) genericTypeArg;
                converted = convert(rawString, pType.getRawType(), genericClassArg);
            } else {
                throw new IllegalArgumentException(Tr.formatMessage(tc, "generic.type.variables.notsupported.CWMCG0018E", type, genericTypeArg));
            }
        } else {
            //first box any primitives
            if (type instanceof Class<?>) {
                Class<?> clazz = (Class<?>) type;
                if (clazz.isPrimitive()) {
                    type = ClassUtils.primitiveToWrapper(clazz);
                }
            }

            //do a simple lookup in the map of converters
            ConversionStatus status = simpleConversion(rawString, type, genericSubType);

            if (!status.isConverterFound() && type instanceof Class) {
                Class<?> requestedClazz = (Class<?>) type;

                //try array conversion
                if (requestedClazz.isArray()) {
                    Class<?> arrayType = requestedClazz.getComponentType();
                    Class<?> conversionType = arrayType;
                    //first convert primitives to wrapper types
                    if (arrayType.isPrimitive()) {
                        conversionType = ClassUtils.primitiveToWrapper(arrayType);
                    }
                    //convert to an array of the wrapper type
                    Object[] wrappedArray = convertArray(rawString, conversionType);// convertArray will throw ConverterNotFoundException if it can't find a converter

                    //switch back to the primitive type if required
                    Object value = wrappedArray;
                    if (arrayType.isPrimitive()) {
                        value = toPrimitiveArray(wrappedArray, arrayType);
                    }

                    status.setConverted(value);
                }

                //try implicit converters (e.g. String Constructors)
                if (!status.isConverterFound()) {
                    status = implicitConverters(rawString, requestedClazz);
                }

                //try to find any compatible converters
                if (!status.isConverterFound()) {
                    status = convertCompatible(rawString, requestedClazz);
                }

            }

            if (!status.isConverterFound()) {
                throw new IllegalArgumentException(Tr.formatMessage(tc, "could.not.find.converter.CWMCG0014E", type.getTypeName()));
            }

            converted = status.getConverted();
        }
        return converted;

    }
1069328
private boolean isaConversionClass(JavaClass conversionCls) {
        for (AnnotationEntry entry : conversionCls.getAnnotationEntries()) {
            if (CONVERSION_ANNOTATIONS.contains(entry.getAnnotationType())) {
                return true;
            }

            // this ignores the fact that this class might be a grand child, but meh
            if (CONVERSION_SUPER_CLASSES.contains(conversionCls.getSuperclassName())) {
                return true;
            }
        }

        return false;
    }
394682
public <T> T convert(ConversionContext context, Object source,
			TypeReference<T> destinationType) throws ConverterException {
		try {
			return (T) multiConverter.convert(context, source, destinationType);
		} catch (ConverterException e) {
			throw e;
		} catch (Exception e) {
			// There is a problem with one converter. This should not happen.
			// Either there is a bug in this converter or it is not properly
			// configured
			throw new ConverterException(
					MessageFormat
							.format(
									"Could not convert given object with class ''{0}'' to object with type signature ''{1}''",
									source == null ? "null" : source.getClass()
											.getName(), destinationType), e);
		}
	}
1279783
public static <C> C getInstanceOf( Object argument,
                                       Class<C> expectedClass,
                                       String name ) {
        isInstanceOf(argument, expectedClass, name);
        return expectedClass.cast(argument);
    }
380722
@Override
    public StringConverter<?> findConverter(Class<?> cls) {
        if (cls == Byte[].class) {
            return ByteArrayStringConverter.INSTANCE;
        }
        return null;
    }
6323
public static StringValueConverterImpl getInstance() {

    if (instance == null) {
      synchronized (StringValueConverterImpl.class) {
        if (instance == null) {
          StringValueConverterImpl converter = new StringValueConverterImpl();
          converter.initialize();
          instance = converter;
        }
      }
    }
    return instance;
  }
474345
static <T> Pair<Boolean, T> constructViaMethod(Class<T> type, String fromValue) {

		// Try to usse fromString before valueOf (enums have valueOf already defined) - in case we override fromString()
		List<Method> methods = getMethods(type, "fromString", "valueOf");

		if (methods != null && methods.size() > 0) {

			for (Method method : methods) {

				try {
					Object value = method.invoke(null, fromValue);
					return new Pair(true, value);
				}
				catch (IllegalAccessException | InvocationTargetException e) {
					// failed with this one ... try the others ...
					log.warn("Failed invoking static method: " + method.getName());
				}
			}
		}

		return new Pair<>(false, null);
	}
120854
@SuppressWarnings("unchecked")
    static <T> T stringToType(String str, Class<T> clazz) {
        try {
            final Function<String, ?> func = supportedElementTypes.get(clazz);
            if (func != null) {
                return (T) func.apply(str);
            }
        } catch (NumberFormatException e) {
            throw e;
        } catch (Throwable cause) {
            throw new IllegalArgumentException(
                    "Can't convert '" + str + "' to type '" + clazz.getSimpleName() + "'.", cause);
        }

        throw new IllegalArgumentException(
                "Can't convert '" + str + "' to type '" + clazz.getSimpleName() + "'.");
    }
151209
private static <T> StringConverter<T> defaultStringConverter() {
        return new StringConverter<T>() {
            @Override
            public String toString(T t) {
                return t == null ? null : t.toString();
            }

            @Override
            public T fromString(String string) {
                return (T) string;
            }
        };
    }