X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-parser-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Fstmt%2Freactor%2FRootStatementContext.java;h=7c8b2d5877d44e16bba09744e3fbe44dd4568467;hb=fa1ed213acc06358d9b759fa871e2b360605734e;hp=d32b8cdee123346d0b072c69ee56ed515ab61348;hpb=fc97aa32d83e94cf8a8d61df31541b0b9b9f980e;p=yangtools.git
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/RootStatementContext.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/RootStatementContext.java
index d32b8cdee1..7c8b2d5877 100644
--- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/RootStatementContext.java
+++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/RootStatementContext.java
@@ -7,83 +7,115 @@
*/
package org.opendaylight.yangtools.yang.parser.stmt.reactor;
-import java.util.List;
-
-import java.util.LinkedList;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.common.QNameModule;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Verify;
+import com.google.common.collect.ImmutableList;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.Map;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.common.YangVersion;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
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.meta.IdentifierNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.NamespaceStorageNode;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Registry;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
+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.IncludedModuleContext;
+
+/**
+ * Root statement class for a YANG source. All statements defined in that YANG source are mapped underneath an instance
+ * of this class, hence recursive lookups from them cross this class.
+ */
+public class RootStatementContext, E extends EffectiveStatement> extends
+ StatementContextBase {
-class RootStatementContext, E extends EffectiveStatement>
- extends StatementContextBase {
+ public static final YangVersion DEFAULT_VERSION = YangVersion.VERSION_1;
private final SourceSpecificContext sourceContext;
private final A argument;
- RootStatementContext(ContextBuilder builder,
- SourceSpecificContext sourceContext) throws SourceException {
+ private YangVersion version;
+
+ /**
+ * References to RootStatementContext of submodules which are included in this source.
+ */
+ private Collection> includedContexts = ImmutableList.of();
+
+ RootStatementContext(final ContextBuilder builder, final SourceSpecificContext sourceContext) {
super(builder);
- this.sourceContext = sourceContext;
- this.argument = builder.getDefinition().parseArgumentValue(this,
- builder.getRawArgument());
+ this.sourceContext = Preconditions.checkNotNull(sourceContext);
+ this.argument = builder.getDefinition().parseArgumentValue(this, builder.getRawArgument());
+ }
+
+ RootStatementContext(final ContextBuilder builder, final SourceSpecificContext sourceContext,
+ final YangVersion version) {
+ this(builder, sourceContext);
+ this.setRootVersion(version);
}
- RootStatementContext(RootStatementContext original,
- QNameModule newQNameModule, TypeOfCopy typeOfCopy)
- throws SourceException {
+ RootStatementContext(final RootStatementContext original, final QNameModule newQNameModule,
+ final CopyType typeOfCopy) {
super(original);
- sourceContext = original.sourceContext;
+ sourceContext = Preconditions.checkNotNull(original.sourceContext);
this.argument = original.argument;
- copyDeclaredStmts(original, newQNameModule, typeOfCopy);
-
- copyEffectiveStmts(original, newQNameModule, typeOfCopy);
-
- }
+ final Collection> declared = original.declaredSubstatements();
+ final Collection> effective = original.effectiveSubstatements();
+ final Collection> buffer = new ArrayList<>(declared.size() + effective.size());
- private void copyDeclaredStmts(RootStatementContext original,
- QNameModule newQNameModule, TypeOfCopy typeOfCopy)
- throws SourceException {
- Collection extends StmtContext, ?, ?>> originalDeclaredSubstatements = original
- .declaredSubstatements();
- for (StmtContext, ?, ?> stmtContext : originalDeclaredSubstatements) {
- this.addEffectiveSubstatement(stmtContext.createCopy(
- newQNameModule, this, typeOfCopy));
+ for (final StatementContextBase, ?, ?> stmtContext : declared) {
+ if (StmtContextUtils.areFeaturesSupported(stmtContext)) {
+ buffer.add(stmtContext.createCopy(newQNameModule, this, typeOfCopy));
+ }
}
- }
-
- private void copyEffectiveStmts(RootStatementContext original,
- QNameModule newQNameModule, TypeOfCopy typeOfCopy)
- throws SourceException {
- Collection extends StmtContext, ?, ?>> originalEffectiveSubstatements = original
- .effectiveSubstatements();
- for (StmtContext, ?, ?> stmtContext : originalEffectiveSubstatements) {
- this.addEffectiveSubstatement(stmtContext.createCopy(
- newQNameModule, this, typeOfCopy));
+ for (final StmtContext, ?, ?> stmtContext : effective) {
+ buffer.add(stmtContext.createCopy(newQNameModule, this, typeOfCopy));
}
+
+ addEffectiveSubstatements(buffer);
}
+ /**
+ * @return null as root cannot have parent
+ */
@Override
public StatementContextBase, ?, ?> getParentContext() {
return null;
}
+ /**
+ * @return namespace storage of source context
+ */
@Override
public NamespaceStorageNode getParentNamespaceStorage() {
return sourceContext;
}
+ /**
+ * @return registry of source context
+ */
@Override
public Registry getBehaviourRegistry() {
return sourceContext;
}
+ @Override
+ public StorageNodeType getStorageNodeType() {
+ return StorageNodeType.ROOT_STATEMENT_LOCAL;
+ }
+ /**
+ * @return this as its own root
+ */
+ @Nonnull
@Override
public RootStatementContext, ?, ?> getRoot() {
return this;
@@ -98,26 +130,117 @@ class RootStatementContext, E extends Effectiv
return argument;
}
+ /**
+ * @return copy of this considering {@link CopyType} (augment, uses)
+ *
+ * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException instance of SourceException
+ */
@Override
- public StatementContextBase createCopy(QNameModule newQNameModule,
- StatementContextBase, ?, ?> newParent, TypeOfCopy typeOfCopy)
- throws SourceException {
- RootStatementContext copy = new RootStatementContext<>(this,
- newQNameModule, typeOfCopy);
- copy.setTypeOfCopy(typeOfCopy);
- copy.setOriginalCtx(this);
+ public StatementContextBase, ?, ?> createCopy(final StatementContextBase, ?, ?> newParent,
+ final CopyType typeOfCopy) {
+ return createCopy(null, newParent, typeOfCopy);
+ }
+
+ /**
+ * @return copy of this considering {@link CopyType} (augment, uses)
+ *
+ * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException instance of SourceException
+ */
+ @Override
+ public StatementContextBase createCopy(final QNameModule newQNameModule,
+ final StatementContextBase, ?, ?> newParent, final CopyType typeOfCopy) {
+ final RootStatementContext copy = new RootStatementContext<>(this, newQNameModule, typeOfCopy);
+
+ copy.appendCopyHistory(typeOfCopy, this.getCopyHistory());
+
+ if (this.getOriginalCtx() != null) {
+ copy.setOriginalCtx(this.getOriginalCtx());
+ } else {
+ copy.setOriginalCtx(this);
+ }
+ definition().onStatementAdded(copy);
return copy;
}
+ @Nonnull
@Override
- public List