import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Verify.verify;
-import static com.google.common.base.Verify.verifyNotNull;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
import org.opendaylight.yangtools.yang.model.api.stmt.UsesStatement;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
-import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStatementState;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase.ExecutionOrder;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Registry;
import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
* {@link #buildEffective()} instance. If this context is reused, it can be inflated to {@link EffectiveInstances}
* and also act as a common instance reuse site.
*/
- private @Nullable Object effectiveInstance;
+ private @Nullable E effectiveInstance;
// Master flag controlling whether this context can yield an effective statement
// FIXME: investigate the mechanics that are being supported by this, as it would be beneficial if we can get rid
@Override
public final <X, Z extends EffectiveStatement<X, ?>> @NonNull Optional<X> findSubstatementArgument(
final @NonNull Class<Z> type) {
- final Object existing = effectiveInstance;
- return existing != null ? EffectiveInstances.local(existing).findFirstEffectiveSubstatementArgument(type)
+ final E existing = effectiveInstance;
+ return existing != null ? existing.findFirstEffectiveSubstatementArgument(type)
: findSubstatementArgumentImpl(type);
}
@Override
public final boolean hasSubstatement(final @NonNull Class<? extends EffectiveStatement<?, ?>> type) {
- final Object existing = effectiveInstance;
- return existing != null ? EffectiveInstances.local(existing).findFirstEffectiveSubstatement(type).isPresent()
- : hasSubstatementImpl(type);
+ final E existing = effectiveInstance;
+ return existing != null ? existing.findFirstEffectiveSubstatement(type).isPresent() : hasSubstatementImpl(type);
}
// Visible due to InferredStatementContext's override. At this point we do not have an effective instance available.
return getLocalNamespace(type);
}
- @Override
- protected final void checkLocalNamespaceAllowed(final Class<? extends ParserNamespace<?, ?>> type) {
- definition().checkNamespaceAllowed(type);
- }
-
@Override
protected <K, V, N extends ParserNamespace<K, V>> void onNamespaceElementAdded(final Class<N> type, final K key,
final V value) {
@Override
public final E buildEffective() {
- final Object existing;
- return (existing = effectiveInstance) != null ? EffectiveInstances.local(existing) : loadEffective();
+ final E existing;
+ return (existing = effectiveInstance) != null ? existing : loadEffective();
}
private @NonNull E loadEffective() {
abstract @NonNull E createEffective();
-
- /**
- * Attach an effective copy of this statement. This essentially acts as a map, where we make a few assumptions:
- * <ul>
- * <li>{@code copy} and {@code this} statement share {@link #getOriginalCtx()} if it exists</li>
- * <li>{@code copy} did not modify any statements relative to {@code this}</li>
- * </ul>
- *
- *
- * @param state effective statement state, acting as a lookup key
- * @param copy New copy to append
- * @return {@code copy} or a previously-created instances with the same {@code state}
- */
- @SuppressWarnings("unchecked")
- final @NonNull E attachCopy(final @NonNull EffectiveStatementState state, final @NonNull E copy) {
- final Object effective = verifyNotNull(effectiveInstance, "Attaching copy to a unbuilt %s", this);
- final EffectiveInstances<E> instances;
- if (effective instanceof EffectiveInstances) {
- instances = (EffectiveInstances<E>) effective;
- } else {
- effectiveInstance = instances = new EffectiveInstances<>((E) effective);
- }
- return instances.attachCopy(state, copy);
- }
-
/**
* Walk this statement's copy history and return the statement closest to original which has not had its effective
* statements modified. This statement and returned substatement logically have the same set of substatements, hence
*/
abstract @NonNull ReactorStmtCtx<A, D, E> unmodifiedEffectiveSource();
+ @Override
+ public final ModelProcessingPhase getCompletedPhase() {
+ return ModelProcessingPhase.ofExecutionOrder(executionOrder());
+ }
+
+ abstract byte executionOrder();
+
/**
* Try to execute current {@link ModelProcessingPhase} of source parsing. If the phase has already been executed,
- * this method does nothing.
+ * this method does nothing. This must not be called with {@link ExecutionOrder#NULL}.
*
* @param phase to be executed (completed)
* @return true if phase was successfully completed
* @throws SourceException when an error occurred in source parsing
*/
- final boolean tryToCompletePhase(final ModelProcessingPhase phase) {
- return phase.isCompletedBy(getCompletedPhase()) || doTryToCompletePhase(phase);
+ final boolean tryToCompletePhase(final byte executionOrder) {
+ return executionOrder() >= executionOrder || doTryToCompletePhase(executionOrder);
}
- abstract boolean doTryToCompletePhase(ModelProcessingPhase phase);
+ abstract boolean doTryToCompletePhase(byte targetOrder);
//
//
@Override
public final QName argumentAsTypeQName() {
- final Object argument = argument();
- verify(argument instanceof String, "Unexpected argument %s", argument);
- return interpretAsQName((String) argument);
+ return interpretAsQName(getRawArgument());
}
@Override