Search in sources :

Example 1 with Bug

use of org.robobinding.Bug in project RoboBinding by RoboBinding.

the class PresentationModelObjectLoader method load.

public AbstractPresentationModelObject load(Object presentationModel) {
    if (presentationModel instanceof HasPresentationModelChangeSupport) {
        Preconditions.checkNotNull(((HasPresentationModelChangeSupport) presentationModel).getPresentationModelChangeSupport(), "The PresentationModelChangeSupport from presentationModel.getPresentationModelChangeSupport() must not be null");
    }
    String presentationModelObjectClassName = getObjectClassName(presentationModel.getClass().getName());
    Class<?> presentationModelObjectType;
    try {
        presentationModelObjectType = Class.forName(presentationModelObjectClassName);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(MessageFormat.format("The source code for ''{0}'' is not generated. Is Java annotation processing(source code generation) correctly configured?", presentationModelObjectClassName));
    }
    try {
        return (AbstractPresentationModelObject) ConstructorUtils.invokeConstructor(presentationModelObjectType, presentationModel);
    } catch (NoSuchMethodException e) {
        throw new Bug("This is a bug of constructor code generation", e);
    } catch (IllegalAccessException e) {
        throw new Bug("This is a bug of constructor code generation", e);
    } catch (InvocationTargetException e) {
        throw new Bug("This is a bug of constructor code generation", e);
    } catch (InstantiationException e) {
        throw new Bug("This is a bug of constructor code generation", e);
    }
}
Also used : Bug(org.robobinding.Bug) AbstractPresentationModelObject(org.robobinding.presentationmodel.AbstractPresentationModelObject) HasPresentationModelChangeSupport(org.robobinding.presentationmodel.HasPresentationModelChangeSupport) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with Bug

use of org.robobinding.Bug in project RoboBinding by RoboBinding.

the class ViewBindingLoader method load.

@SuppressWarnings("unchecked")
public <ViewType> ViewBinding<ViewType> load(CustomViewBinding<ViewType> customViewBinding) {
    String viewBindingClassName = getViewBindingClassName(customViewBinding.getClass().getName());
    Class<?> viewBindingType;
    try {
        viewBindingType = Class.forName(viewBindingClassName);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(MessageFormat.format("The source code for ''{0}'' is not generated. Is Java annotation processing(source code generation) correctly configured?", viewBindingClassName));
    }
    try {
        return (ViewBinding<ViewType>) ConstructorUtils.invokeConstructor(viewBindingType, customViewBinding);
    } catch (NoSuchMethodException e) {
        throw new Bug("This is a bug of constructor code generation", e);
    } catch (IllegalAccessException e) {
        throw new Bug("This is a bug of constructor code generation", e);
    } catch (InvocationTargetException e) {
        throw new Bug("This is a bug of constructor code generation", e);
    } catch (InstantiationException e) {
        throw new Bug("This is a bug of constructor code generation", e);
    }
}
Also used : ViewBinding(org.robobinding.viewbinding.ViewBinding) Bug(org.robobinding.Bug) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with Bug

use of org.robobinding.Bug in project RoboBinding by RoboBinding.

the class LazyFunctions method find.

@Override
public Function find(String functionName, Class<?>... parameterTypes) {
    Method method = MethodUtils.getMatchingAccessibleMethod(beanClass, functionName, parameterTypes);
    if (method == null) {
        return null;
    }
    MethodDescriptor methodDescriptor = new MethodDescriptor(method.getName(), method.getParameterTypes());
    if (!functions.containsKey(methodDescriptor)) {
        throw new RuntimeException("No such method '" + new MethodDescription(beanClass, method) + "'");
    }
    Function function = functions.get(methodDescriptor);
    if (function == null) {
        function = supply.tryToCreateFunction(methodDescriptor);
        if (function == null) {
            throw new Bug(MessageFormat.format("The method '{0}' is not generated", new MethodDescription(beanClass, method)));
        }
        functions.put(methodDescriptor, function);
    }
    return function;
}
Also used : Bug(org.robobinding.Bug) Method(java.lang.reflect.Method)

Aggregations

Bug (org.robobinding.Bug)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)1 AbstractPresentationModelObject (org.robobinding.presentationmodel.AbstractPresentationModelObject)1 HasPresentationModelChangeSupport (org.robobinding.presentationmodel.HasPresentationModelChangeSupport)1 ViewBinding (org.robobinding.viewbinding.ViewBinding)1