Search in sources :

Example 1 with ModuleEffectiveStatement

use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project mdsal by opendaylight.

the class ModuleInfoSnapshotResolver method updateSnapshot.

@Holding("this")
@NonNull
private ModuleInfoSnapshot updateSnapshot(final EffectiveModelContext effectiveModel) {
    // Alright, now let's find out which sources got captured
    final Set<SourceIdentifier> sources = new HashSet<>();
    for (Entry<QNameModule, ModuleEffectiveStatement> entry : effectiveModel.getModuleStatements().entrySet()) {
        final Optional<Revision> revision = entry.getKey().getRevision();
        final ModuleEffectiveStatement module = entry.getValue();
        sources.add(RevisionSourceIdentifier.create(module.argument().getLocalName(), revision));
        module.streamEffectiveSubstatements(SubmoduleEffectiveStatement.class).map(submodule -> RevisionSourceIdentifier.create(submodule.argument().getLocalName(), revision)).forEach(sources::add);
    }
    final Map<SourceIdentifier, YangModuleInfo> moduleInfos = new HashMap<>();
    final Map<String, ClassLoader> classLoaders = new HashMap<>();
    for (SourceIdentifier source : sources) {
        final List<RegisteredModuleInfo> regs = sourceToInfoReg.get(source);
        checkState(!regs.isEmpty(), "No registration for %s", source);
        final RegisteredModuleInfo reg = regs.get(0);
        final YangModuleInfo info = reg.info;
        moduleInfos.put(source, info);
        final Class<?> infoClass = info.getClass();
        classLoaders.put(BindingReflections.getModelRootPackageName(infoClass.getPackage()), infoClass.getClassLoader());
    }
    final ModuleInfoSnapshot next = new DefaultModuleInfoSnapshot(effectiveModel, moduleInfos, classLoaders);
    currentSnapshot = next;
    return next;
}
Also used : YangTextSchemaSource(org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource) ListMultimap(com.google.common.collect.ListMultimap) YangSyntaxErrorException(org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException) MultimapBuilder(com.google.common.collect.MultimapBuilder) Mutable(org.opendaylight.yangtools.concepts.Mutable) BindingReflections(org.opendaylight.mdsal.binding.spec.reflect.BindingReflections) LoggerFactory(org.slf4j.LoggerFactory) YangParserFactory(org.opendaylight.yangtools.yang.parser.api.YangParserFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) HashSet(java.util.HashSet) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) ImmutableList(com.google.common.collect.ImmutableList) Nullable(org.eclipse.jdt.annotation.Nullable) ObjectRegistration(org.opendaylight.yangtools.concepts.ObjectRegistration) Objects.requireNonNull(java.util.Objects.requireNonNull) Map(java.util.Map) YangTextSchemaContextResolver(org.opendaylight.yangtools.yang.parser.repo.YangTextSchemaContextResolver) LinkedHashSet(java.util.LinkedHashSet) ModuleInfoSnapshot(org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot) Logger(org.slf4j.Logger) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) MoreObjects(com.google.common.base.MoreObjects) Set(java.util.Set) IOException(java.io.IOException) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) SubmoduleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleEffectiveStatement) QName(org.opendaylight.yangtools.yang.common.QName) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Beta(com.google.common.annotations.Beta) YangModuleInfo(org.opendaylight.yangtools.yang.binding.YangModuleInfo) List(java.util.List) Holding(org.checkerframework.checker.lock.qual.Holding) AbstractObjectRegistration(org.opendaylight.yangtools.concepts.AbstractObjectRegistration) Revision(org.opendaylight.yangtools.yang.common.Revision) GuardedBy(org.checkerframework.checker.lock.qual.GuardedBy) RevisionSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier) Entry(java.util.Map.Entry) Optional(java.util.Optional) SchemaSourceException(org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException) Registration(org.opendaylight.yangtools.concepts.Registration) Builder(com.google.common.collect.ImmutableList.Builder) NonNull(org.eclipse.jdt.annotation.NonNull) ModuleInfoSnapshot(org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot) HashMap(java.util.HashMap) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) RevisionSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) YangModuleInfo(org.opendaylight.yangtools.yang.binding.YangModuleInfo) Revision(org.opendaylight.yangtools.yang.common.Revision) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Objects.requireNonNull(java.util.Objects.requireNonNull) NonNull(org.eclipse.jdt.annotation.NonNull) Holding(org.checkerframework.checker.lock.qual.Holding)

Example 2 with ModuleEffectiveStatement

use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement 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)

Example 3 with ModuleEffectiveStatement

use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project yangtools by opendaylight.

the class ModuleNameNamespaceContext method toBiMap.

/**
 * Convert this object to an equivalent {@link BiMapYangNamespaceContext}.
 *
 * @return A BiMapYangNamespaceContext.
 */
public BiMapYangNamespaceContext toBiMap() {
    final Builder<String, QNameModule> builder = ImmutableBiMap.builder();
    for (ModuleEffectiveStatement module : getEffectiveModelContext().getModuleStatements().values()) {
        final String name = module.argument().getLocalName();
        builder.put(name, findNamespaceForPrefix(name).get());
    }
    return new BiMapYangNamespaceContext(builder.build());
}
Also used : QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) BiMapYangNamespaceContext(org.opendaylight.yangtools.yang.common.BiMapYangNamespaceContext)

Example 4 with ModuleEffectiveStatement

use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project yangtools by opendaylight.

the class SchemaInferenceStack method pushFirstTypedef.

@NonNull
private TypedefEffectiveStatement pushFirstTypedef(@NonNull final QName nodeIdentifier) {
    final ModuleEffectiveStatement module = getModule(nodeIdentifier);
    final TypedefEffectiveStatement ret = pushTypedef(module, nodeIdentifier);
    currentModule = module;
    return ret;
}
Also used : TypedefEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.TypedefEffectiveStatement) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) NonNull(org.eclipse.jdt.annotation.NonNull) Objects.requireNonNull(java.util.Objects.requireNonNull)

Example 5 with ModuleEffectiveStatement

use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project yangtools by opendaylight.

the class SchemaInferenceStack method getModule.

@NonNull
private ModuleEffectiveStatement getModule(@NonNull final QName nodeIdentifier) {
    final ModuleEffectiveStatement module = effectiveModel.getModuleStatements().get(nodeIdentifier.getModule());
    checkArgument(module != null, "Module for %s not found", nodeIdentifier);
    return module;
}
Also used : ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) NonNull(org.eclipse.jdt.annotation.NonNull) Objects.requireNonNull(java.util.Objects.requireNonNull)

Aggregations

ModuleEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement)45 Test (org.junit.Test)28 GroupingEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement)20 ContainerEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement)12 NonNull (org.eclipse.jdt.annotation.NonNull)9 Objects.requireNonNull (java.util.Objects.requireNonNull)8 NotificationEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement)8 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)5 QName (org.opendaylight.yangtools.yang.common.QName)4 LeafEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement)4 LeafListEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.LeafListEffectiveStatement)4 SubmoduleEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleEffectiveStatement)4 ModuleStatement (org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement)3 ImmutableList (com.google.common.collect.ImmutableList)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Entry (java.util.Map.Entry)2 Revision (org.opendaylight.yangtools.yang.common.Revision)2 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)2 Module (org.opendaylight.yangtools.yang.model.api.Module)2