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 javax.annotation.Nonnull;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
14 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
15 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
16 import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
18 class StatementContextWriter implements StatementWriter {
20 private final SourceSpecificContext ctx;
21 private StatementContextBase<?, ?, ?> parent;
22 private ContextBuilder<?, ?, ?> current;
23 private ModelProcessingPhase phase;
25 public StatementContextWriter(SourceSpecificContext ctx, ModelProcessingPhase phase) {
26 this.ctx = Preconditions.checkNotNull(ctx);
27 this.phase = Preconditions.checkNotNull(phase);
31 public void startStatement(QName name, StatementSourceReference ref) throws SourceException {
33 current = ctx.createDeclaredChild(parent, name, ref);
38 public void argumentValue(String value, StatementSourceReference ref) {
39 Preconditions.checkState(current != null, "Could not set two arguments for one statement: %s", ref);
40 current.setArgument(value, ref);
43 void defferedCreate() throws SourceException {
45 parent = current.build();
51 public void endStatement(StatementSourceReference ref) throws SourceException {
53 Preconditions.checkState(parent != null);
54 parent.endDeclared(ref,phase);
55 parent = parent.getParentContext();
60 public ModelProcessingPhase getPhase() {