import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.if_feature.IfFeatureStatementRFC7950Support;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.import_.ImportStatementRFC6020Support;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.import_.ImportStatementRFC7950Support;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.include.IncludeStatementRFC6020Support;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.include.IncludeStatementRFC7950Support;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.include.IncludeStatementSupport;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.input.InputStatementRFC6020Support;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.input.InputStatementRFC7950Support;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.key.KeyStatementSupport;
.addSupport(NamespaceStatementSupport.getInstance())
.addVersionSpecificSupport(VERSION_1, ImportStatementRFC6020Support.getInstance())
.addVersionSpecificSupport(VERSION_1_1, ImportStatementRFC7950Support.getInstance())
- .addVersionSpecificSupport(VERSION_1, IncludeStatementRFC6020Support.getInstance())
- .addVersionSpecificSupport(VERSION_1_1, IncludeStatementRFC7950Support.getInstance())
+ .addVersionSpecificSupport(VERSION_1, IncludeStatementSupport.rfc6020Instance())
+ .addVersionSpecificSupport(VERSION_1_1, IncludeStatementSupport.rfc7950Instance())
.addSupport(BelongsToStatementSupport.getInstance())
.addSupport(PrefixStatementSupport.getInstance())
.addSupport(YangVersionStatementSupport.getInstance())
+++ /dev/null
-/*
- * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.include;
-
-import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
-import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
-
-public final class IncludeStatementRFC6020Support extends AbstractIncludeStatementSupport {
- private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
- YangStmtMapping.INCLUDE).addOptional(YangStmtMapping.REVISION_DATE).build();
- private static final IncludeStatementRFC6020Support INSTANCE = new IncludeStatementRFC6020Support();
-
- private IncludeStatementRFC6020Support() {
- // Hidden
- }
-
- public static IncludeStatementRFC6020Support getInstance() {
- return INSTANCE;
- }
-
- @Override
- protected SubstatementValidator getSubstatementValidator() {
- return SUBSTATEMENT_VALIDATOR;
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2016 Inocybe Technologies and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.include;
-
-import com.google.common.annotations.Beta;
-import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
-import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
-
-/**
- * Implementation of include statement definition for Yang 1.1 (RFC 7950) to
- * allow include statement to have "description" and "reference" as substatements.
- */
-@Beta
-public final class IncludeStatementRFC7950Support extends AbstractIncludeStatementSupport {
- private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator
- .builder(YangStmtMapping.INCLUDE)
- .addOptional(YangStmtMapping.REVISION_DATE)
- .addOptional(YangStmtMapping.DESCRIPTION)
- .addOptional(YangStmtMapping.REFERENCE).build();
- private static final IncludeStatementRFC7950Support INSTANCE = new IncludeStatementRFC7950Support();
-
- private IncludeStatementRFC7950Support() {
- // Hidden
- }
-
- public static IncludeStatementRFC7950Support getInstance() {
- return INSTANCE;
- }
-
- @Override
- protected SubstatementValidator getSubstatementValidator() {
- return SUBSTATEMENT_VALIDATOR;
- }
-}
\ No newline at end of file
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.include;
+import static java.util.Objects.requireNonNull;
import static org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase.SOURCE_LINKAGE;
import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.findFirstDeclaredSubstatement;
+import com.google.common.annotations.Beta;
import com.google.common.collect.ImmutableList;
import java.util.Collection;
import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceKeyCriterion;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
+import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
import org.opendaylight.yangtools.yang.parser.spi.source.IncludedModuleContext;
import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToModuleCtx;
-abstract class AbstractIncludeStatementSupport
+@Beta
+public final class IncludeStatementSupport
extends BaseStringStatementSupport<IncludeStatement, IncludeEffectiveStatement> {
+ private static final @NonNull IncludeStatementSupport RFC6020_INSTANCE = new IncludeStatementSupport(
+ SubstatementValidator.builder(YangStmtMapping.INCLUDE).addOptional(YangStmtMapping.REVISION_DATE).build());
+ private static final @NonNull IncludeStatementSupport RFC7950_INSTANCE = new IncludeStatementSupport(
+ SubstatementValidator.builder(YangStmtMapping.INCLUDE)
+ .addOptional(YangStmtMapping.REVISION_DATE)
+ .addOptional(YangStmtMapping.DESCRIPTION)
+ .addOptional(YangStmtMapping.REFERENCE)
+ .build());
- AbstractIncludeStatementSupport() {
+ private final SubstatementValidator validator;
+
+ IncludeStatementSupport(final SubstatementValidator validator) {
super(YangStmtMapping.INCLUDE, CopyPolicy.REJECT);
+ this.validator = requireNonNull(validator);
+ }
+
+ public static @NonNull IncludeStatementSupport rfc6020Instance() {
+ return RFC6020_INSTANCE;
+ }
+
+ public static @NonNull IncludeStatementSupport rfc7950Instance() {
+ return RFC7950_INSTANCE;
}
@Override
- public final void onPreLinkageDeclared(final Mutable<String, IncludeStatement, IncludeEffectiveStatement> stmt) {
+ public void onPreLinkageDeclared(final Mutable<String, IncludeStatement, IncludeEffectiveStatement> stmt) {
final StmtContext<Revision, ?, ?> revision = findFirstDeclaredSubstatement(stmt,
RevisionDateStatement.class);
stmt.addRequiredSource(revision == null ? RevisionSourceIdentifier.create(stmt.argument())
}
@Override
- public final void onLinkageDeclared(final Mutable<String, IncludeStatement, IncludeEffectiveStatement> stmt) {
+ public void onLinkageDeclared(final Mutable<String, IncludeStatement, IncludeEffectiveStatement> stmt) {
final String submoduleName = stmt.getArgument();
final StmtContext<Revision, ?, ?> revision = findFirstDeclaredSubstatement(stmt, RevisionDateStatement.class);
}
@Override
- protected final IncludeStatement createDeclared(final StmtContext<String, IncludeStatement, ?> ctx,
+ protected SubstatementValidator getSubstatementValidator() {
+ return validator;
+ }
+
+ @Override
+ protected IncludeStatement createDeclared(final StmtContext<String, IncludeStatement, ?> ctx,
final ImmutableList<? extends DeclaredStatement<?>> substatements) {
return new RegularIncludeStatement(ctx.getRawArgument(), ctx.getArgument(), substatements);
}
@Override
- protected final IncludeStatement createEmptyDeclared(final StmtContext<String, IncludeStatement, ?> ctx) {
+ protected IncludeStatement createEmptyDeclared(final StmtContext<String, IncludeStatement, ?> ctx) {
return new EmptyIncludeStatement(ctx.getRawArgument(), ctx.getArgument());
}
@Override
- protected final IncludeEffectiveStatement createEffective(final Current<String, IncludeStatement> stmt,
+ protected IncludeEffectiveStatement createEffective(final Current<String, IncludeStatement> stmt,
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
return substatements.isEmpty() ? new EmptyIncludeEffectiveStatement(stmt.declared())
: new RegularIncludeEffectiveStatement(stmt.declared(), substatements);