2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.uses;
10 import com.google.common.collect.ImmutableList;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
14 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
15 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Descendant;
17 import org.opendaylight.yangtools.yang.model.api.stmt.UsesStatement;
20 * An extension of {@link EmptyLocalUsesEffectiveStatement}, which adds substatements to the mix. Since this means we
21 * can also have refine statements, we keep a lazily-populated map of those.
23 final class RegularLocalUsesEffectiveStatement extends EmptyLocalUsesEffectiveStatement {
24 private final Object substatements;
26 private volatile Map<Descendant, SchemaNode> refines;
28 RegularLocalUsesEffectiveStatement(final UsesStatement declared, final GroupingDefinition sourceGrouping,
29 final int flags, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
30 super(declared, sourceGrouping, flags);
31 this.substatements = maskList(substatements);
35 public ImmutableList<? extends EffectiveStatement<?, ?>> effectiveSubstatements() {
36 return unmaskList(substatements);
40 public Map<Descendant, SchemaNode> getRefines() {
41 final Map<Descendant, SchemaNode> local;
42 return (local = refines) != null ? local : loadRefines();
45 private synchronized @NonNull Map<Descendant, SchemaNode> loadRefines() {
46 Map<Descendant, SchemaNode> local = refines;
48 refines = local = UsesStatementSupport.indexRefines(effectiveSubstatements());