package org.opendaylight.yangtools.yang.parser.spi.meta;
import com.google.common.base.Preconditions;
+import java.util.Optional;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import org.opendaylight.yangtools.yang.common.QName;
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.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementDefinitionContext;
/**
*
private final StatementDefinition type;
- protected AbstractStatementSupport(StatementDefinition publicDefinition) {
+ protected AbstractStatementSupport(final StatementDefinition publicDefinition) {
Preconditions.checkArgument(publicDefinition != this);
this.type = Preconditions.checkNotNull(publicDefinition);
}
+ @Nonnull
@Override
public final QName getStatementName() {
return type.getStatementName();
return type.getArgumentName();
}
+ @Nonnull
@Override
public final Class<? extends DeclaredStatement<?>> getDeclaredRepresentationClass() {
return type.getDeclaredRepresentationClass();
}
+ @Nonnull
@Override
- public final Class<? extends DeclaredStatement<?>> getEffectiveRepresentationClass() {
+ public final Class<? extends EffectiveStatement<?,?>> getEffectiveRepresentationClass() {
return type.getEffectiveRepresentationClass();
}
}
@Override
- public abstract A parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) throws SourceException;
+ public Optional<StatementContextBase<?, ?, ?>> beforeSubStatementCreated(final StmtContext.Mutable<?, ?, ?> stmt,
+ final int offset, final StatementDefinitionContext<?, ?, ?> def, final StatementSourceReference ref,
+ final String argument) {
+ // NOOP for most implementations and also no implicit statements
+ return Optional.empty();
+ }
@Override
- public void onStatementAdded(StmtContext.Mutable<A, D, E> stmt) {
+ public void onStatementAdded(final StmtContext.Mutable<A, D, E> stmt) {
// NOOP for most implementations
}
/**
- *
* {@inheritDoc}
*
* Subclasses of this class may override this method to perform actions on
* this event or register modification action using
* {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
- *
*/
@Override
- public void onLinkageDeclared(StmtContext.Mutable<A, D, E> stmt) throws SourceException {
+ public void onPreLinkageDeclared(final StmtContext.Mutable<A, D, E> stmt) {
// NOOP for most implementations
}
/**
- *
* {@inheritDoc}
*
* Subclasses of this class may override this method to perform actions on
* this event or register modification action using
* {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
- *
*/
@Override
- public void onStatementDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt) throws SourceException {
+ public void onLinkageDeclared(final StmtContext.Mutable<A, D, E> stmt) {
// NOOP for most implementations
}
/**
- *
* {@inheritDoc}
*
* Subclasses of this class may override this method to perform actions on
* this event or register modification action using
* {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
- *
*/
@Override
- public void onFullDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt) throws SourceException {
+ public void onStatementDefinitionDeclared(final StmtContext.Mutable<A, D, E> stmt) {
// NOOP for most implementations
}
+ /**
+ * {@inheritDoc}
+ *
+ * Subclasses of this class may override this method to perform actions on
+ * this event or register modification action using
+ * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
+ */
+ @Override
+ public void onFullDefinitionDeclared(final StmtContext.Mutable<A, D, E> stmt) {
+ final SubstatementValidator validator = getSubstatementValidator();
+ if (validator != null) {
+ validator.validate(stmt);
+ }
+ }
+
+ @Override
+ public boolean isArgumentYinElement() {
+ return getPublicView().isArgumentYinElement();
+ }
+
+ @Override
+ public boolean hasArgumentSpecificSupports() {
+ // Most of statement supports don't have any argument specific
+ // supports, so return 'false'.
+ return false;
+ }
+
+ @Override
+ public StatementSupport<?, ?, ?> getSupportSpecificForArgument(final String argument) {
+ // Most of statement supports don't have any argument specific
+ // supports, so return null.
+ return null;
+ }
+
+ /**
+ * Returns corresponding substatement validator of a statement support
+ *
+ * @return substatement validator or null, if substatement validator is not
+ * defined
+ */
+ @Nullable
+ protected abstract SubstatementValidator getSubstatementValidator();
}