import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.OnDemandSchemaTreeStorageNode;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextDefaults;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
import org.slf4j.Logger;
public <X, Z extends EffectiveStatement<X, ?>> @NonNull Optional<X> findSubstatementArgument(
final @NonNull Class<Z> type) {
if (substatements instanceof List) {
- return StmtContextDefaults.findSubstatementArgument(this, type);
+ return super.findSubstatementArgument(type);
}
final Optional<X> templateArg = prototype.findSubstatementArgument(type);
@Override
public boolean hasSubstatement(final @NonNull Class<? extends EffectiveStatement<?, ?>> type) {
- return substatements instanceof List ? StmtContextDefaults.hasSubstatement(prototype, type)
+ return substatements instanceof List ? super.hasSubstatement(type)
// We do not allow deletion of partially-materialized statements, hence this is accurate
: prototype.hasSubstatement(type);
}
return getOriginalCtx().map(StmtContext::buildEffective).orElse(null);
}
+ @Override
+ // Non-final due to InferredStatementContext's override
+ public <X, Z extends EffectiveStatement<X, ?>> @NonNull Optional<X> findSubstatementArgument(
+ final @NonNull Class<Z> type) {
+ return allSubstatementsStream()
+ .filter(ctx -> ctx.isSupportedToBuildEffective() && ctx.producesEffective(type))
+ .findAny()
+ .map(ctx -> (X) ctx.getArgument());
+ }
+
+ @Override
+ // Non-final due to InferredStatementContext's override
+ public boolean hasSubstatement(final @NonNull Class<? extends EffectiveStatement<?, ?>> type) {
+ return allSubstatementsStream()
+ .anyMatch(ctx -> ctx.isSupportedToBuildEffective() && ctx.producesEffective(type));
+ }
+
@Override
@Deprecated
@SuppressWarnings("unchecked")
import com.google.common.annotations.Beta;
import com.google.common.base.VerifyException;
+import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.common.YangVersion;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
/**
* A {@link CommonStmtCtx} which has additionally been bound to a {@link StatementSupport}. It provides
* @return YANG version used to bind this statement
*/
@NonNull YangVersion yangVersion();
+
+ /**
+ * Search of any child statement context of specified type and return its argument. If such a statement exists, it
+ * is assumed to have the right argument. Users should be careful to use this method for statements which have
+ * cardinality {@code 0..1}, otherwise this method can return any one of the statement's argument.
+ *
+ * @param <X> Substatement argument type
+ * @param <Z> Substatement effective statement representation
+ * @param type Effective statement representation being look up
+ * @return {@link Optional#empty()} if no statement exists, otherwise the argument value
+ */
+ <X, Z extends EffectiveStatement<X, ?>> @NonNull Optional<X> findSubstatementArgument(@NonNull Class<Z> type);
+
+ /**
+ * Check if there is any child statement context of specified type.
+ *
+ * @param type Effective statement representation being look up
+ * @return True if such a child statement exists, false otherwise
+ */
+ boolean hasSubstatement(@NonNull Class<? extends EffectiveStatement<?, ?>> type);
}
void setIsSupportedToBuildEffective(boolean isSupportedToBuild);
}
-
- /**
- * Search of any child statement context of specified type and return its argument. If such a statement exists, it
- * is assumed to have the right argument. Users should be careful to use this method for statements which have
- * cardinality {@code 0..1}, otherwise this method can return any one of the statement's argument.
- *
- * <p>
- * The default implementation defers to
- * {@link StmtContextDefaults#findSubstatementArgument(StmtContext, Class)}, subclasses are expected to provide
- * optimized implementation if possible.
- *
- * @param <X> Substatement argument type
- * @param <Z> Substatement effective statement representation
- * @param type Effective statement representation being look up
- * @return {@link Optional#empty()} if no statement exists, otherwise the argument value
- */
- default <X, Z extends EffectiveStatement<X, ?>> @NonNull Optional<X> findSubstatementArgument(
- final @NonNull Class<Z> type) {
- return StmtContextDefaults.findSubstatementArgument(this, type);
- }
-
- /**
- * Check if there is any child statement context of specified type.
- *
- * <p>
- * The default implementation defers to {@link StmtContextDefaults#hasSubstatement(StmtContext, Class)},
- * subclasses are expected to provide optimized implementation if possible.
- *
- * @param type Effective statement representation being look up
- * @return True if such a child statement exists, false otherwise
- */
- default boolean hasSubstatement(final @NonNull Class<? extends EffectiveStatement<?, ?>> type) {
- return StmtContextDefaults.hasSubstatement(this, type);
- }
}
+++ /dev/null
-/*
- * Copyright (c) 2020 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 java.util.Optional;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-
-/**
- * Default implementations for various {@link StmtContext} methods. Code hosted here is meant for use by actual
- * {@link StmtContext} implementations, not for general use by others.
- */
-public final class StmtContextDefaults {
- private StmtContextDefaults() {
- // Hidden on purpose
- }
-
- /**
- * Default implementation of {@link StmtContext#findSubstatementArgument(Class)}. See that method for API contract.
- *
- * @param <A> Substatement argument type
- * @param <E> Substatement effective statement representation
- * @param stmt Statement context to search
- * @param type Effective statement representation being look up
- * @return Effective statement argument, if found
- */
- @SuppressWarnings({"unchecked" })
- public static <A, E extends EffectiveStatement<A, ?>> @NonNull Optional<A> findSubstatementArgument(
- final @NonNull StmtContext<?, ?, ?> stmt, final @NonNull Class<E> type) {
- return stmt.allSubstatementsStream()
- .filter(ctx -> ctx.isSupportedToBuildEffective() && ctx.producesEffective(type))
- .findAny()
- .map(ctx -> (A) ctx.getArgument());
- }
-
- /**
- * Default implementation of {@link StmtContext#hasSubstatement(Class)}. See that method for API contract.
- *
- * @param stmt Statement context to search
- * @param type Effective statement representation being look up
- * @return True if a match is found, false otherwise
- */
- public static boolean hasSubstatement(final @NonNull StmtContext<?, ?, ?> stmt,
- final @NonNull Class<? extends EffectiveStatement<?, ?>> type) {
- return stmt.allSubstatementsStream()
- .anyMatch(ctx -> ctx.isSupportedToBuildEffective() && ctx.producesEffective(type));
- }
-}
* @param <A> statement argument type
* @param <D> declared statement type
* @return statement context that was searched for or null if was not found
- * @deprecated Use {@link StmtContext#findSubstatementArgument(Class)} instead.
+ * @deprecated Use {@link BoundStmtCtx#findSubstatementArgument(Class)} instead.
*/
@Deprecated(forRemoval = true)
public static <A, D extends DeclaredStatement<A>> StmtContext<A, ?, ?> findFirstSubstatement(