/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @flow strict * @format */ 'use strict'; import type { FunctionTypeAnnotationParamTypeAnnotation, FunctionTypeAnnotationReturn, NativeModuleShape, TypeAliasTypeAnnotation, ObjectTypeAliasTypeShape, SchemaType, } from '../../CodegenSchema'; type FilesOutput = Map; const moduleTemplate = `/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the LICENSE file in the root * directory of this source tree. * * ${'@'}generated by codegen project: GenerateModuleJavaSpec.js * * @nolint */ package ::_PACKAGENAME_::; ::_IMPORTS_:: public abstract class ::_CLASSNAME_:: extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule { public ::_CLASSNAME_::(ReactApplicationContext reactContext) { super(reactContext); } ::_METHODS_:: } `; function getImportList(nativeModule: NativeModuleShape): Set { const imports: Set = new Set(); // Always required. imports.add('com.facebook.react.bridge.ReactApplicationContext'); imports.add('com.facebook.react.bridge.ReactContextBaseJavaModule'); imports.add('com.facebook.react.bridge.ReactMethod'); imports.add('com.facebook.react.bridge.ReactModuleWithSpec'); imports.add('com.facebook.react.turbomodule.core.interfaces.TurboModule'); return imports; } // TODO: complete this implementation module.exports = { generate( libraryName: string, schema: SchemaType, moduleSpecName: string, ): FilesOutput { const files = new Map(); // TODO: Allow package configuration. const packageName = 'com.facebook.fbreact.specs'; const nativeModules = Object.keys(schema.modules) .map(moduleName => { const modules = schema.modules[moduleName].nativeModules; if (modules == null) { return null; } return modules; }) .filter(Boolean) .reduce((acc, components) => Object.assign(acc, components), {}); Object.keys(nativeModules).forEach(name => { const {aliases, properties} = nativeModules[name]; const className = `Native${name}Spec`; const methods = properties.map(method => { const traversedArgs = method.typeAnnotation.params.map(param => {}); }); files.set( `${className}.java`, moduleTemplate .replace(/::_PACKAGENAME_::/g, packageName) .replace(/::_CLASSNAME_::/g, className), ); }); return files; }, };