Search in sources :

Example 1 with SetterElement

use of org.robobinding.codegen.apt.element.SetterElement in project RoboBinding by RoboBinding.

the class ViewBindingInfoBuilder method extractSimpleOneWayPropertyInfoList.

private List<SimpleOneWayPropertyInfo> extractSimpleOneWayPropertyInfoList(WrappedTypeElement viewType) {
    ViewBindingAnnotationMirror annotation = new ViewBindingAnnotationMirror(typeElement.getAnnotation(ViewBinding.class));
    List<String> simpleOneWayProperties = annotation.getSimpleOneWayProperties();
    SetterElements setters = new SetterElements(viewType.looseSetters(new SimpleOneWayPropertySetterFilter(simpleOneWayProperties)));
    if (setters.hasAmbiguousSetters()) {
        throw OneWayBindingPropertyGenerationException.setterWithDifferentParameterTypes(viewType, setters.getPropertiesWithAmbiguousSetters());
    }
    if (!setters.containsAll(simpleOneWayProperties)) {
        throw OneWayBindingPropertyGenerationException.noSettersFound(viewType, setters.findMissingProperties(simpleOneWayProperties));
    }
    List<SimpleOneWayPropertyInfo> result = Lists.newArrayList();
    for (SetterElement setter : setters) {
        result.add(new SimpleOneWayPropertyInfo(setter));
    }
    return result;
}
Also used : CustomViewBinding(org.robobinding.customviewbinding.CustomViewBinding) ViewBinding(org.robobinding.annotation.ViewBinding) SetterElement(org.robobinding.codegen.apt.element.SetterElement)

Example 2 with SetterElement

use of org.robobinding.codegen.apt.element.SetterElement in project RoboBinding by RoboBinding.

the class SimpleOneWayPropertyInfoTest method givenPrimitivePropertyType_thenReturnBoxedType.

@Test
public void givenPrimitivePropertyType_thenReturnBoxedType() {
    final SetterElement setter = context.mock(SetterElement.class);
    final WrappedPrimitiveType primitiveType = context.mock(WrappedPrimitiveType.class);
    context.checking(new Expectations() {

        {
            oneOf(setter).parameterType();
            will(returnValue(primitiveType));
            oneOf(primitiveType).isPrimitive();
            will(returnValue(true));
            oneOf(primitiveType).boxedClassName();
            will(returnValue(Integer.class.getName()));
        }
    });
    SimpleOneWayPropertyInfo info = new SimpleOneWayPropertyInfo(setter);
    assertThat(info.propertyType(), equalTo(Integer.class.getName()));
}
Also used : Expectations(org.jmock.Expectations) SetterElement(org.robobinding.codegen.apt.element.SetterElement) WrappedPrimitiveType(org.robobinding.codegen.apt.type.WrappedPrimitiveType) Test(org.junit.Test)

Example 3 with SetterElement

use of org.robobinding.codegen.apt.element.SetterElement in project RoboBinding by RoboBinding.

the class SimpleOneWayPropertyInfoTest method givenObjectPropertyType_thenReturnSameType.

@Test
public void givenObjectPropertyType_thenReturnSameType() {
    final SetterElement setter = context.mock(SetterElement.class);
    final WrappedDeclaredType declaredType = context.mock(WrappedDeclaredType.class);
    context.checking(new Expectations() {

        {
            oneOf(setter).parameterType();
            will(returnValue(declaredType));
            oneOf(declaredType).isPrimitive();
            will(returnValue(false));
            oneOf(declaredType).className();
            will(returnValue(Object.class.getName()));
        }
    });
    SimpleOneWayPropertyInfo info = new SimpleOneWayPropertyInfo(setter);
    assertThat(info.propertyType(), equalTo(Object.class.getName()));
}
Also used : Expectations(org.jmock.Expectations) SetterElement(org.robobinding.codegen.apt.element.SetterElement) WrappedDeclaredType(org.robobinding.codegen.apt.type.WrappedDeclaredType) Test(org.junit.Test)

Example 4 with SetterElement

use of org.robobinding.codegen.apt.element.SetterElement in project RoboBinding by RoboBinding.

the class SimpleOneWayPropertyInfoTest method shouldGetCorrectAttributeTypeName.

@Test
public void shouldGetCorrectAttributeTypeName() {
    final SetterElement setter = context.mock(SetterElement.class);
    context.checking(new Expectations() {

        {
            oneOf(setter).propertyName();
            will(returnValue("prop1"));
        }
    });
    SimpleOneWayPropertyInfo info = new SimpleOneWayPropertyInfo(setter);
    assertThat(info.bindingTypeName(), equalTo("Prop1Attribute"));
}
Also used : Expectations(org.jmock.Expectations) SetterElement(org.robobinding.codegen.apt.element.SetterElement) Test(org.junit.Test)

Aggregations

SetterElement (org.robobinding.codegen.apt.element.SetterElement)4 Expectations (org.jmock.Expectations)3 Test (org.junit.Test)3 ViewBinding (org.robobinding.annotation.ViewBinding)1 WrappedDeclaredType (org.robobinding.codegen.apt.type.WrappedDeclaredType)1 WrappedPrimitiveType (org.robobinding.codegen.apt.type.WrappedPrimitiveType)1 CustomViewBinding (org.robobinding.customviewbinding.CustomViewBinding)1