X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-parser-rfc7950%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Frfc7950%2Fstmt%2Fmodule%2FModuleEffectiveStatementImpl.java;h=e9f9a6df4d52b9992fc96e5f2253ca3f77b63ef2;hb=60aaa85b10b02b29f357fb53fed5723a498e1cef;hp=9e4df502fb8f94efb002813a715525f3ec0505d3;hpb=68e44f106cc8b3ba8e2354f3dfeb3770b868b25a;p=yangtools.git diff --git a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/module/ModuleEffectiveStatementImpl.java b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/module/ModuleEffectiveStatementImpl.java index 9e4df502fb..e9f9a6df4d 100644 --- a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/module/ModuleEffectiveStatementImpl.java +++ b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/module/ModuleEffectiveStatementImpl.java @@ -9,17 +9,21 @@ package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.module; 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.eclipse.jdt.annotation.NonNull; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; +import org.opendaylight.yangtools.yang.common.UnqualifiedQName; import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.Submodule; +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; @@ -30,7 +34,6 @@ import org.opendaylight.yangtools.yang.model.api.stmt.FeatureStatement; import org.opendaylight.yangtools.yang.model.api.stmt.IdentityEffectiveStatement; import org.opendaylight.yangtools.yang.model.api.stmt.IdentityEffectiveStatementNamespace; import org.opendaylight.yangtools.yang.model.api.stmt.IdentityStatement; -import org.opendaylight.yangtools.yang.model.api.stmt.ImportEffectiveStatement; 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.PrefixEffectiveStatement; @@ -40,12 +43,11 @@ import org.opendaylight.yangtools.yang.parser.spi.ExtensionNamespace; import org.opendaylight.yangtools.yang.parser.spi.FeatureNamespace; import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace; import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; -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; -final class ModuleEffectiveStatementImpl extends AbstractEffectiveModule - implements ModuleEffectiveStatement { +final class ModuleEffectiveStatementImpl extends AbstractEffectiveModule + implements Module, ModuleEffectiveStatement { private final ImmutableMap nameToSubmodule; private final ImmutableMap qnameToExtension; private final ImmutableMap qnameToFeature; @@ -53,26 +55,20 @@ final class ModuleEffectiveStatementImpl extends AbstractEffectiveModule prefixToModule; private final ImmutableMap namespaceToPrefix; private final @NonNull QNameModule qnameModule; - private final ImmutableSet submodules; + private final ImmutableList submodules; - private ModuleEffectiveStatementImpl(final @NonNull ModuleStmtContext ctx) { - super(ctx, findPrefix(ctx.delegate(), "module", ctx.getStatementArgument())); - submodules = ctx.getSubmodules(); + ModuleEffectiveStatementImpl(final StmtContext ctx, + final ModuleStatement declared, final ImmutableList> substatements, + final Collection submodules) { + super(declared, ctx, substatements, findPrefix(ctx, "module", ctx.coerceRawStatementArgument())); - 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 prefixToModuleBuilder = ImmutableMap.builder(); prefixToModuleBuilder.put(localPrefix, this); - - streamEffectiveSubstatements(ImportEffectiveStatement.class) - .map(imp -> imp.findFirstEffectiveSubstatementArgument(PrefixEffectiveStatement.class).get()) - .forEach(prefix -> { - final StmtContext importedCtx = - verifyNotNull(ctx.getFromNamespace(ImportPrefixToModuleCtx.class, prefix), - "Failed to resolve prefix %s", prefix); - prefixToModuleBuilder.put(prefix, (ModuleEffectiveStatement) importedCtx.buildEffective()); - }); + appendPrefixes(ctx, prefixToModuleBuilder); prefixToModule = prefixToModuleBuilder.build(); final Map tmp = Maps.newLinkedHashMapWithExpectedSize(prefixToModule.size() + 1); @@ -102,10 +98,6 @@ final class ModuleEffectiveStatementImpl extends AbstractEffectiveModule ctx) { - this(ModuleStmtContext.create(ctx)); - } - @Override public @NonNull QNameModule localQNameModule() { return qnameModule; @@ -117,10 +109,15 @@ final class ModuleEffectiveStatementImpl extends AbstractEffectiveModule getSubmodules() { + public Collection getSubmodules() { return submodules; } + @Override + public ModuleEffectiveStatement asEffectiveStatement() { + return this; + } + @Override @SuppressWarnings("unchecked") public > Optional> getNamespaceContents(