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.ir;
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.model.repo.api.SchemaSourceRepresentation;
19 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
20 import org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRKeyword.Unqualified;
23 public final class IRSchemaSource extends AbstractSimpleIdentifiable<SourceIdentifier>
24 implements SchemaSourceRepresentation {
25 private final @NonNull IRStatement rootStatement;
26 private final @Nullable String symbolicName;
28 public IRSchemaSource(final @NonNull SourceIdentifier identifier, final @NonNull IRStatement rootStatement,
29 @Nullable final String symbolicName) {
31 this.rootStatement = requireNonNull(rootStatement);
32 this.symbolicName = symbolicName;
34 final IRKeyword rootKeyword = rootStatement.keyword();
35 checkArgument(rootKeyword instanceof Unqualified, "Root statement has invalid keyword %s", rootKeyword);
36 final String rootName = rootKeyword.identifier();
42 throw new IllegalArgumentException("Invalid root statement keyword " + rootName);
45 checkArgument(rootStatement.argument() != null, "Root statement does not have an argument");
48 public IRSchemaSource(final @NonNull SourceIdentifier identifier, final @NonNull IRStatement rootStatement) {
49 this(identifier, rootStatement, null);
53 public Optional<String> getSymbolicName() {
54 return Optional.ofNullable(symbolicName);
58 public Class<@NonNull IRSchemaSource> getType() {
59 return IRSchemaSource.class;
63 * Return the root statement of this source.
65 * @return Root statement.
67 public @NonNull IRStatement getRootStatement() {