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.namespace;
10 import static com.google.common.base.Verify.verify;
12 import com.google.common.annotations.Beta;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.yang.common.YangNamespaceContext;
15 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
21 public interface YangNamespaceContextNamespace extends ParserNamespace<StmtContext<?, ?, ?>, YangNamespaceContext> {
22 NamespaceBehaviour<StmtContext<?, ?, ?>, YangNamespaceContext, @NonNull YangNamespaceContextNamespace> BEHAVIOUR =
23 NamespaceBehaviour.global(YangNamespaceContextNamespace.class);
25 static @NonNull YangNamespaceContext computeIfAbsent(final StmtContext<?, ?, ?> ctx) {
26 final StmtContext<?, ?, ?> root = ctx.getRoot();
27 YangNamespaceContext ret = ctx.getFromNamespace(YangNamespaceContextNamespace.class, root);
29 verify(ctx instanceof Mutable, "Cannot populate namespace context to %s", ctx);
30 ret = new StmtNamespaceContext(root);
31 ((Mutable<?, ?, ?>)ctx).addToNs(YangNamespaceContextNamespace.class, root, ret);