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=386ae9ad8dbecf8e53bbc207df0a6a17a7e816f1;hpb=478bc415b646bffd2cfd144cc7247a73f8455636;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 386ae9ad8d..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,52 +9,66 @@ 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.Maps; +import java.util.Collection; import java.util.Map; import java.util.Map.Entry; -import java.util.Objects; 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.ImportEffectiveStatement; +import org.opendaylight.yangtools.yang.model.api.stmt.ExtensionEffectiveStatement; +import org.opendaylight.yangtools.yang.model.api.stmt.ExtensionEffectiveStatementNamespace; +import org.opendaylight.yangtools.yang.model.api.stmt.ExtensionStatement; +import org.opendaylight.yangtools.yang.model.api.stmt.FeatureEffectiveStatement; +import org.opendaylight.yangtools.yang.model.api.stmt.FeatureEffectiveStatementNamespace; +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.ModuleEffectiveStatement; import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement; import org.opendaylight.yangtools.yang.model.api.stmt.PrefixEffectiveStatement; import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleEffectiveStatement; import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractEffectiveModule; +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 { - private final Map nameToSubmodule; - private final Map prefixToModule; - private final Map namespaceToPrefix; +final class ModuleEffectiveStatementImpl extends AbstractEffectiveModule + implements Module, ModuleEffectiveStatement { + private final ImmutableMap nameToSubmodule; + private final ImmutableMap qnameToExtension; + private final ImmutableMap qnameToFeature; + private final ImmutableMap qnameToIdentity; + private final ImmutableMap prefixToModule; + private final ImmutableMap namespaceToPrefix; private final @NonNull QNameModule qnameModule; + private final ImmutableList submodules; + + ModuleEffectiveStatementImpl(final StmtContext ctx, + final ModuleStatement declared, final ImmutableList> substatements, + final Collection submodules) { + super(declared, ctx, substatements, findPrefix(ctx, "module", ctx.coerceRawStatementArgument())); - ModuleEffectiveStatementImpl( - final StmtContext> ctx) { - super(ctx); 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); @@ -64,11 +78,24 @@ final class ModuleEffectiveStatementImpl extends AbstractEffectiveModule> submodules = + final Map> includedSubmodules = ctx.getAllFromCurrentStmtCtxNamespace(IncludedSubmoduleNameToModuleCtx.class); - nameToSubmodule = submodules == null ? ImmutableMap.of() : - ImmutableMap.copyOf(Maps.transformValues(submodules, - submodule -> (SubmoduleEffectiveStatement) submodule.buildEffective())); + nameToSubmodule = includedSubmodules == null ? ImmutableMap.of() + : ImmutableMap.copyOf(Maps.transformValues(includedSubmodules, + submodule -> (SubmoduleEffectiveStatement) submodule.buildEffective())); + + final Map> extensions = + ctx.getAllFromCurrentStmtCtxNamespace(ExtensionNamespace.class); + qnameToExtension = extensions == null ? ImmutableMap.of() + : ImmutableMap.copyOf(Maps.transformValues(extensions, StmtContext::buildEffective)); + final Map> features = + ctx.getAllFromCurrentStmtCtxNamespace(FeatureNamespace.class); + qnameToFeature = features == null ? ImmutableMap.of() + : ImmutableMap.copyOf(Maps.transformValues(features, StmtContext::buildEffective)); + final Map> identities = + ctx.getAllFromCurrentStmtCtxNamespace(IdentityNamespace.class); + qnameToIdentity = identities == null ? ImmutableMap.of() + : ImmutableMap.copyOf(Maps.transformValues(identities, StmtContext::buildEffective)); } @Override @@ -81,6 +108,16 @@ final class ModuleEffectiveStatementImpl extends AbstractEffectiveModule getSubmodules() { + return submodules; + } + + @Override + public ModuleEffectiveStatement asEffectiveStatement() { + return this; + } + @Override @SuppressWarnings("unchecked") public > Optional> getNamespaceContents( @@ -94,37 +131,15 @@ final class ModuleEffectiveStatementImpl extends AbstractEffectiveModule) nameToSubmodule); } - return super.getNamespaceContents(namespace); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + Objects.hashCode(getName()); - result = prime * result + Objects.hashCode(getYangVersion()); - result = prime * result + Objects.hashCode(qnameModule); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof ModuleEffectiveStatementImpl)) { - return false; + if (ExtensionEffectiveStatementNamespace.class.equals(namespace)) { + return Optional.of((Map) qnameToExtension); } - ModuleEffectiveStatementImpl other = (ModuleEffectiveStatementImpl) obj; - if (!Objects.equals(getName(), other.getName())) { - return false; + if (FeatureEffectiveStatementNamespace.class.equals(namespace)) { + return Optional.of((Map) qnameToFeature); } - if (!qnameModule.equals(other.qnameModule)) { - return false; + if (IdentityEffectiveStatementNamespace.class.equals(namespace)) { + return Optional.of((Map) qnameToIdentity); } - if (!Objects.equals(getYangVersion(), other.getYangVersion())) { - return false; - } - return true; + return super.getNamespaceContents(namespace); } }