import com.google.common.annotations.Beta;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
/**
* Effective view of a {@link ModuleStatement}.
}
}
+ @Override
+ default StatementDefinition statementDefinition() {
+ return YangStmtMapping.MODULE;
+ }
+
/**
* Get the local QNameModule of this module. All implementations need to override this default method.
*
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
public interface ModuleStatement extends MetaDeclaredStatement<String>, ModuleHeaderGroup, LinkageDeclaredStatement,
RevisionAwareDeclaredStatement, BodyDeclaredStatement {
+ @Override
+ default StatementDefinition statementDefinition() {
+ return YangStmtMapping.MODULE;
+ }
+
default @NonNull String getName() {
// FIXME: YANGTOOLS-908: verifyNotNull() should not be needed here
return verifyNotNull(rawArgument());
package org.opendaylight.yangtools.yang.model.api.stmt;
import com.google.common.annotations.Beta;
+import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
/**
* Representation of {@code submodule} statement. Note that implementations of this interface are required to provide
*/
@Beta
public interface SubmoduleEffectiveStatement extends DataTreeAwareEffectiveStatement<String, SubmoduleStatement> {
-
+ @Override
+ default StatementDefinition statementDefinition() {
+ return YangStmtMapping.SUBMODULE;
+ }
}
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
public interface SubmoduleStatement extends MetaDeclaredStatement<String>, LinkageDeclaredStatement,
RevisionAwareDeclaredStatement, BodyDeclaredStatement {
+ @Override
+ default StatementDefinition statementDefinition() {
+ return YangStmtMapping.SUBMODULE;
+ }
+
default @NonNull String getName() {
// FIXME: YANGTOOLS-908: verifyNotNull() should not be needed here
return verifyNotNull(rawArgument());
--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.rfc7950.stmt;
+
+import com.google.common.annotations.Beta;
+import com.google.common.collect.ImmutableList;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.BodyDeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.LinkageDeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.MetaDeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.RevisionAwareDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredStatement.WithRawStringArgument.WithSubstatements;
+
+@Beta
+public abstract class AbstractDeclaredEffectiveRootStatement<D extends DeclaredStatement<String>>
+ extends WithSubstatements implements LinkageDeclaredStatement, MetaDeclaredStatement<String>,
+ RevisionAwareDeclaredStatement, BodyDeclaredStatement {
+ protected AbstractDeclaredEffectiveRootStatement(final String rawArgument,
+ final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+ super(rawArgument, substatements);
+ }
+}
this.substatements = maskList(substatements);
}
+ protected WithSubstatements(final String rawArgument,
+ final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+ super(rawArgument);
+ this.substatements = maskList(substatements);
+ }
+
@Override
public final Collection<? extends DeclaredStatement<?>> declaredSubstatements() {
return unmaskList(substatements);
import com.google.common.annotations.Beta;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Collections2;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.ImmutableSet;
import org.opendaylight.yangtools.yang.model.api.stmt.TypedefEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.YangVersionEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.compat.NotificationNodeContainerCompat;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredEffectiveStatement.DefaultWithDataTree.WithSubstatements;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.DocumentedNodeMixin;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToModuleCtx;
@Beta
public abstract class AbstractEffectiveModule<D extends DeclaredStatement<String>,
- E extends DataTreeAwareEffectiveStatement<String, D>>
- extends AbstractEffectiveDocumentedNodeWithStatus<String, D>
- implements Module, NotificationNodeContainerCompat<String, D, E> {
+ E extends DataTreeAwareEffectiveStatement<String, D>> extends WithSubstatements<String, D, E>
+ implements Module, DocumentedNodeMixin<String, D>, NotificationNodeContainerCompat<String, D, E> {
private final String prefix;
private final ImmutableSet<GroupingDefinition> groupings;
private final ImmutableSet<UsesNode> uses;
private final ImmutableSet<TypeDefinition<?>> typeDefinitions;
private final ImmutableMap<QName, SchemaTreeEffectiveStatement<?>> schemaTreeNamespace;
- protected AbstractEffectiveModule(
- final @NonNull StmtContext<String, D, ? extends EffectiveStatement<String, ?>> ctx,
- final @NonNull String prefix) {
- super(ctx);
+ protected AbstractEffectiveModule(final D declared,
+ final StmtContext<String, D, ? extends EffectiveStatement<String, ?>> ctx,
+ final ImmutableList<? extends EffectiveStatement<?, ?>> substatements, final String prefix) {
+ super(declared, ctx, substatements);
// This check is rather weird, but comes from our desire to lower memory footprint while providing both
// EffectiveStatements and SchemaNode interfaces -- which do not overlap completely where child lookups are
this.uses = ImmutableSet.copyOf(mutableUses);
}
+ @Override
+ public String argument() {
+ return getDeclared().argument();
+ }
+
@Override
public String getName() {
return argument();
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+@Deprecated(forRemoval = true)
public abstract class AbstractRootStatement<T extends DeclaredStatement<String>>
extends AbstractDeclaredStatement<String> implements LinkageDeclaredStatement, MetaDeclaredStatement<String>,
RevisionAwareDeclaredStatement, BodyDeclaredStatement {
public final E createEffective(final StmtContext<A, D, E> ctx) {
final D declared = ctx.buildDeclared();
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements =
- buildEffectiveSubstatements(statementsToBuild(ctx, declaredSubstatements(ctx)));
+ buildEffectiveSubstatements(ctx, statementsToBuild(ctx, declaredSubstatements(ctx)));
return substatements.isEmpty() ? createEmptyEffective(ctx, declared)
: createEffective(ctx, declared, substatements);
}
}
/**
- * Create a set of substatements. This method is split out so it can be overridden in
- * ExtensionEffectiveStatementImpl to leak a not-fully-initialized instance.
+ * Create a set of substatements. This method is split out so it can be overridden in subclasses adjust the
+ * resulting statements.
*
+ * @param ctx Parent statement context
* @param substatements proposed substatements
- * @return Filtered substatements
+ * @return Built effective substatements
*/
- private static ImmutableList<? extends EffectiveStatement<?, ?>> buildEffectiveSubstatements(
+ protected ImmutableList<? extends EffectiveStatement<?, ?>> buildEffectiveSubstatements(
+ final StmtContext<A, D, E> ctx, final List<? extends StmtContext<?, ?, ?>> substatements) {
+ return defaultBuildEffectiveSubstatements(substatements);
+ }
+
+ static final ImmutableList<? extends EffectiveStatement<?, ?>> buildEffectiveSubstatements(
+ final StmtContext<?, ?, ?> ctx) {
+ return defaultBuildEffectiveSubstatements(declaredSubstatements(ctx));
+ }
+
+ private static ImmutableList<? extends EffectiveStatement<?, ?>> defaultBuildEffectiveSubstatements(
final List<? extends StmtContext<?, ?, ?>> substatements) {
return substatements.stream()
.filter(StmtContext::isSupportedToBuildEffective)
.collect(ImmutableList.toImmutableList());
}
- static final ImmutableList<? extends EffectiveStatement<?, ?>> buildEffectiveSubstatements(
- final StmtContext<?, ?, ?> ctx) {
- return buildEffectiveSubstatements(declaredSubstatements(ctx));
- }
-
static final @NonNull List<StmtContext<?, ?, ?>> declaredSubstatements(final StmtContext<?, ?, ?> ctx) {
/*
* This dance is required to ensure that effects of 'uses' nodes are applied in the same order as
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.module;
+import static com.google.common.base.Verify.verify;
import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
+import com.google.common.collect.ImmutableList;
import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
import java.util.Optional;
import org.opendaylight.yangtools.concepts.SemVer;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
+import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.NamespaceStatement;
import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.SemVerSourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace;
import org.opendaylight.yangtools.yang.parser.spi.NamespaceToModule;
import org.opendaylight.yangtools.yang.parser.spi.PreLinkageModuleNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.SemanticVersionModuleNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.SemanticVersionNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToNamespace;
import org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToModuleCtx;
+import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToModuleCtx;
import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToSourceIdentifier;
import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
abstract class AbstractModuleStatementSupport
- extends AbstractStatementSupport<String, ModuleStatement, ModuleEffectiveStatement> {
+ extends BaseStatementSupport<String, ModuleStatement, ModuleEffectiveStatement> {
AbstractModuleStatementSupport() {
super(YangStmtMapping.MODULE);
}
return value;
}
- @Override
- public final ModuleStatement createDeclared(final StmtContext<String, ModuleStatement, ?> ctx) {
- return new ModuleStatementImpl(ctx);
- }
-
- @Override
- public final ModuleEffectiveStatement createEffective(
- final StmtContext<String, ModuleStatement, ModuleEffectiveStatement> ctx) {
- return new ModuleEffectiveStatementImpl(ctx);
- }
-
@Override
public final void onPreLinkageDeclared(final Mutable<String, ModuleStatement, ModuleEffectiveStatement> stmt) {
final String moduleName = stmt.getStatementArgument();
}
}
+ @Override
+ protected final ImmutableList<? extends EffectiveStatement<?, ?>> buildEffectiveSubstatements(
+ final StmtContext<String, ModuleStatement, ModuleEffectiveStatement> ctx,
+ final List<? extends StmtContext<?, ?, ?>> substatements) {
+ final ImmutableList<? extends EffectiveStatement<?, ?>> local =
+ super.buildEffectiveSubstatements(ctx, substatements);
+ final Collection<StmtContext<?, ?, ?>> submodules = submoduleContexts(ctx);
+ if (submodules.isEmpty()) {
+ return local;
+ }
+
+ // Concatenate statements so they appear as if they were part of target module
+ final List<EffectiveStatement<?, ?>> others = new ArrayList<>();
+ for (StmtContext<?, ?, ?> submoduleCtx : submodules) {
+ for (EffectiveStatement<?, ?> effective : submoduleCtx.buildEffective().effectiveSubstatements()) {
+ if (effective instanceof SchemaNode || effective instanceof DataNodeContainer) {
+ others.add(effective);
+ }
+ }
+ }
+
+ return ImmutableList.<EffectiveStatement<?, ?>>builderWithExpectedSize(local.size() + others.size())
+ .addAll(local)
+ .addAll(others)
+ .build();
+ }
+
+ @Override
+ protected final ModuleStatement createDeclared(final StmtContext<String, ModuleStatement, ?> ctx,
+ final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+ return new ModuleStatementImpl(ctx.coerceRawStatementArgument(), substatements);
+ }
+
+ @Override
+ protected final ModuleStatement createEmptyDeclared(final StmtContext<String, ModuleStatement, ?> ctx) {
+ throw noNamespace(ctx);
+ }
+
+ @Override
+ protected final ModuleEffectiveStatement createEffective(
+ final StmtContext<String, ModuleStatement, ModuleEffectiveStatement> ctx,
+ final ModuleStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+ final List<Module> submodules = new ArrayList<>();
+ for (StmtContext<?, ?, ?> submoduleCtx : submoduleContexts(ctx)) {
+ final EffectiveStatement<?, ?> submodule = submoduleCtx.buildEffective();
+ verify(submodule instanceof Module, "Submodule statement %s is not a Module", submodule);
+ submodules.add((Module) submodule);
+ }
+
+ return new ModuleEffectiveStatementImpl(ctx, declared, substatements, submodules);
+ }
+
+ @Override
+ protected final ModuleEffectiveStatement createEmptyEffective(
+ final StmtContext<String, ModuleStatement, ModuleEffectiveStatement> ctx, final ModuleStatement declared) {
+ throw noNamespace(ctx);
+ }
+
+ private static Collection<StmtContext<?, ?, ?>> submoduleContexts(final StmtContext<?, ?, ?> ctx) {
+ final Map<String, StmtContext<?, ?, ?>> submodules = ctx.getAllFromCurrentStmtCtxNamespace(
+ IncludedSubmoduleNameToModuleCtx.class);
+ return submodules == null ? List.of() : submodules.values();
+ }
+
+ private static SourceException noNamespace(final StmtContext<?, ?, ?> ctx) {
+ return new SourceException("No namespace declared in module", ctx.getStatementSourceReference());
+ }
+
private static void addToSemVerModuleNamespace(
final Mutable<String, ModuleStatement, ModuleEffectiveStatement> stmt,
final SourceIdentifier moduleIdentifier) {
import static com.google.common.base.Verify.verifyNotNull;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
-import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
+import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
import org.opendaylight.yangtools.yang.model.api.stmt.ExtensionEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ExtensionEffectiveStatementNamespace;
private final ImmutableMap<String, ModuleEffectiveStatement> prefixToModule;
private final ImmutableMap<QNameModule, String> namespaceToPrefix;
private final @NonNull QNameModule qnameModule;
- private final ImmutableSet<Module> submodules;
+ private final ImmutableList<Module> submodules;
- private ModuleEffectiveStatementImpl(final @NonNull ModuleStmtContext ctx) {
- super(ctx, findPrefix(ctx.delegate(), "module", ctx.getStatementArgument()));
- submodules = ctx.getSubmodules();
+ ModuleEffectiveStatementImpl(final StmtContext<String, ModuleStatement, ModuleEffectiveStatement> ctx,
+ final ModuleStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements,
+ final Collection<? extends Module> submodules) {
+ super(declared, ctx, substatements, findPrefix(ctx, "module", ctx.getStatementArgument()));
- qnameModule = verifyNotNull(ctx.getFromNamespace(ModuleCtxToModuleQName.class, ctx.delegate()));
+ qnameModule = verifyNotNull(ctx.getFromNamespace(ModuleCtxToModuleQName.class, ctx));
+ this.submodules = ImmutableList.copyOf(submodules);
final String localPrefix = findFirstEffectiveSubstatementArgument(PrefixEffectiveStatement.class).get();
final Builder<String, ModuleEffectiveStatement> prefixToModuleBuilder = ImmutableMap.builder();
: ImmutableMap.copyOf(Maps.transformValues(identities, StmtContext::buildEffective));
}
- ModuleEffectiveStatementImpl(final StmtContext<String, ModuleStatement, ModuleEffectiveStatement> ctx) {
- this(ModuleStmtContext.create(ctx));
- }
-
@Override
public @NonNull QNameModule localQNameModule() {
return qnameModule;
}
@Override
- public ImmutableSet<Module> getSubmodules() {
+ public Collection<? extends Module> getSubmodules() {
return submodules;
}
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.module;
+import com.google.common.collect.ImmutableList;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractRootStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredEffectiveRootStatement;
-final class ModuleStatementImpl extends AbstractRootStatement<ModuleStatement> implements ModuleStatement {
- ModuleStatementImpl(final StmtContext<String, ModuleStatement,?> context) {
- super(context);
+final class ModuleStatementImpl extends AbstractDeclaredEffectiveRootStatement<ModuleStatement>
+ implements ModuleStatement {
+ ModuleStatementImpl(final String rawArgument,
+ final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+ super(rawArgument, substatements);
}
}
+++ /dev/null
-/*
- * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.module;
-
-import static com.google.common.base.Verify.verify;
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.collect.ForwardingObject;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.yangtools.yang.common.YangVersion;
-import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
-import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
-import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.CopyHistory;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToModuleCtx;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
-
-/**
- * A concentrator {@link StmtContext}, which makes it appear as though as all effective statements in submodules
- * are included in it.
- */
-final class ModuleStmtContext extends ForwardingObject
- implements StmtContext<String, ModuleStatement, ModuleEffectiveStatement> {
-
- private final @NonNull StmtContext<String, ModuleStatement, ModuleEffectiveStatement> delegate;
- private final @NonNull ImmutableList<StmtContext<?, ?, ?>> effectiveSubstatements;
- private final @NonNull ImmutableSet<Module> submodules;
-
- private ModuleStmtContext(final StmtContext<String, ModuleStatement, ModuleEffectiveStatement> delegate,
- final Collection<StmtContext<?, ?, ?>> submodules) {
- this.delegate = requireNonNull(delegate);
-
- final List<StmtContext<?, ?, ?>> statements = new ArrayList<>(delegate.effectiveSubstatements());
- final Set<Module> subs = new LinkedHashSet<>(submodules.size());
- for (StmtContext<?, ?, ?> submoduleCtx : submodules) {
- final EffectiveStatement<?, ?> submodule = submoduleCtx.buildEffective();
- verify(submodule instanceof Module, "Submodule statement %s is not a Module", submodule);
- subs.add((Module) submodule);
-
- for (StmtContext<?, ?, ?> stmt : submoduleCtx.allSubstatements()) {
- if (stmt.isSupportedByFeatures()) {
- final EffectiveStatement<?, ?> effective = stmt.buildEffective();
- if (effective instanceof SchemaNode || effective instanceof DataNodeContainer) {
- statements.add(stmt);
- }
- }
- }
- }
-
- this.effectiveSubstatements = ImmutableList.copyOf(statements);
- this.submodules = ImmutableSet.copyOf(subs);
- }
-
- static @NonNull ModuleStmtContext create(
- final StmtContext<String, ModuleStatement, ModuleEffectiveStatement> delegate) {
- final Map<String, StmtContext<?, ?, ?>> includedSubmodules = delegate.getAllFromCurrentStmtCtxNamespace(
- IncludedSubmoduleNameToModuleCtx.class);
- return new ModuleStmtContext(delegate, includedSubmodules == null || includedSubmodules.isEmpty()
- ? ImmutableList.of() : includedSubmodules.values());
- }
-
- @Override
- protected @NonNull StmtContext<String, ModuleStatement, ModuleEffectiveStatement> delegate() {
- return delegate;
- }
-
- ImmutableSet<Module> getSubmodules() {
- return submodules;
- }
-
- @Override
- public ImmutableList<StmtContext<?, ?, ?>> effectiveSubstatements() {
- return effectiveSubstatements;
- }
-
- @Override
- public ModuleEffectiveStatement buildEffective() {
- throw new UnsupportedOperationException("Attempted to instantiate proxy context " + this);
- }
-
- @Override
- public ModuleStatement buildDeclared() {
- return delegate.buildDeclared();
- }
-
- @Override
- public StatementSource getStatementSource() {
- return delegate.getStatementSource();
- }
-
- @Override
- public StatementSourceReference getStatementSourceReference() {
- return delegate.getStatementSourceReference();
- }
-
- @Override
- public StatementDefinition getPublicDefinition() {
- return delegate.getPublicDefinition();
- }
-
- @Override
- public StmtContext<?, ?, ?> getParentContext() {
- return delegate.getParentContext();
- }
-
- @Override
- public String rawStatementArgument() {
- return delegate.rawStatementArgument();
- }
-
- @Override
- public @Nullable String getStatementArgument() {
- return delegate.getStatementArgument();
- }
-
- @Override
- public @NonNull Optional<SchemaPath> getSchemaPath() {
- return delegate.getSchemaPath();
- }
-
- @Override
- public boolean isConfiguration() {
- return delegate.isConfiguration();
- }
-
- @Override
- public boolean isEnabledSemanticVersioning() {
- return delegate.isEnabledSemanticVersioning();
- }
-
- @Override
- public <K, V, T extends K, N extends IdentifierNamespace<K, V>> V getFromNamespace(final Class<N> type,
- final T key) {
- return delegate.getFromNamespace(type, key);
- }
-
- @Override
- public <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromNamespace(final Class<N> type) {
- return delegate.getAllFromNamespace(type);
- }
-
- @Override
- public <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(
- final Class<N> type) {
- return delegate.getAllFromCurrentStmtCtxNamespace(type);
- }
-
- @Override
- public StmtContext<?, ?, ?> getRoot() {
- return delegate.getRoot();
- }
-
- @Override
- public Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements() {
- return delegate.declaredSubstatements();
- }
-
- @Override
- public boolean isSupportedToBuildEffective() {
- return delegate.isSupportedToBuildEffective();
- }
-
- @Override
- public boolean isSupportedByFeatures() {
- return delegate.isSupportedByFeatures();
- }
-
- @Override
- public Collection<? extends StmtContext<?, ?, ?>> getEffectOfStatement() {
- return delegate.getEffectOfStatement();
- }
-
- @Override
- public CopyHistory getCopyHistory() {
- return delegate.getCopyHistory();
- }
-
- @Override
- public Optional<StmtContext<String, ModuleStatement, ModuleEffectiveStatement>> getOriginalCtx() {
- return delegate.getOriginalCtx();
- }
-
- @Override
- public Optional<StmtContext<String, ModuleStatement, ModuleEffectiveStatement>> getPreviousCopyCtx() {
- return delegate.getPreviousCopyCtx();
- }
-
- @Override
- public ModelProcessingPhase getCompletedPhase() {
- return delegate.getCompletedPhase();
- }
-
- @Override
- public @NonNull YangVersion getRootVersion() {
- return delegate.getRootVersion();
- }
-}
import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.findFirstDeclaredSubstatement;
import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
+import com.google.common.collect.ImmutableList;
import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
abstract class AbstractSubmoduleStatementSupport
- extends AbstractStatementSupport<String, SubmoduleStatement, SubmoduleEffectiveStatement> {
+ extends BaseStatementSupport<String, SubmoduleStatement, SubmoduleEffectiveStatement> {
AbstractSubmoduleStatementSupport() {
super(YangStmtMapping.SUBMODULE);
}
return value;
}
- @Override
- public final SubmoduleStatement createDeclared(final StmtContext<String, SubmoduleStatement, ?> ctx) {
- return new SubmoduleStatementImpl(ctx);
- }
-
- @Override
- public final SubmoduleEffectiveStatement createEffective(
- final StmtContext<String, SubmoduleStatement, SubmoduleEffectiveStatement> ctx) {
- return new SubmoduleEffectiveStatementImpl(ctx);
- }
-
@Override
public final void onPreLinkageDeclared(
final Mutable<String, SubmoduleStatement, SubmoduleEffectiveStatement> stmt) {
stmt.addToNs(BelongsToPrefixToModuleName.class, prefix, belongsToModuleName);
}
+
+ @Override
+ protected final SubmoduleStatement createDeclared(final StmtContext<String, SubmoduleStatement, ?> ctx,
+ final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+ return new SubmoduleStatementImpl(ctx.coerceRawStatementArgument(), substatements);
+ }
+
+ @Override
+ protected final SubmoduleStatement createEmptyDeclared(final StmtContext<String, SubmoduleStatement, ?> ctx) {
+ throw noBelongsTo(ctx);
+ }
+
+ @Override
+ protected final SubmoduleEffectiveStatement createEffective(
+ final StmtContext<String, SubmoduleStatement, SubmoduleEffectiveStatement> ctx,
+ final SubmoduleStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+ return new SubmoduleEffectiveStatementImpl(ctx, declared, substatements);
+ }
+
+ @Override
+ protected final SubmoduleEffectiveStatement createEmptyEffective(
+ final StmtContext<String, SubmoduleStatement, SubmoduleEffectiveStatement> ctx,
+ final SubmoduleStatement declared) {
+ throw noBelongsTo(ctx);
+ }
+
+ private static SourceException noBelongsTo(final StmtContext<?, ?, ?> ctx) {
+ return new SourceException("No belongs-to declared in submodule", ctx.getStatementSourceReference());
+ }
}
import static com.google.common.base.Preconditions.checkState;
import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.ImmutableSet;
private ImmutableSet<Module> submodules;
private boolean sealed;
- SubmoduleEffectiveStatementImpl(final StmtContext<String, SubmoduleStatement, SubmoduleEffectiveStatement> ctx) {
- super(ctx, findSubmodulePrefix(ctx));
+ SubmoduleEffectiveStatementImpl(final StmtContext<String, SubmoduleStatement, SubmoduleEffectiveStatement> ctx,
+ final SubmoduleStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+ super(declared, ctx, substatements, findSubmodulePrefix(ctx));
final String belongsToModuleName = firstAttributeOf(ctx.declaredSubstatements(), BelongsToStatement.class);
final QNameModule belongsToModuleQName = ctx.getFromNamespace(ModuleNameToModuleQName.class,
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.submodule;
+import com.google.common.collect.ImmutableList;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractRootStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredEffectiveRootStatement;
-final class SubmoduleStatementImpl extends AbstractRootStatement<SubmoduleStatement> implements SubmoduleStatement {
- SubmoduleStatementImpl(final StmtContext<String, SubmoduleStatement, ?> context) {
- super(context);
+final class SubmoduleStatementImpl extends AbstractDeclaredEffectiveRootStatement<SubmoduleStatement>
+ implements SubmoduleStatement {
+ SubmoduleStatementImpl(final String rawArgument,
+ final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+ super(rawArgument, substatements);
}
}