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 java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import com.google.common.collect.ImmutableList;
14 import java.util.List;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.eclipse.jdt.annotation.Nullable;
19 * A single YANG statement in its raw string form. A statement is composed of:
21 * <li>a mandatory keyword, modeled as {@link IRKeyword}</li>
22 * <li>an optional argument, modeled as {@link IRArgument}</li>
23 * <li>zero or more nested statements</li>
27 public abstract class IRStatement extends AbstractIRObject {
28 private final @NonNull IRKeyword keyword;
29 private final IRArgument argument;
31 IRStatement(final IRKeyword keyword, final IRArgument argument) {
32 this.keyword = requireNonNull(keyword);
33 this.argument = argument;
37 * Return this statement's keyword.
39 * @return This statement's keyword.
41 public final @NonNull IRKeyword keyword() {
46 * Return this statement's argument, if it is present.
48 * @return This statement's argument, or null if this statement does not have an argument
50 public final @Nullable IRArgument argument() {
55 * Return this statement's substatements.
57 * @return This statement's substatements.
59 public @NonNull List<? extends IRStatement> statements() {
60 return ImmutableList.of();
64 * Return the line number on which this statement's keyword has its first character, counting from <b>1</b>. This
65 * information is used only for diagnostic purposes.
67 * @return Line number where this statement started in the source code.
69 public abstract int startLine();
72 * Return the column number on which this statement's keyword has its first character, counting from <b>0</b>. This
73 * information is used only for diagnostic purposes.
75 * @return Column number where this statement started in the source code.
77 public abstract int startColumn();
80 final StringBuilder toYangFragment(final StringBuilder sb) {
81 keyword.toYangFragment(sb);
82 if (argument != null) {
83 argument.toYangFragment(sb.append(' '));
86 final List<? extends IRStatement> statements = statements();
87 if (statements.isEmpty()) {
88 return sb.append(';');
92 for (IRStatement stmt : statements) {
93 stmt.toYangFragment(sb).append('\n');
95 return sb.append('}');