Search in sources :

Example 1 with FTypeRef

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

the class TypeUtilTest method testRecurstiveStruct.

@Test
public void testRecurstiveStruct() throws Exception {
    FStructType structType = FrancaFactory.eINSTANCE.createFStructType();
    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);
    TypeUtil typeUtil = Guice.createInjector().getInstance(TypeUtil.class);
    FCompoundType result = typeUtil.getCompoundType(structType);
    assertEquals(structType, result);
}
Also used : FCompoundType(org.franca.core.franca.FCompoundType) FStructType(org.franca.core.franca.FStructType) FTypeRef(org.franca.core.franca.FTypeRef) FField(org.franca.core.franca.FField) Test(org.junit.Test)

Example 2 with FTypeRef

use of org.franca.core.franca.FTypeRef 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

FField (org.franca.core.franca.FField)2 FStructType (org.franca.core.franca.FStructType)2 FTypeRef (org.franca.core.franca.FTypeRef)2 Test (org.junit.Test)2 AbstractModule (com.google.inject.AbstractModule)1 FactoryModuleBuilder (com.google.inject.assistedinject.FactoryModuleBuilder)1 JsTemplateFactory (io.joynr.generator.js.util.JsTemplateFactory)1 FCompoundType (org.franca.core.franca.FCompoundType)1 FModel (org.franca.core.franca.FModel)1 FTypeCollection (org.franca.core.franca.FTypeCollection)1