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
9 package org.opendaylight.yangtools.yang.parser.stmt.reactor;
11 import com.google.common.base.Preconditions;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.yangtools.concepts.Builder;
14 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
15 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
16 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
17 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
19 abstract class ContextBuilder<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
20 implements Builder<StatementContextBase<A, D, E>> {
22 private final StatementDefinitionContext<A, D, E> definition;
23 private final StatementSourceReference stmtRef;
25 private StatementSourceReference argRef;
26 private String rawArg;
28 ContextBuilder(final StatementDefinitionContext<A, D, E> def, final StatementSourceReference sourceRef) {
29 this.definition = Preconditions.checkNotNull(def);
30 this.stmtRef = Preconditions.checkNotNull(sourceRef);
33 void setArgument(@Nonnull final String argument, @Nonnull final StatementSourceReference argumentSource) {
34 SourceException.throwIf(!definition.hasArgument(), argumentSource, "Statement %s does not take argument",
35 definition.getStatementName());
36 this.rawArg = Preconditions.checkNotNull(argument);
37 this.argRef = Preconditions.checkNotNull(argumentSource);
40 String getRawArgument() {
44 StatementSourceReference getStamementSource() {
48 StatementSourceReference getArgumentSource() {
52 StatementDefinitionContext<A, D, E> getDefinition() {
56 StatementIdentifier createIdentifier() {
57 return new StatementIdentifier(definition.getStatementName(), rawArg);
63 * @throws SourceException when a source-level problem is found
66 public abstract StatementContextBase<A, D, E> build();