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.repo;
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static java.util.Objects.requireNonNull;
13 import com.google.common.annotations.Beta;
14 import java.util.Optional;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.opendaylight.yangtools.concepts.AbstractSimpleIdentifiable;
18 import org.opendaylight.yangtools.yang.ir.IRKeyword;
19 import org.opendaylight.yangtools.yang.ir.IRKeyword.Unqualified;
20 import org.opendaylight.yangtools.yang.ir.IRStatement;
21 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
22 import org.opendaylight.yangtools.yang.model.repo.api.YangSchemaSourceRepresentation;
25 public final class IRSchemaSource extends AbstractSimpleIdentifiable<SourceIdentifier>
26 implements YangSchemaSourceRepresentation {
27 private final @NonNull IRStatement rootStatement;
28 private final @Nullable String symbolicName;
30 public IRSchemaSource(final @NonNull SourceIdentifier identifier, final @NonNull IRStatement rootStatement,
31 final @Nullable String symbolicName) {
33 this.rootStatement = requireNonNull(rootStatement);
34 this.symbolicName = symbolicName;
36 final IRKeyword rootKeyword = rootStatement.keyword();
37 checkArgument(rootKeyword instanceof Unqualified, "Root statement has invalid keyword %s", rootKeyword);
38 final String rootName = rootKeyword.identifier();
44 throw new IllegalArgumentException("Invalid root statement keyword " + rootName);
47 checkArgument(rootStatement.argument() != null, "Root statement does not have an argument");
51 public Optional<String> getSymbolicName() {
52 return Optional.ofNullable(symbolicName);
56 public Class<IRSchemaSource> getType() {
57 return IRSchemaSource.class;
61 * Return the root statement of this source.
63 * @return Root statement.
65 public @NonNull IRStatement getRootStatement() {