Search in sources :

Example 1 with ModelLoader

use of io.joynr.generator.loading.ModelLoader in project joynr by bmwcarit.

the class AbstractTypeUtilTest method testMultipleOutParameters.

@Test
public void testMultipleOutParameters() throws Exception {
    URL fixtureURL = AbstractTypeUtilTest.class.getResource("MultipleOutParameters.fidl");
    ModelLoader loader = new ModelLoader(fixtureURL.getPath());
    Resource fixtureResource = loader.getResources().iterator().next();
    class MyCallsRealMethods extends CallsRealMethods {

        private static final long serialVersionUID = 1L;

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            if (invocation.getMethod().getName().equals("getTypeName")) {
                Class<?> parameterType0 = invocation.getMethod().getParameterTypes()[0];
                if (parameterType0.equals(FBasicTypeId.class)) {
                    return ((FBasicTypeId) invocation.getArguments()[0]).getName();
                } else if (parameterType0.equals(FType.class)) {
                    return ((FType) invocation.getArguments()[0]).getName();
                } else {
                    return super.answer(invocation);
                }
            } else {
                return super.answer(invocation);
            }
        }
    }
    AbstractTypeUtil typeUtil = mock(AbstractTypeUtil.class, new MyCallsRealMethods());
    Guice.createInjector().injectMembers(typeUtil);
    FModel model = (FModel) fixtureResource.getContents().get(0);
    String stringDatatype = FBasicTypeId.STRING.getName();
    String numberDatatype = FBasicTypeId.INT16.getName();
    String complexDatatype = model.getTypeCollections().get(0).getTypes().get(0).getName();
    FMethod fixture = model.getInterfaces().get(0).getMethods().get(0);
    Iterator<String> result = typeUtil.getTypeNamesForOutputParameter(fixture).iterator();
    assertEquals(result.next(), stringDatatype);
    assertEquals(result.next(), numberDatatype);
    assertEquals(result.next(), complexDatatype);
    assertFalse(result.hasNext());
}
Also used : FType(org.franca.core.franca.FType) FModel(org.franca.core.franca.FModel) Resource(org.eclipse.emf.ecore.resource.Resource) URL(java.net.URL) FBasicTypeId(org.franca.core.franca.FBasicTypeId) ModelLoader(io.joynr.generator.loading.ModelLoader) CallsRealMethods(org.mockito.internal.stubbing.answers.CallsRealMethods) InvocationOnMock(org.mockito.invocation.InvocationOnMock) FMethod(org.franca.core.franca.FMethod) Test(org.junit.Test)

Example 2 with ModelLoader

use of io.joynr.generator.loading.ModelLoader 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 3 with ModelLoader

use of io.joynr.generator.loading.ModelLoader in project joynr by bmwcarit.

the class CppStdTypeUtilTest method setUp.

@Override
protected void setUp() throws Exception {
    URL fixtureURL = CppStdTypeUtilTest.class.getResource("CppStdTypeUtil.fidl");
    ModelLoader loader = new ModelLoader(fixtureURL.getPath());
    Resource fixtureResource = loader.getResources().iterator().next();
    cppStdTypeUtil = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            bindConstant().annotatedWith(Names.named("generationId")).to("");
            bindConstant().annotatedWith(Names.named(JoynrGeneratorExtensions.JOYNR_GENERATOR_CLEAN)).to(false);
            bindConstant().annotatedWith(Names.named(JoynrGeneratorExtensions.JOYNR_GENERATOR_GENERATE)).to(true);
            install(new FactoryModuleBuilder().build(CppTemplateFactory.class));
        }
    }).getInstance(CppStdTypeUtil.class);
    model = (FModel) fixtureResource.getContents().get(0);
}
Also used : ModelLoader(io.joynr.generator.loading.ModelLoader) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) Resource(org.eclipse.emf.ecore.resource.Resource) URL(java.net.URL) AbstractModule(com.google.inject.AbstractModule)

Example 4 with ModelLoader

use of io.joynr.generator.loading.ModelLoader in project joynr by bmwcarit.

the class Executor method generate.

public void generate() {
    ModelLoader modelLoader = prepareGeneratorEnvironment();
    for (Resource resource : modelLoader.getResources()) {
        if (resource.getErrors().size() > 0) {
            StringBuilder errorMsg = new StringBuilder();
            errorMsg.append("Error loading model " + resource.getURI().toString() + ". The following errors occured: \n");
            for (Diagnostic error : resource.getErrors()) {
                errorMsg.append(error.getMessage());
            }
            logger.log(Level.SEVERE, errorMsg.toString());
            System.exit(-1);
        } else {
            generator.doGenerate(resource, outputFileSystem);
        }
    }
}
Also used : ModelLoader(io.joynr.generator.loading.ModelLoader) Resource(org.eclipse.emf.ecore.resource.Resource) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic)

Example 5 with ModelLoader

use of io.joynr.generator.loading.ModelLoader in project joynr by bmwcarit.

the class SupportedFrancaFeatureCheckerTest method testIntegerTypeIsUsed_ExceptionIsThrown.

@Test
public void testIntegerTypeIsUsed_ExceptionIsThrown() {
    URL fixtureURL = SupportedFrancaFeatureCheckerTest.class.getResource("IntegerTypeUsed.fidl");
    ModelLoader loader = new ModelLoader(fixtureURL.getPath());
    Resource fixtureResource = loader.getResources().iterator().next();
    FModel model = (FModel) fixtureResource.getContents().get(0);
    try {
        SupportedFrancaFeatureChecker.checkModel(model);
        fail("This line should not be reached, as an exception is expected when invoking checkModel");
    } catch (Exception e) {
        assertTrue(e.getMessage().contains("not supported"));
    }
}
Also used : ModelLoader(io.joynr.generator.loading.ModelLoader) FModel(org.franca.core.franca.FModel) Resource(org.eclipse.emf.ecore.resource.Resource) URL(java.net.URL) Test(org.junit.Test)

Aggregations

ModelLoader (io.joynr.generator.loading.ModelLoader)6 Resource (org.eclipse.emf.ecore.resource.Resource)6 URL (java.net.URL)4 FModel (org.franca.core.franca.FModel)4 Test (org.junit.Test)3 FType (org.franca.core.franca.FType)2 AbstractModule (com.google.inject.AbstractModule)1 FactoryModuleBuilder (com.google.inject.assistedinject.FactoryModuleBuilder)1 Diagnostic (org.eclipse.emf.ecore.resource.Resource.Diagnostic)1 FBasicTypeId (org.franca.core.franca.FBasicTypeId)1 FBroadcast (org.franca.core.franca.FBroadcast)1 FCompoundType (org.franca.core.franca.FCompoundType)1 FMethod (org.franca.core.franca.FMethod)1 FTypeCollection (org.franca.core.franca.FTypeCollection)1 CallsRealMethods (org.mockito.internal.stubbing.answers.CallsRealMethods)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1