@Override public @NonNull StatementSourceReference getSourceReference() { return getStatementSourceReference(); }
private void beforeAddEffectiveStatement(final int toAdd) { final ModelProcessingPhase inProgressPhase = getRoot().getSourceContext().getInProgressPhase(); checkState(inProgressPhase == ModelProcessingPhase.FULL_DECLARATION || inProgressPhase == ModelProcessingPhase.EFFECTIVE_MODEL, "Effective statement cannot be added in declared phase at: %s", getStatementSourceReference()); if (effective.isEmpty()) { effective = new ArrayList<>(toAdd); } }
/** * Adds {@link OnPhaseFinished} listener for a {@link ModelProcessingPhase} end. If the base has already completed * the listener is notified immediately. * * @param phase requested completion phase * @param listener listener to invoke * @throws NullPointerException if any of the arguments is null */ void addPhaseCompletedListener(final ModelProcessingPhase phase, final OnPhaseFinished listener) { checkNotNull(phase, "Statement context processing phase cannot be null at: %s", getStatementSourceReference()); checkNotNull(listener, "Statement context phase listener cannot be null at: %s", getStatementSourceReference()); ModelProcessingPhase finishedPhase = completedPhase; while (finishedPhase != null) { if (phase.equals(finishedPhase)) { listener.phaseFinished(this, finishedPhase); return; } finishedPhase = finishedPhase.getPreviousPhase(); } if (phaseListeners.isEmpty()) { phaseListeners = newMultimap(); } phaseListeners.put(phase, listener); }
/** * Adds a {@link ContextMutation} to a {@link ModelProcessingPhase}. * * @throws IllegalStateException * when the mutation was registered after phase was completed */ void addMutation(final ModelProcessingPhase phase, final ContextMutation mutation) { ModelProcessingPhase finishedPhase = completedPhase; while (finishedPhase != null) { checkState(!phase.equals(finishedPhase), "Mutation registered after phase was completed at: %s", getStatementSourceReference()); finishedPhase = finishedPhase.getPreviousPhase(); } if (phaseMutation.isEmpty()) { phaseMutation = newMultimap(); } phaseMutation.put(phase, mutation); }
public void appendImplicitStatement(final StatementSupport<?, ?, ?> statementToAdd) { createSubstatement(substatements.capacity(), new StatementDefinitionContext<>(statementToAdd), ImplicitSubstatement.of(getStatementSourceReference()), null); }
@Override public void apply(final InferenceContext ctx) { final StatementContextBase<?, ?, ?> augmentTargetCtx = (StatementContextBase<?, ?, ?>) target.resolve(ctx); if (!isSupportedAugmentTarget(augmentTargetCtx) || StmtContextUtils.isInExtensionBody(augmentTargetCtx)) { augmentNode.setIsSupportedToBuildEffective(false); return; } /** * Marks case short hand in augment */ if (augmentTargetCtx.getPublicDefinition() == YangStmtMapping.CHOICE) { augmentNode.addToNs(AugmentToChoiceNamespace.class, augmentNode, Boolean.TRUE); } // FIXME: this is a workaround for models which augment a node which is added via an extension // which we do not handle. This needs to be reworked in terms of unknown schema nodes. final StatementContextBase<?, ?, ?> augmentSourceCtx = (StatementContextBase<?, ?, ?>) augmentNode; try { copyFromSourceToTarget(augmentSourceCtx, augmentTargetCtx); augmentTargetCtx.addEffectiveSubstatement(augmentSourceCtx); updateAugmentOrder(augmentSourceCtx); } catch (final SourceException e) { LOG.warn("Failed to add augmentation {} defined at {}", augmentTargetCtx.getStatementSourceReference(), augmentSourceCtx.getStatementSourceReference(), e); } }
/** * Create a new substatement at the specified offset. * * @param offset Substatement offset * @param def definition context * @param ref source reference * @param argument statement argument * @param <X> new substatement argument type * @param <Y> new substatement declared type * @param <Z> new substatement effective type * @return A new substatement */ @SuppressWarnings("checkstyle:methodTypeParameterName") public final <X, Y extends DeclaredStatement<X>, Z extends EffectiveStatement<X, Y>> StatementContextBase<X, Y, Z> createSubstatement(final int offset, final StatementDefinitionContext<X, Y, Z> def, final StatementSourceReference ref, final String argument) { final ModelProcessingPhase inProgressPhase = getRoot().getSourceContext().getInProgressPhase(); checkState(inProgressPhase != ModelProcessingPhase.EFFECTIVE_MODEL, "Declared statement cannot be added in effective phase at: %s", getStatementSourceReference()); final Optional<StatementSupport<?, ?, ?>> implicitParent = definition.getImplicitParentFor(def.getPublicView()); if (implicitParent.isPresent()) { return createImplicitParent(offset, implicitParent.get(), ref, argument).createSubstatement(offset, def, ref, argument); } final StatementContextBase<X, Y, Z> ret = new SubstatementContext<>(this, def, ref, argument); substatements = substatements.put(offset, ret); def.onStatementAdded(ret); return ret; }