*/
package org.opendaylight.yangtools.yang.model.api.stmt;
+import com.google.common.base.VerifyException;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
/**
- * Effective representation of a {@code action} statement.
+ * Effective representation of a {@code action} statement. The effective view always defines an {@code input} and an
+ * {@code output} substatement, both of which are available through {@link #input()} and {@link #output()} methods.
*/
public interface ActionEffectiveStatement extends SchemaTreeEffectiveStatement<ActionStatement>,
DataTreeAwareEffectiveStatement<QName, ActionStatement>,
default StatementDefinition statementDefinition() {
return YangStmtMapping.ACTION;
}
+
+ /**
+ * Return this statement's {@code input} substatement.
+ *
+ * @implSpec
+ * Default implementation uses {@link #findFirstEffectiveSubstatement(Class)} and throws a
+ * {@link VerifyException} if a matching substatement is not found.
+ * @return An {@link InputEffectiveStatement}
+ */
+ default @NonNull InputEffectiveStatement input() {
+ return DefaultMethodHelpers.verifyInputSubstatement(this);
+ }
+
+ /**
+ * Return this statement's {@code output} substatement.
+ *
+ * @implSpec
+ * Default implementation uses {@link #findFirstEffectiveSubstatement(Class)} and throws a
+ * {@link VerifyException} if a matching substatement is not found.
+ * @return An {@link OutputEffectiveStatement}
+ */
+ default @NonNull OutputEffectiveStatement output() {
+ return DefaultMethodHelpers.verifyOutputSubstatement(this);
+ }
}
*/
package org.opendaylight.yangtools.yang.model.api.stmt;
+import com.google.common.base.VerifyException;
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
/**
* Simple helper methods used in default implementations.
static <E> @NonNull Optional<E> filterOptional(final @NonNull Optional<?> optional, final @NonNull Class<E> type) {
return optional.filter(type::isInstance).map(type::cast);
}
+
+ static @NonNull InputEffectiveStatement verifyInputSubstatement(final EffectiveStatement<?, ?> stmt) {
+ return verifySubstatement(stmt, InputEffectiveStatement.class);
+ }
+
+ static @NonNull OutputEffectiveStatement verifyOutputSubstatement(final EffectiveStatement<?, ?> stmt) {
+ return verifySubstatement(stmt, OutputEffectiveStatement.class);
+ }
+
+ private static <T extends EffectiveStatement<?, ?>> @NonNull T verifySubstatement(
+ final EffectiveStatement<?, ?> stmt, final Class<T> type) {
+ return stmt.findFirstEffectiveSubstatement(type).orElseThrow(
+ () -> new VerifyException(stmt + " does not define a " + type.getSimpleName() + " substatement"));
+ }
}
*/
package org.opendaylight.yangtools.yang.model.api.stmt;
+import com.google.common.base.VerifyException;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
/**
- * Effective representation of a {@code rpc} statement.
+ * Effective representation of a {@code rpc} statement. The effective view always defines an {@code input} and an
+ * {@code output} substatement, both of which are available through {@link #input()} and {@link #output()} methods.
*/
public interface RpcEffectiveStatement extends SchemaTreeEffectiveStatement<RpcStatement>,
DataTreeAwareEffectiveStatement<QName, RpcStatement>, TypedefAwareEffectiveStatement<QName, RpcStatement> {
default StatementDefinition statementDefinition() {
return YangStmtMapping.RPC;
}
+
+ /**
+ * Return this statement's {@code input} substatement.
+ *
+ * @implSpec
+ * Default implementation uses {@link #findFirstEffectiveSubstatement(Class)} and throws a
+ * {@link VerifyException} if a matching substatement is not found.
+ * @return An {@link InputEffectiveStatement}
+ */
+ default @NonNull InputEffectiveStatement input() {
+ return DefaultMethodHelpers.verifyInputSubstatement(this);
+ }
+
+ /**
+ * Return this statement's {@code output} substatement.
+ *
+ * @implSpec
+ * Default implementation uses {@link #findFirstEffectiveSubstatement(Class)} and throws a
+ * {@link VerifyException} if a matching substatement is not found.
+ * @return An {@link OutputEffectiveStatement}
+ */
+ default @NonNull OutputEffectiveStatement output() {
+ return DefaultMethodHelpers.verifyOutputSubstatement(this);
+ }
}
import org.opendaylight.yangtools.yang.model.api.stmt.ActionEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.InputEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ListEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.OutputEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.TypedefAwareEffectiveStatement;
final var action = container.findFirstEffectiveSubstatement(ActionEffectiveStatement.class).orElseThrow();
assertTypedef(action, "adef");
- assertTypedef(action.findFirstEffectiveSubstatement(InputEffectiveStatement.class).orElseThrow(), "idef");
- assertTypedef(action.findFirstEffectiveSubstatement(OutputEffectiveStatement.class).orElseThrow(), "odef");
+ assertTypedef(action.input(), "idef");
+ assertTypedef(action.output(), "odef");
}
private static void assertTypedef(final EffectiveStatement<?, ?> parent, final String typedefName) {