@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); CompoundTypeGenerator generator = Guice.createInjector( new AbstractModule() { @Override protected void configure() { 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(CompoundTypeGenerator.class); generator.generateCompoundType(structType, Sets.newHashSet()); }
@Test public void test() { System.out.println("*** HppGeneratorTest"); // load example Franca IDL interface URI root = URI.createURI("classpath:/"); URI loc = URI.createFileURI("org/example/MediaPlayer.fidl"); FModel fmodel = loader.loadModel(loc, root); assertNotNull(fmodel); System.out.println("Franca IDL: package '" + fmodel.getName() + "'"); // generate code from first interface in Franca model assertTrue(fmodel.getInterfaces().size() > 0); FInterface api = fmodel.getInterfaces().get(0); ExampleHppGenerator generator = new ExampleHppGenerator(); String code = generator.generateInterface(api).toString(); System.out.println("Generated code:\n" + code); FileHelper.save("src-gen", getBasename(fmodel) + ".hpp", code); }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { ISelection selection = HandlerUtil.getCurrentSelection(event); if (selection != null && selection instanceof IStructuredSelection && !selection.isEmpty()) { IFile file = (IFile) ((IStructuredSelection) selection).getFirstElement(); URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true); URI rootURI = URI.createURI("classpath:/"); FModel model = loader.loadModel(uri, rootURI); if (model != null) { if (!validator.hasErrors(model.eResource())) { ResourceSet resourceSet = new ResourceSetImpl(); resourceSet .getResourceFactoryRegistry() .getExtensionToFactoryMap() .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl()); int extensionIndex = file.getFullPath().toString().lastIndexOf("." + file.getFileExtension()); String outputFilePath = file.getFullPath().toString().substring(0, extensionIndex) + ".xmi"; URI fileURI = URI.createPlatformResourceURI(outputFilePath, true); Resource resource = resourceSet.createResource(fileURI); resource.getContents().add(model); try { resource.save(Collections.EMPTY_MAP); file.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); } catch (IOException e) { e.printStackTrace(); } catch (CoreException e) { e.printStackTrace(); } } else { SpecificConsole console = new SpecificConsole("Franca"); console.getErr().println("Aborting XMI generation due to validation errors!"); } } } return null; }