All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cucumber.runtime.xstream.DynamicClassWithStringAssignableConverter Maven / Gradle / Ivy

There is a newer version: 1.2.6
Show newest version
package cucumber.runtime.xstream;

import cucumber.deps.com.thoughtworks.xstream.converters.SingleValueConverterWrapper;

import java.lang.reflect.Constructor;

class DynamicClassWithStringAssignableConverter extends DynamicClassBasedSingleValueConverter {

    @Override
    public SingleValueConverterWrapper converterForClass(Class type) {
        final Constructor assignableConstructor = findAssignableConstructor(type);
        return new SingleValueConverterWrapperExt(new ClassWithStringAssignableConstructorConverter(assignableConstructor));
    }

    @Override
    public boolean canConvert(Class type) {
        return null != findAssignableConstructor(type);
    }

    private static Constructor findAssignableConstructor(Class type) {
        for (Constructor constructor : type.getConstructors()) {
            if (constructor.getParameterTypes().length == 1 && constructor.getParameterTypes()[0].isAssignableFrom(String.class)) {
                return constructor;
            }
        }
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy