/* * 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.rfc7950.stmt; import static java.util.Objects.requireNonNull; import com.google.common.annotations.Beta; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement; import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition; import org.opendaylight.yangtools.yang.model.api.meta.StatementSource; /** * Base stateless superclass for statements which (logically) always have an associated {@link DeclaredStatement}. This * is notably not true for all {@code case} statements, some of which may actually be implied. * *

* Note implementations are not strictly required to make the declared statement available, they are free to throw * {@link UnsupportedOperationException} from {@link #getDeclared()}, rendering any services relying on declared * statement to be not available. * * @param Argument type ({@link Void} if statement does not have argument.) * @param Class representing declared version of this statement. */ @Beta public abstract class AbstractDeclaredEffectiveStatement> extends AbstractEffectiveStatement { @Override public final StatementSource getStatementSource() { return StatementSource.DECLARATION; } @Override public final StatementDefinition statementDefinition() { return getDeclared().statementDefinition(); } @Override public abstract @NonNull D getDeclared(); /** * A stateful version of {@link AbstractDeclaredEffectiveStatement}, which holds (and requires) a declared * statement. * * @param Argument type ({@link Void} if statement does not have argument.) * @param Class representing declared version of this statement. */ public abstract static class Default> extends AbstractDeclaredEffectiveStatement { private final @NonNull D declared; protected Default(final D declared) { this.declared = requireNonNull(declared); } @Override public final D getDeclared() { return declared; } } /** * An extra building block on top of {@link Default}, which is wiring {@link #argument()} to the declared statement. * This is mostly useful for arguments that are not subject to inference transformation -- for example Strings in * {@code description}, etc. This explicitly is not true of statements which underwent namespace binding via * {@code uses} or similar. * * @param Argument type ({@link Void} if statement does not have argument.) * @param Class representing declared version of this statement. */ public abstract static class DefaultArgument> extends Default { protected DefaultArgument(final D declared) { super(declared); } @Override public final @Nullable A argument() { return getDeclared().argument(); } } }