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
8 package org.opendaylight.yangtools.yang.parser.spi.source;
10 import com.google.common.annotations.Beta;
11 import java.util.Optional;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.eclipse.jdt.annotation.NonNullByDefault;
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
19 public interface StatementWriter {
21 * Resumed statement state.
23 * @author Robert Varga
27 interface ResumedStatement {
29 * Return statement definition.
31 * @return statement definition.
33 StatementDefinition getDefinition();
36 * Return statement source reference.
38 * @return statement source reference.
40 StatementSourceReference getSourceReference();
43 * Check if the statement has been fully defined. This implies that all its children have been fully defined.
45 * @return True if the statement has been fully defined.
47 boolean isFullyDefined();
51 * Attempt to resume a child statement. If the statement has been previously defined, a {@link ResumedStatement}
52 * instance is returned.
55 * If an empty optional is returned, the caller is expected to follow-up with
56 * {@link #startStatement(int, QName, String, StatementSourceReference)} to define the statement.
59 * If the returned resumed statement indicates {@link ResumedStatement#isFullyDefined()}, the caller should take
60 * no further action with this or any of the child statements. Otherwise this call is equivalent of issuing
61 * {@link #startStatement(int, QName, String, StatementSourceReference)} and the caller is expected to process
62 * any child statements. The caller should call {@link #storeStatement(int, boolean)} before finishing processing
63 * with {@link #endStatement(StatementSourceReference)}.
65 * @param childId Child
66 * @return A resumed statement or empty if the statement has not previously been defined.
69 default Optional<? extends ResumedStatement> resumeStatement(final int childId) {
70 return Optional.empty();
74 * Store a defined statement, hinting at the number of children it is expected to have and indicating whether
75 * it has been fully defined. This method should be called before {@link #endStatement(StatementSourceReference)}
76 * when the caller is taking advantage of {@link #resumeStatement(int)}.
78 * @param expectedChildren Number of expected children, cannot be negative
79 * @param fullyDefined True if the statement and all its descendants have been defined.
82 default void storeStatement(final int expectedChildren, final boolean fullyDefined) {
87 * Starts statement with supplied name and location in source.
90 * Each started statement must also be closed by
91 * {@link #endStatement(StatementSourceReference)} in order for stream to be
95 * If statement has substatements, in order to start substatement, call to
96 * {@link #startStatement(int, QName, String, StatementSourceReference)} needs to be done for substatement.
98 * @param childId Child identifier, unique among siblings
99 * @param name Fully qualified name of statement.
100 * @param argument String representation of value as appeared in source, null if not present
101 * @param ref Identifier of location in source, which will be used for reporting in case of statement processing
103 * @throws SourceException if statement is not valid according to current context.
105 void startStatement(int childId, @NonNull QName name, @Nullable String argument,
106 @NonNull StatementSourceReference ref);
109 * Ends current opened statement.
111 * @param ref Identifier of location in source, which will be used for reporting in case of statement processing
113 * @throws SourceException if closed statement is not valid in current context, or there is no such statement
115 void endStatement(@NonNull StatementSourceReference ref);
118 * Return current model processing phase.
120 * @return current processing phase
122 @NonNull ModelProcessingPhase getPhase();