import com.google.common.annotations.Beta;
import com.google.common.collect.ImmutableList;
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.Status;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
import org.opendaylight.yangtools.yang.model.api.stmt.StatusEffectiveStatement;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.EffectiveStatementWithFlags.FlagsBuilder;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractQNameStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
/**
*/
@Beta
public abstract class BaseQNameStatementSupport<D extends DeclaredStatement<QName>,
- E extends EffectiveStatement<QName, D>> extends AbstractQNameStatementSupport<D, E> {
+ E extends EffectiveStatement<QName, D>> extends BaseStatementSupport<QName, D, E> {
protected BaseQNameStatementSupport(final StatementDefinition publicDefinition) {
super(publicDefinition);
}
- @Override
- public final D createDeclared(final StmtContext<QName, D, ?> ctx) {
- final ImmutableList<? extends DeclaredStatement<?>> substatements = ctx.declaredSubstatements().stream()
- .map(StmtContext::buildDeclared)
- .collect(ImmutableList.toImmutableList());
- return substatements.isEmpty() ? createEmptyDeclared(ctx) : createDeclared(ctx, substatements);
+ protected BaseQNameStatementSupport(final StatementDefinition publicDefinition, final CopyPolicy copyPolicy) {
+ super(publicDefinition, copyPolicy);
}
- protected abstract @NonNull D createDeclared(@NonNull StmtContext<QName, D, ?> ctx,
- @NonNull ImmutableList<? extends DeclaredStatement<?>> substatements);
-
- protected abstract @NonNull D createEmptyDeclared(@NonNull StmtContext<QName, D, ?> ctx);
-
@Override
- public E createEffective(final StmtContext<QName, D, E> ctx) {
- final D declared = ctx.buildDeclared();
- final ImmutableList<? extends EffectiveStatement<?, ?>> substatements =
- BaseStatementSupport.buildEffectiveSubstatements(ctx);
- return substatements.isEmpty() ? createEmptyEffective(ctx, declared)
- : createEffective(ctx, declared, substatements);
- }
-
- protected abstract @NonNull E createEffective(@NonNull StmtContext<QName, D, E> ctx, @NonNull D declared,
- @NonNull ImmutableList<? extends EffectiveStatement<?, ?>> substatements);
-
- protected abstract @NonNull E createEmptyEffective(@NonNull StmtContext<QName, D, E> ctx, @NonNull D declared);
-
- protected static final <E extends EffectiveStatement<?, ?>> @Nullable E findFirstStatement(
- final ImmutableList<? extends EffectiveStatement<?, ?>> statements, final Class<E> type) {
- return BaseStatementSupport.findFirstStatement(statements, type);
- }
-
- protected static final <A, E extends EffectiveStatement<A, ?>> A findFirstArgument(
- final ImmutableList<? extends EffectiveStatement<?, ?>> statements, final Class<E> type, final A defValue) {
- return BaseStatementSupport.findFirstArgument(statements, type, defValue);
+ public QName adaptArgumentValue(final StmtContext<QName, D, E> ctx, final QNameModule targetModule) {
+ return ctx.coerceStatementArgument().bindTo(targetModule).intern();
}
protected static final int historyAndStatusFlags(final StmtContext<?, ?, ?> ctx,
protected abstract @NonNull D createEmptyDeclared(@NonNull StmtContext<A, D, ?> ctx);
@Override
- public final E createEffective(final StmtContext<A, D, E> ctx) {
+ public E createEffective(final StmtContext<A, D, E> ctx) {
final D declared = ctx.buildDeclared();
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements =
buildEffectiveSubstatements(ctx, statementsToBuild(ctx, declaredSubstatements(ctx)));
return defaultBuildEffectiveSubstatements(substatements);
}
- static final ImmutableList<? extends EffectiveStatement<?, ?>> buildEffectiveSubstatements(
- final StmtContext<?, ?, ?> ctx) {
- return defaultBuildEffectiveSubstatements(declaredSubstatements(ctx));
- }
-
private static ImmutableList<? extends EffectiveStatement<?, ?>> defaultBuildEffectiveSubstatements(
final List<? extends StmtContext<?, ?, ?>> substatements) {
return substatements.stream()
.collect(ImmutableList.toImmutableList());
}
- static final @NonNull List<StmtContext<?, ?, ?>> declaredSubstatements(final StmtContext<?, ?, ?> ctx) {
+ private static @NonNull List<StmtContext<?, ?, ?>> declaredSubstatements(final StmtContext<?, ?, ?> ctx) {
/*
* This dance is required to ensure that effects of 'uses' nodes are applied in the same order as
* the statements were defined -- i.e. if we have something like this:
+++ /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.spi.meta;
-
-import com.google.common.annotations.Beta;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
-
-/**
- * Class providing necessary support for processing a YANG statements which has a {@link QName} argument. In addition
- * to functions of {@link AbstractStatementSupport}, it takes care of adapting QNames across modules.
- *
- * @param <D>
- * Declared Statement representation
- * @param <E>
- * Effective Statement representation
- */
-@Beta
-public abstract class AbstractQNameStatementSupport<D extends DeclaredStatement<QName>,
- E extends EffectiveStatement<QName, D>> extends AbstractStatementSupport<QName, D, E> {
-
- protected AbstractQNameStatementSupport(final StatementDefinition publicDefinition) {
- super(publicDefinition);
- }
-
- @Override
- public QName adaptArgumentValue(final StmtContext<QName, D, E> ctx, final QNameModule targetModule) {
- return ctx.coerceStatementArgument().bindTo(targetModule).intern();
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2019 PANTHEON.tech, 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.spi.meta;
-
-import com.google.common.annotations.Beta;
-import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
-
-/**
- * Class providing necessary support for processing a YANG statements which does not have an argument. In addition
- * to functions of {@link AbstractStatementSupport}, it provide the argument value.
- *
- * @param <D> Declared Statement representation
- * @param <E> Effective Statement representation
- */
-@Beta
-public abstract class AbstractVoidStatementSupport<D extends DeclaredStatement<Void>,
- E extends EffectiveStatement<Void, D>> extends AbstractStatementSupport<Void, D, E> {
-
- protected AbstractVoidStatementSupport(final StatementDefinition publicDefinition) {
- super(publicDefinition);
- }
-
- protected AbstractVoidStatementSupport(final StatementDefinition publicDefinition, final CopyPolicy copyPolicy) {
- super(publicDefinition, copyPolicy);
- }
-
- @Override
- public final Void parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
- return null;
- }
-}