Search in sources :

Example 1 with FTypeCollection

use of org.franca.core.franca.FTypeCollection in project joynr by bmwcarit.

the class JoynrJavaGeneratorExtensionsTest method testIncludesOfFixture.

private void testIncludesOfFixture(boolean shallIncludeTopLevel, boolean shallIncludeSecondLevel, String model) {
    // this test shall check for correct import statements (avoiding
    // warnings) in case of hierachical structs
    ModelLoader modelLoader = new ModelLoader(model);
    Iterator<Resource> modelResourcesIterator = modelLoader.getResources().iterator();
    Resource input = modelResourcesIterator.next();
    assertFalse(modelResourcesIterator.hasNext());
    FModel fModel = (FModel) input.getContents().get(0);
    EList<FTypeCollection> typeCollections = fModel.getTypeCollections();
    assertEquals(1, typeCollections.size());
    boolean typeFound = false;
    for (FType type : typeCollections.get(0).getTypes()) {
        if (type.getName().equals(FIXTURE_TYPE_NAME)) {
            if (type instanceof FCompoundType) {
                typeFound = true;
                Iterable<String> result = fixture.getRequiredIncludesFor((FCompoundType) type);
                boolean topLevelStructAsInclude = false;
                boolean secondLevelStructAsInclude = false;
                for (String include : result) {
                    if (include.equals(TOP_LEVEL_STRUCT_INCLUDE)) {
                        topLevelStructAsInclude = true;
                    } else if (include.equals(SECOND_LEVEL_STRUCT_TYPE_NAME)) {
                        secondLevelStructAsInclude = true;
                    }
                }
                assertEquals(TOP_LEVEL_STRUCT_INCLUDE + " shall NOT be part of includes", shallIncludeTopLevel, topLevelStructAsInclude);
                assertEquals(SECOND_LEVEL_STRUCT_TYPE_NAME + " shall be part of includes", shallIncludeSecondLevel, secondLevelStructAsInclude);
            }
        }
    }
    assertTrue(typeFound);
}
Also used : FCompoundType(org.franca.core.franca.FCompoundType) ModelLoader(io.joynr.generator.loading.ModelLoader) FType(org.franca.core.franca.FType) FTypeCollection(org.franca.core.franca.FTypeCollection) FModel(org.franca.core.franca.FModel) Resource(org.eclipse.emf.ecore.resource.Resource)

Example 2 with FTypeCollection

use of org.franca.core.franca.FTypeCollection in project joynr by bmwcarit.

the class CompoundTypeGeneratorTest method testRecursiveStruct.

@Test
public void testRecursiveStruct() throws Exception {
    FModel model = FrancaFactory.eINSTANCE.createFModel();
    FStructType structType = FrancaFactory.eINSTANCE.createFStructType();
    FTypeCollection typeCollection = FrancaFactory.eINSTANCE.createFTypeCollection();
    typeCollection.getTypes().add(structType);
    model.getTypeCollections().add(typeCollection);
    structType.setName("TestStruct");
    FField field = FrancaFactory.eINSTANCE.createFField();
    field.setName("exampleField");
    field.setArray(true);
    FTypeRef typeRef = FrancaFactory.eINSTANCE.createFTypeRef();
    typeRef.setDerived(structType);
    field.setType(typeRef);
    structType.getElements().add(field);
    JsTemplateFactory templateFactory = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            install(new FactoryModuleBuilder().build(JsTemplateFactory.class));
            bind(Boolean.class).annotatedWith(Names.named(JoynrGeneratorExtensions.JOYNR_GENERATOR_GENERATE)).toInstance(true);
            bind(Boolean.class).annotatedWith(Names.named(JoynrGeneratorExtensions.JOYNR_GENERATOR_CLEAN)).toInstance(false);
        }
    }).getInstance(JsTemplateFactory.class);
    CompoundTypeGenerator generator = templateFactory.createCompoundTypeGenerator(structType);
    generator.generate();
}
Also used : FStructType(org.franca.core.franca.FStructType) FTypeRef(org.franca.core.franca.FTypeRef) FTypeCollection(org.franca.core.franca.FTypeCollection) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) FModel(org.franca.core.franca.FModel) JsTemplateFactory(io.joynr.generator.js.util.JsTemplateFactory) FField(org.franca.core.franca.FField) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Aggregations

FModel (org.franca.core.franca.FModel)2 FTypeCollection (org.franca.core.franca.FTypeCollection)2 AbstractModule (com.google.inject.AbstractModule)1 FactoryModuleBuilder (com.google.inject.assistedinject.FactoryModuleBuilder)1 JsTemplateFactory (io.joynr.generator.js.util.JsTemplateFactory)1 ModelLoader (io.joynr.generator.loading.ModelLoader)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 FCompoundType (org.franca.core.franca.FCompoundType)1 FField (org.franca.core.franca.FField)1 FStructType (org.franca.core.franca.FStructType)1 FType (org.franca.core.franca.FType)1 FTypeRef (org.franca.core.franca.FTypeRef)1 Test (org.junit.Test)1