import com.google.common.annotations.Beta;
import com.google.common.base.MoreObjects;
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 java.net.URI;
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.opendaylight.yangtools.yang.model.api.UsesNode;
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.model.api.stmt.ContactEffectiveStatement;
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.OrganizationEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.PrefixEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeAwareEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
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;
private final ImmutableSet<TypeDefinition<?>> typeDefinitions;
private final ImmutableSet<DataSchemaNode> publicChildNodes;
private final SemVer semanticVersion;
+ private final ImmutableMap<QName, SchemaTreeEffectiveStatement<?>> schemaTreeNamespace;
protected AbstractEffectiveModule(
final @NonNull StmtContext<String, D, ? extends EffectiveStatement<String, ?>> ctx,
final @NonNull String prefix) {
super(ctx);
+ // 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
+ // concerned. This ensures that we have SchemaTree index available for use with child lookups.
+ final Map<QName, SchemaTreeEffectiveStatement<?>> schemaTree =
+ createSchemaTreeNamespace(ctx.getStatementSourceReference(), effectiveSubstatements());
+ schemaTreeNamespace = ImmutableMap.copyOf(schemaTree);
+
+ // Data tree check, not currently used
+ createDataTreeNamespace(ctx.getStatementSourceReference(), schemaTree.values(), schemaTreeNamespace);
+
this.name = argument();
this.prefix = requireNonNull(prefix);
this.yangVersion = findFirstEffectiveSubstatementArgument(YangVersionEffectiveStatement.class)
@Override
@SuppressWarnings("checkstyle:hiddenField")
public final Optional<DataSchemaNode> findDataChildByName(final QName name) {
- return findDataSchemaNode(name);
+ final SchemaTreeEffectiveStatement<?> child = schemaTreeNamespace.get(requireNonNull(name));
+ return child instanceof DataSchemaNode ? Optional.of((DataSchemaNode) child) : Optional.empty();
}
@Override
return Optional.ofNullable(semanticVersion);
}
+ @Override
+ @SuppressWarnings("unchecked")
+ protected <K, V, N extends IdentifierNamespace<K, V>> Optional<? extends Map<K, V>> getNamespaceContents(
+ final Class<N> namespace) {
+ if (SchemaTreeAwareEffectiveStatement.Namespace.class.equals(namespace)) {
+ return Optional.of((Map<K, V>) schemaTreeNamespace);
+ }
+ return super.getNamespaceContents(namespace);
+ }
+
@Override
public String toString() {
return MoreObjects.toStringHelper(this).omitNullValues()
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt;
-import static com.google.common.base.Verify.verify;
-import static java.util.Objects.requireNonNull;
-
import com.google.common.annotations.Beta;
import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import java.lang.invoke.VarHandle;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
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.model.api.stmt.CaseEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.DataTreeAwareEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.DataTreeEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeAwareEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
@Beta
public abstract class AbstractSchemaEffectiveDocumentedNode<A, D extends DeclaredStatement<A>>
extends AbstractEffectiveDocumentedNode<A, D> {
- private final ImmutableMap<QName, DataTreeEffectiveStatement<?>> dataTreeNamespace;
- private final ImmutableMap<QName, SchemaTreeEffectiveStatement<?>> schemaTreeNamespace;
-
protected AbstractSchemaEffectiveDocumentedNode(final StmtContext<A, D, ?> ctx) {
super(ctx);
-
- // 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
- // concerned. This ensures that we have SchemaTree index available for use with child lookups.
- final Map<QName, SchemaTreeEffectiveStatement<?>> schemaTree;
- if (this instanceof SchemaTreeAwareEffectiveStatement || this instanceof DataNodeContainer) {
- schemaTree = createSchemaTreeNamespace(ctx.getStatementSourceReference(),
- effectiveSubstatements());
- } else {
- schemaTree = ImmutableMap.of();
- }
- schemaTreeNamespace = ImmutableMap.copyOf(schemaTree);
-
- if (this instanceof DataTreeAwareEffectiveStatement && !schemaTree.isEmpty()) {
- dataTreeNamespace = createDataTreeNamespace(ctx.getStatementSourceReference(), schemaTree.values(),
- schemaTreeNamespace);
- } else {
- dataTreeNamespace = ImmutableMap.of();
- }
- }
-
- @Override
- @SuppressWarnings("unchecked")
- protected <K, V, N extends IdentifierNamespace<K, V>> Optional<? extends Map<K, V>> getNamespaceContents(
- final Class<N> namespace) {
- if (this instanceof SchemaTreeAwareEffectiveStatement
- && SchemaTreeAwareEffectiveStatement.Namespace.class.equals(namespace)) {
- return Optional.of((Map<K, V>) schemaTreeNamespace);
- }
- if (this instanceof DataTreeAwareEffectiveStatement
- && DataTreeAwareEffectiveStatement.Namespace.class.equals(namespace)) {
- return Optional.of((Map<K, V>) dataTreeNamespace);
- }
- return super.getNamespaceContents(namespace);
- }
-
- protected final <T> @NonNull ImmutableSet<T> derivedSet(final VarHandle vh, final @NonNull Class<T> clazz) {
- final ImmutableSet<T> existing = (ImmutableSet<T>) vh.getAcquire(this);
- return existing != null ? existing : loadSet(vh, clazz);
- }
-
- /**
- * Indexing support for {@link DataNodeContainer#findDataChildByName(QName)}.
- */
- protected final Optional<DataSchemaNode> findDataSchemaNode(final QName name) {
- // Only DataNodeContainer subclasses should be calling this method
- verify(this instanceof DataNodeContainer);
- final SchemaTreeEffectiveStatement<?> child = schemaTreeNamespace.get(requireNonNull(name));
- return child instanceof DataSchemaNode ? Optional.of((DataSchemaNode) child) : Optional.empty();
}
static @NonNull Map<QName, SchemaTreeEffectiveStatement<?>> createSchemaTreeNamespace(
return sameAsSchema ? (ImmutableMap) schemaTreeNamespace : ImmutableMap.copyOf(dataChildren);
}
- @SuppressWarnings("unchecked")
- private <T> @NonNull ImmutableSet<T> loadSet(final VarHandle vh, final @NonNull Class<T> clazz) {
- final ImmutableSet<T> computed = ImmutableSet.copyOf(allSubstatementsOfType(clazz));
- final Object witness = vh.compareAndExchangeRelease(this, null, computed);
- return witness == null ? computed : (ImmutableSet<T>) witness;
- }
-
private static <T extends SchemaTreeEffectiveStatement<?>> void putChild(final Map<QName, T> map,
final T child, final StatementSourceReference ref, final String tree) {
final QName id = child.getIdentifier();