Search in sources :

Example 1 with WrappedTypeElement

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

the class PresentationModelProcessor method createItemPresentationModelObjectSourceFiles.

private void createItemPresentationModelObjectSourceFiles(PresentationModelInfo presentationModelInfo, ProcessingContext context) throws JClassAlreadyExistsException, IOException {
    for (DataSetPropertyInfo info : presentationModelInfo.dataSetProperties()) {
        if (processedItemPresentationModels.contains(info.itemPresentationModelTypeName())) {
            continue;
        }
        WrappedTypeElement typeElement = context.typeElementOf(info.itemPresentationModelTypeName());
        PresentationModelInfoBuilder builder = new PresentationModelInfoBuilder(typeElement, info.itemPresentationModelObjectTypeName(), true);
        PresentationModelInfo itemPresentationModelInfo = builder.build();
        Logger log = typeElement.logger();
        try {
            ItemPresentationModelObjectClassGen gen = new ItemPresentationModelObjectClassGen(itemPresentationModelInfo);
            run(gen);
            gen.writeTo(createOutput());
            log.info("ItemPresentationModel '" + itemPresentationModelInfo.getPresentationModelObjectTypeName() + "' generated.");
        } catch (java.lang.NoClassDefFoundError e) {
            RuntimeException error = new RuntimeException("an error occured when generating source code for '" + presentationModelInfo.getPresentationModelObjectTypeName() + "'", e);
            log.error(error);
            throw error;
        }
        processedItemPresentationModels.add(info.itemPresentationModelTypeName());
    }
}
Also used : PresentationModelInfo(org.robobinding.codegen.presentationmodel.PresentationModelInfo) DataSetPropertyInfo(org.robobinding.codegen.presentationmodel.DataSetPropertyInfo) WrappedTypeElement(org.robobinding.codegen.apt.element.WrappedTypeElement) ItemPresentationModelObjectClassGen(org.robobinding.codegen.presentationmodel.ItemPresentationModelObjectClassGen) Logger(org.robobinding.codegen.apt.Logger)

Example 2 with WrappedTypeElement

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

the class ViewBindingInfoBuilder method build.

public ViewBindingInfo build() {
    WrappedTypeElement viewType = extractViewType();
    List<SimpleOneWayPropertyInfo> simpleOneWayPropertyInfoList = extractSimpleOneWayPropertyInfoList(viewType);
    return new ViewBindingInfo(typeElement.qName(), viewBindingObjectTypeName, viewType, simpleOneWayPropertyInfoList);
}
Also used : WrappedTypeElement(org.robobinding.codegen.apt.element.WrappedTypeElement)

Example 3 with WrappedTypeElement

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

the class ViewBindingProcessor method process.

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    RoundContext roundContext = new RoundContext(roundEnv, processingEnv.getTypeUtils(), processingEnv.getElementUtils(), processingEnv.getMessager());
    Set<WrappedTypeElement> typeElements = roundContext.typeElementsAnnotatedWith(ViewBinding.class, new ViewBindingFilter());
    for (WrappedTypeElement typeElement : typeElements) {
        String viewBindingObjectTypeName = ViewBindingLoader.getViewBindingClassName(typeElement.binaryName());
        ViewBindingInfoBuilder builder = new ViewBindingInfoBuilder(typeElement, viewBindingObjectTypeName);
        ViewBindingInfo info = builder.build();
        Logger log = typeElement.logger();
        try {
            generateViewBindingObjectSourceFile(info, log);
        } catch (IOException e) {
            log.error(e);
            throw new RuntimeException(e);
        } catch (JClassAlreadyExistsException e) {
            log.error(e);
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            log.error(e);
            throw new RuntimeException(e);
        }
    }
    return true;
}
Also used : JClassAlreadyExistsException(com.helger.jcodemodel.JClassAlreadyExistsException) WrappedTypeElement(org.robobinding.codegen.apt.element.WrappedTypeElement) IOException(java.io.IOException) Logger(org.robobinding.codegen.apt.Logger) RoundContext(org.robobinding.codegen.apt.RoundContext)

Example 4 with WrappedTypeElement

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

the class ViewBindingInfoBuilderTest method givenValidImageViewBinding_whenBuildViewBindingInfo_thenReturnExpectedResult.

@Test
public void givenValidImageViewBinding_whenBuildViewBindingInfo_thenReturnExpectedResult() {
    WrappedTypeElement typeElement = typeElementOf(ViewBindingWithVariousProperties.class);
    ViewBindingInfoBuilder builder = new ViewBindingInfoBuilder(typeElement, viewBindingObjectTypeName);
    ViewBindingInfo viewBindingInfo = builder.build();
    ViewBindingInfo expectedViewBindingInfo = new ViewBindingInfo(ViewBindingWithVariousProperties.class.getName(), viewBindingObjectTypeName, typeElementOf(ViewWithProperties.class), Lists.newArrayList(new SimpleOneWayPropertyInfo(looseSetterOf(ViewWithProperties.PRIMITIVE_PROP)), new SimpleOneWayPropertyInfo(looseSetterOf(ViewWithProperties.OBJECT_PROP))));
    Assert.assertThat(viewBindingInfo, equalTo(expectedViewBindingInfo));
}
Also used : WrappedTypeElement(org.robobinding.codegen.apt.element.WrappedTypeElement) Test(org.junit.Test)

Example 5 with WrappedTypeElement

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

the class ViewBindingInfoBuilderTest method givenInvalidViewBinding_whenBuildViewBindingInfo_thenThrowBindingPropertyCreationError.

@Theory
public void givenInvalidViewBinding_whenBuildViewBindingInfo_thenThrowBindingPropertyCreationError(@FromDataPoints("invalidViewBindings") Class<?> invalidViewBinding) {
    WrappedTypeElement typeElement = typeElementOf(invalidViewBinding);
    ViewBindingInfoBuilder builder = new ViewBindingInfoBuilder(typeElement, viewBindingObjectTypeName);
    thrownException.expect(OneWayBindingPropertyGenerationException.class);
    builder.build();
}
Also used : WrappedTypeElement(org.robobinding.codegen.apt.element.WrappedTypeElement) Theory(org.junit.experimental.theories.Theory)

Aggregations

WrappedTypeElement (org.robobinding.codegen.apt.element.WrappedTypeElement)10 Logger (org.robobinding.codegen.apt.Logger)3 JClassAlreadyExistsException (com.helger.jcodemodel.JClassAlreadyExistsException)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 RoundContext (org.robobinding.codegen.apt.RoundContext)2 AptTestHelper (org.robobinding.codegen.apt.element.AptTestHelper)2 DataSetPropertyInfo (org.robobinding.codegen.presentationmodel.DataSetPropertyInfo)2 PresentationModelInfo (org.robobinding.codegen.presentationmodel.PresentationModelInfo)2 PresentationModelInfoBuilder (org.robobinding.codegen.presentationmodel.processor.PresentationModelInfoBuilder)2 Theory (org.junit.experimental.theories.Theory)1 ProcessingContext (org.robobinding.codegen.apt.ProcessingContext)1 ItemPresentationModelObjectClassGen (org.robobinding.codegen.presentationmodel.ItemPresentationModelObjectClassGen)1