2 * Copyright (c) 2015 Cisco Systems, Inc. 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
9 package org.opendaylight.yangtools.yang.stmt.test;
11 import java.util.ArrayList;
12 import java.util.List;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16 import java.util.Collection;
18 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
19 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.Module;
21 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
22 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
24 public class StmtTestUtils {
26 private static final Logger LOG = LoggerFactory.getLogger(StmtTestUtils.class);
28 private StmtTestUtils() {
32 public static void log(Throwable e, String indent) {
33 LOG.debug(indent + e.getMessage());
35 Throwable[] suppressed = e.getSuppressed();
36 for (Throwable throwable : suppressed) {
37 log(throwable, indent + " ");
41 public static List<Module> findModules(final Set<Module> modules, final String moduleName) {
42 List<Module> result = new ArrayList<>();
43 for (Module module : modules) {
44 if (module.getName().equals(moduleName)) {
51 public static void addSources(
52 CrossSourceStatementReactor.BuildAction reactor,
53 YangStatementSourceImpl... sources) {
54 for (YangStatementSourceImpl source : sources) {
55 reactor.addSource(source);
59 public static void printReferences(Module module, boolean isSubmodule,
61 LOG.debug(indent + (isSubmodule ? "Submodule " : "Module ")
63 Set<Module> submodules = module.getSubmodules();
64 for (Module submodule : submodules) {
65 printReferences(submodule, true, indent + " ");
66 printChilds(submodule.getChildNodes(), indent + " ");
70 public static void printChilds(Collection<DataSchemaNode> childNodes,
73 for (DataSchemaNode child : childNodes) {
74 LOG.debug(indent + "Child "
75 + child.getQName().getLocalName());
76 if (child instanceof DataNodeContainer) {
77 printChilds(((DataNodeContainer) child).getChildNodes(), indent