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.meta;
10 import com.google.common.collect.Collections2;
11 import com.google.common.collect.ImmutableList;
12 import java.util.Collection;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
15 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
16 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
19 * Utility abstract base class for implementing declared statements.
21 * @param <A> Argument type.
23 public abstract class AbstractDeclaredStatement<A> implements DeclaredStatement<A> {
24 private final @NonNull ImmutableList<? extends DeclaredStatement<?>> substatements;
25 private final @NonNull StatementDefinition definition;
26 private final @NonNull StatementSource source;
28 private final A argument;
29 private final String rawArgument;
31 protected AbstractDeclaredStatement(final StmtContext<A, ?, ?> context) {
32 rawArgument = context.rawStatementArgument();
33 argument = context.getStatementArgument();
34 source = context.getStatementSource();
35 definition = context.getPublicDefinition();
37 * Perform an explicit copy, because Collections2.transform() is lazily transformed and retains pointer to
38 * original collection, which may contains references to mutable context.
40 substatements = ImmutableList.copyOf(Collections2.transform(context.declaredSubstatements(),
41 StmtContext::buildDeclared));
45 public String rawArgument() {
55 public StatementDefinition statementDefinition() {
60 public Collection<? extends DeclaredStatement<?>> declaredSubstatements() {
65 public StatementSource getStatementSource() {