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.stmt.reactor;
10 import com.google.common.base.Preconditions;
11 import com.google.common.base.Verify;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
15 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
16 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
17 import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
19 final class StatementContextWriter implements StatementWriter {
20 private final ModelProcessingPhase phase;
21 private final SourceSpecificContext ctx;
23 private StatementContextBase<?, ?, ?> current;
25 StatementContextWriter(final SourceSpecificContext ctx, final ModelProcessingPhase phase) {
26 this.ctx = Preconditions.checkNotNull(ctx);
27 this.phase = Preconditions.checkNotNull(phase);
31 public void startStatement(final int childId, @Nonnull final QName name, final String argument,
32 @Nonnull final StatementSourceReference ref) {
33 current = Verify.verifyNotNull(ctx.createDeclaredChild(current, childId, name, argument, ref));
37 public void endStatement(@Nonnull final StatementSourceReference ref) {
38 Preconditions.checkState(current != null);
39 current.endDeclared(ref, phase);
40 StatementContextBase<?, ?, ?> parentContext = current.getParentContext();
41 while (parentContext != null && StatementSource.CONTEXT == parentContext.getStatementSource()) {
42 parentContext.endDeclared(ref, phase);
43 parentContext = parentContext.getParentContext();
45 current = parentContext;
50 public ModelProcessingPhase getPhase() {