Search in sources :

Example 1 with PresentationModelInfo

use of org.robobinding.codegen.presentationmodel.PresentationModelInfo 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 PresentationModelInfo

use of org.robobinding.codegen.presentationmodel.PresentationModelInfo in project RoboBinding by RoboBinding.

the class PresentationModelTest method whenProcessPresentationModel_thenGetExpectedResult.

@Test
public void whenProcessPresentationModel_thenGetExpectedResult() {
    PresentationModelInfo result = processJavaFileOf(SelfDescribedPresentationModel.class);
    assertThat(result.properties().size(), is(SelfDescribedPresentationModel.numProperties));
    assertThat(result.dataSetProperties().size(), is(SelfDescribedPresentationModel.numDataSetProperties));
    assertThat(result.eventMethods().size(), is(SelfDescribedPresentationModel.numEventMethods));
}
Also used : PresentationModelInfo(org.robobinding.codegen.presentationmodel.PresentationModelInfo) Test(org.junit.Test)

Example 3 with PresentationModelInfo

use of org.robobinding.codegen.presentationmodel.PresentationModelInfo in project RoboBinding by RoboBinding.

the class PresentationModelTest method shouldGetPresentationModelChangeSupportMethodIgnored.

@Test
public void shouldGetPresentationModelChangeSupportMethodIgnored() {
    PresentationModelInfo result = processJavaFileOf(GetPresentationModelChangeSupportIgnored.class);
    assertThat(result.properties().size(), is(0));
}
Also used : PresentationModelInfo(org.robobinding.codegen.presentationmodel.PresentationModelInfo) Test(org.junit.Test)

Example 4 with PresentationModelInfo

use of org.robobinding.codegen.presentationmodel.PresentationModelInfo in project RoboBinding by RoboBinding.

the class PresentationModelTest method shouldHierarchicalPresentationModelRecognized.

@Test
public void shouldHierarchicalPresentationModelRecognized() {
    PresentationModelInfo result = processJavaFileOf(HierarchicalPresentationModel.class);
    assertThat(result.properties().size(), is(HierarchicalPresentationModel.numProperties));
    assertThat(result.eventMethods().size(), is(HierarchicalPresentationModel.numEventMethods));
}
Also used : PresentationModelInfo(org.robobinding.codegen.presentationmodel.PresentationModelInfo) Test(org.junit.Test)

Example 5 with PresentationModelInfo

use of org.robobinding.codegen.presentationmodel.PresentationModelInfo in project RoboBinding by RoboBinding.

the class PresentationModelProcessor 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(PresentationModel.class, new PresentationModelFilter());
    for (WrappedTypeElement typeElement : typeElements) {
        String presentationModelObjectTypeName = PresentationModelObjectLoader.getObjectClassName(typeElement.binaryName());
        PresentationModelInfoBuilder builder = new PresentationModelInfoBuilder(typeElement, presentationModelObjectTypeName, true);
        PresentationModelInfo presentationModelInfo = builder.build();
        Logger log = typeElement.logger();
        ProcessingContext context = new ProcessingContext(processingEnv.getTypeUtils(), processingEnv.getElementUtils(), processingEnv.getMessager());
        try {
            if (isItemPresentationModelAlso(typeElement)) {
                createItemPresentationModelObjectSourceFiles(presentationModelInfo, context);
            } else {
                generateAllClasses(presentationModelInfo, context, 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 : ProcessingContext(org.robobinding.codegen.apt.ProcessingContext) WrappedTypeElement(org.robobinding.codegen.apt.element.WrappedTypeElement) IOException(java.io.IOException) Logger(org.robobinding.codegen.apt.Logger) RoundContext(org.robobinding.codegen.apt.RoundContext) JClassAlreadyExistsException(com.helger.jcodemodel.JClassAlreadyExistsException) PresentationModelInfo(org.robobinding.codegen.presentationmodel.PresentationModelInfo)

Aggregations

PresentationModelInfo (org.robobinding.codegen.presentationmodel.PresentationModelInfo)9 Test (org.junit.Test)7 Logger (org.robobinding.codegen.apt.Logger)2 WrappedTypeElement (org.robobinding.codegen.apt.element.WrappedTypeElement)2 JClassAlreadyExistsException (com.helger.jcodemodel.JClassAlreadyExistsException)1 IOException (java.io.IOException)1 ProcessingContext (org.robobinding.codegen.apt.ProcessingContext)1 RoundContext (org.robobinding.codegen.apt.RoundContext)1 DataSetPropertyInfo (org.robobinding.codegen.presentationmodel.DataSetPropertyInfo)1 ItemPresentationModelObjectClassGen (org.robobinding.codegen.presentationmodel.ItemPresentationModelObjectClassGen)1