*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
-
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType;
-import java.util.LinkedHashSet;
-import java.util.LinkedHashMap;
import com.google.common.collect.ImmutableMap;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.UsesNode;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
-import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
-import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
-import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
-import java.util.Map;
-import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToIdentifier;
+import com.google.common.collect.ImmutableSet;
import java.net.URI;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Deviation;
import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
+import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.UsesNode;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
+import org.opendaylight.yangtools.yang.model.util.ExtendedType;
+import org.opendaylight.yangtools.yang.model.util.ModuleImportImpl;
+import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
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.source.DeclarationInTextSource;
+import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToIdentifier;
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
public class ModuleEffectiveStatementImpl extends
- AbstractEffectiveDocumentedNode<String, ModuleStatement>
- implements Module, Immutable {
+ AbstractEffectiveDocumentedNode<String, ModuleStatement> implements
+ Module, Immutable {
private final QNameModule qNameModule;
private final String name;
- private String sourcePath; // TODO fill
+ private final String sourcePath;
private String prefix;
private String yangVersion;
private String organization;
private ImmutableList<ExtensionDefinition> extensionNodes;
private ImmutableSet<IdentitySchemaNode> identities;
private ImmutableList<UnknownSchemaNode> unknownNodes;
- private String source;
- private ImmutableList<EffectiveStatement<?,?>> substatementsOfSubmodules;
+ private final String source;
+ private ImmutableList<EffectiveStatement<?, ?>> substatementsOfSubmodules;
private ImmutableMap<QName, DataSchemaNode> childNodes;
private ImmutableSet<GroupingDefinition> groupings;
private ImmutableSet<DataSchemaNode> publicChildNodes;
public ModuleEffectiveStatementImpl(
- StmtContext<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> ctx) {
+ final StmtContext<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> ctx) {
super(ctx);
name = argument();
}
}
- // TODO init source, sourcePath
- source = ctx.getStatementSource().name();
+ if (yangVersion == null) {
+ yangVersion = "1";
+ }
+
+ DeclarationInTextSource sourceReference = (DeclarationInTextSource) ctx.getStatementSourceReference();
+ sourcePath = sourceReference.getSourceName();
+ source = sourceReference.getSourceText();
initSubmodules(ctx);
initSubstatementCollections(ctx);
}
private void initSubmodules(
- StmtContext<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> ctx) {
+ final StmtContext<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> ctx) {
Map<String, ModuleIdentifier> includedSubmodulesMap = ctx
.getAllFromCurrentStmtCtxNamespace(IncludedSubmoduleNameToIdentifier.class);
.values();
Set<Module> submodulesInit = new HashSet<>();
- List<EffectiveStatement<?,?>> substatementsOfSubmodulesInit = new LinkedList<>();
+ List<EffectiveStatement<?, ?>> substatementsOfSubmodulesInit = new LinkedList<>();
for (ModuleIdentifier submoduleIdentifier : includedSubmodules) {
Mutable<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> submoduleCtx = (Mutable<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>>) ctx
.getFromNamespace(SubmoduleNamespace.class,
submoduleIdentifier);
- SubmoduleEffectiveStatementImpl submodule = (SubmoduleEffectiveStatementImpl) submoduleCtx.buildEffective();
+ SubmoduleEffectiveStatementImpl submodule = (SubmoduleEffectiveStatementImpl) submoduleCtx
+ .buildEffective();
submodulesInit.add(submodule);
- substatementsOfSubmodulesInit.addAll(submodule.effectiveSubstatements());
+ substatementsOfSubmodulesInit.addAll(submodule
+ .effectiveSubstatements());
}
this.submodules = ImmutableSet.copyOf(submodulesInit);
- this.substatementsOfSubmodules = ImmutableList.copyOf(substatementsOfSubmodulesInit);
+ this.substatementsOfSubmodules = ImmutableList
+ .copyOf(substatementsOfSubmodulesInit);
}
- private void initSubstatementCollections(StmtContext<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> ctx) {
+ private void initSubstatementCollections(
+ final StmtContext<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> ctx) {
List<EffectiveStatement<?, ?>> effectiveSubstatements = new LinkedList<>();
effectiveSubstatements.addAll(effectiveSubstatements());
dataSchemaNode);
mutablePublicChildNodes.add(dataSchemaNode);
} else {
- throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
+ throw EffectiveStmtUtils
+ .createNameCollisionSourceException(ctx,
+ effectiveStatement);
}
}
if (effectiveStatement instanceof UsesNode) {
if (!mutableUses.contains(usesNode)) {
mutableUses.add(usesNode);
} else {
- throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
+ throw EffectiveStmtUtils
+ .createNameCollisionSourceException(ctx,
+ effectiveStatement);
}
}
if (effectiveStatement instanceof TypeDefEffectiveStatementImpl) {
if (!mutableTypeDefinitions.contains(extendedType)) {
mutableTypeDefinitions.add(extendedType);
} else {
- throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
+ throw EffectiveStmtUtils
+ .createNameCollisionSourceException(ctx,
+ effectiveStatement);
}
}
if (effectiveStatement instanceof GroupingDefinition) {
if (!mutableGroupings.contains(grp)) {
mutableGroupings.add(grp);
} else {
- throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
+ throw EffectiveStmtUtils
+ .createNameCollisionSourceException(ctx,
+ effectiveStatement);
}
}
}
this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
this.augmentations = ImmutableSet.copyOf(augmentationsInit);
- this.imports = ImmutableSet.copyOf(importsInit);
+ this.imports = ImmutableSet.copyOf(resolveModuleImports(importsInit,
+ ctx));
this.notifications = ImmutableSet.copyOf(notificationsInit);
this.rpcs = ImmutableSet.copyOf(rpcsInit);
this.deviations = ImmutableSet.copyOf(deviationsInit);
this.uses = ImmutableSet.copyOf(mutableUses);
}
+ private static Set<ModuleImport> resolveModuleImports(
+ final Set<ModuleImport> importsInit,
+ final StmtContext<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> ctx) {
+ Set<ModuleImport> resolvedModuleImports = new LinkedHashSet<>();
+ for (ModuleImport moduleImport : importsInit) {
+ if (moduleImport.getRevision().equals(
+ SimpleDateFormatUtil.DEFAULT_DATE_IMP)) {
+ QNameModule impModuleQName = Utils.getModuleQNameByPrefix(ctx,
+ moduleImport.getPrefix());
+ if (!impModuleQName.getRevision().equals(
+ SimpleDateFormatUtil.DEFAULT_DATE_REV)) {
+ ModuleImport resolvedModuleImport = new ModuleImportImpl(
+ moduleImport.getModuleName(),
+ impModuleQName.getRevision(),
+ moduleImport.getPrefix());
+ resolvedModuleImports.add(resolvedModuleImport);
+ }
+ } else {
+ resolvedModuleImports.add(moduleImport);
+ }
+ }
+ return resolvedModuleImports;
+ }
+
@Override
public String getModuleSourcePath() {
return sourcePath;
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(ModuleEffectiveStatementImpl.class.getSimpleName());
+ StringBuilder sb = new StringBuilder(
+ ModuleEffectiveStatementImpl.class.getSimpleName());
sb.append("[");
sb.append("name=").append(name);
sb.append(", namespace=").append(getNamespace());