Search in sources :

Example 1 with ModuleGenerator

use of org.opendaylight.mdsal.binding.generator.impl.reactor.ModuleGenerator in project mdsal by opendaylight.

the class BindingRuntimeTypesFactory method indexModules.

private void indexModules(final Map<QNameModule, ModuleGenerator> moduleGens) {
    for (var entry : moduleGens.entrySet()) {
        final var modGen = entry.getValue();
        // index the module's runtime type
        safePut(modules, "modules", entry.getKey(), modGen.runtimeType().orElseThrow());
        // index module's identities and RPC input/outputs
        for (var gen : modGen) {
            if (gen instanceof IdentityGenerator) {
                ((IdentityGenerator) gen).runtimeType().ifPresent(identity -> {
                    safePut(identities, "identities", identity.statement().argument(), identity);
                });
            }
            // FIXME: do not collect these once we they generate a proper RuntimeType
            if (gen instanceof RpcGenerator) {
                final QName rpcName = ((RpcGenerator) gen).statement().argument();
                for (var subgen : gen) {
                    if (subgen instanceof RpcInputGenerator) {
                        ((RpcInputGenerator) subgen).runtimeType().ifPresent(input -> rpcInputs.put(rpcName, input));
                    } else if (subgen instanceof RpcOutputGenerator) {
                        ((RpcOutputGenerator) subgen).runtimeType().ifPresent(output -> rpcOutputs.put(rpcName, output));
                    }
                }
            }
        }
    }
    indexRuntimeTypes(moduleGens.values());
}
Also used : RpcOutputGenerator(org.opendaylight.mdsal.binding.generator.impl.reactor.RpcOutputGenerator) ModuleGenerator(org.opendaylight.mdsal.binding.generator.impl.reactor.ModuleGenerator) Stopwatch(com.google.common.base.Stopwatch) Mutable(org.opendaylight.yangtools.concepts.Mutable) TypeBuilderFactory(org.opendaylight.mdsal.binding.generator.impl.reactor.TypeBuilderFactory) BindingRuntimeTypes(org.opendaylight.mdsal.binding.runtime.api.BindingRuntimeTypes) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) GeneratorReactor(org.opendaylight.mdsal.binding.generator.impl.reactor.GeneratorReactor) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Verify.verify(com.google.common.base.Verify.verify) Map(java.util.Map) IdentityGenerator(org.opendaylight.mdsal.binding.generator.impl.reactor.IdentityGenerator) OutputRuntimeType(org.opendaylight.mdsal.binding.runtime.api.OutputRuntimeType) Generator(org.opendaylight.mdsal.binding.generator.impl.reactor.Generator) DefaultBindingRuntimeTypes(org.opendaylight.mdsal.binding.generator.impl.rt.DefaultBindingRuntimeTypes) IdentityRuntimeType(org.opendaylight.mdsal.binding.runtime.api.IdentityRuntimeType) RuntimeType(org.opendaylight.mdsal.binding.runtime.api.RuntimeType) Logger(org.slf4j.Logger) RpcInputGenerator(org.opendaylight.mdsal.binding.generator.impl.reactor.RpcInputGenerator) ModuleRuntimeType(org.opendaylight.mdsal.binding.runtime.api.ModuleRuntimeType) RpcGenerator(org.opendaylight.mdsal.binding.generator.impl.reactor.RpcGenerator) AbstractExplicitGenerator(org.opendaylight.mdsal.binding.generator.impl.reactor.AbstractExplicitGenerator) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) QName(org.opendaylight.yangtools.yang.common.QName) InputRuntimeType(org.opendaylight.mdsal.binding.runtime.api.InputRuntimeType) JavaTypeName(org.opendaylight.mdsal.binding.model.api.JavaTypeName) NonNull(org.eclipse.jdt.annotation.NonNull) GeneratedType(org.opendaylight.mdsal.binding.model.api.GeneratedType) RpcOutputGenerator(org.opendaylight.mdsal.binding.generator.impl.reactor.RpcOutputGenerator) RpcGenerator(org.opendaylight.mdsal.binding.generator.impl.reactor.RpcGenerator) QName(org.opendaylight.yangtools.yang.common.QName) IdentityGenerator(org.opendaylight.mdsal.binding.generator.impl.reactor.IdentityGenerator) RpcInputGenerator(org.opendaylight.mdsal.binding.generator.impl.reactor.RpcInputGenerator)

Example 2 with ModuleGenerator

use of org.opendaylight.mdsal.binding.generator.impl.reactor.ModuleGenerator in project mdsal by opendaylight.

the class DefaultBindingGenerator method generateFor.

/**
 * Resolves generated types from {@code context} schema nodes only for modules specified in {@code modules}.
 * Generated types are created for modules, groupings, types, containers, lists, choices, augments, rpcs,
 * notification, identities and actions.
 *
 * @param context schema context which contains data about all schema nodes saved in modules
 * @param modules set of modules for which schema nodes should be generated types
 * @return list of types (usually a {@link GeneratedType} or an {@link GeneratedTransferObject}), which:
 *         <ul>
 *           <li>are generated from {@code context} schema nodes and</li>
 *           <li>are also part of some of the module in {@code modules} set.</li>
 *         </ul>
 * @throws NullPointerException if any argument is {@code null}, or if {@code modules} contains a {@code null}
 *                              element
 */
@VisibleForTesting
@NonNull
static List<GeneratedType> generateFor(final EffectiveModelContext context, final Collection<? extends Module> modules) {
    final Set<ModuleEffectiveStatement> filter = modules.stream().map(Module::asEffectiveStatement).collect(Collectors.toUnmodifiableSet());
    final List<GeneratedType> result = new ArrayList<>();
    for (ModuleGenerator gen : new GeneratorReactor(context).execute(TypeBuilderFactory.codegen()).values()) {
        if (filter.contains(gen.statement())) {
            addTypes(result, gen);
        }
    }
    return result;
}
Also used : GeneratorReactor(org.opendaylight.mdsal.binding.generator.impl.reactor.GeneratorReactor) GeneratedType(org.opendaylight.mdsal.binding.model.api.GeneratedType) ArrayList(java.util.ArrayList) ModuleGenerator(org.opendaylight.mdsal.binding.generator.impl.reactor.ModuleGenerator) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NonNull(org.eclipse.jdt.annotation.NonNull)

Aggregations

NonNull (org.eclipse.jdt.annotation.NonNull)2 GeneratorReactor (org.opendaylight.mdsal.binding.generator.impl.reactor.GeneratorReactor)2 ModuleGenerator (org.opendaylight.mdsal.binding.generator.impl.reactor.ModuleGenerator)2 GeneratedType (org.opendaylight.mdsal.binding.model.api.GeneratedType)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Stopwatch (com.google.common.base.Stopwatch)1 Verify.verify (com.google.common.base.Verify.verify)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AbstractExplicitGenerator (org.opendaylight.mdsal.binding.generator.impl.reactor.AbstractExplicitGenerator)1 Generator (org.opendaylight.mdsal.binding.generator.impl.reactor.Generator)1 IdentityGenerator (org.opendaylight.mdsal.binding.generator.impl.reactor.IdentityGenerator)1 RpcGenerator (org.opendaylight.mdsal.binding.generator.impl.reactor.RpcGenerator)1 RpcInputGenerator (org.opendaylight.mdsal.binding.generator.impl.reactor.RpcInputGenerator)1 RpcOutputGenerator (org.opendaylight.mdsal.binding.generator.impl.reactor.RpcOutputGenerator)1 TypeBuilderFactory (org.opendaylight.mdsal.binding.generator.impl.reactor.TypeBuilderFactory)1 DefaultBindingRuntimeTypes (org.opendaylight.mdsal.binding.generator.impl.rt.DefaultBindingRuntimeTypes)1 JavaTypeName (org.opendaylight.mdsal.binding.model.api.JavaTypeName)1 BindingRuntimeTypes (org.opendaylight.mdsal.binding.runtime.api.BindingRuntimeTypes)1