@NonNull StatementDefinitionContext<?, ?, ?> getSubDefinitionSpecificForArgument(final String argument) { if (!hasArgumentSpecificSubDefinitions()) { return this; } StatementDefinitionContext<?, ?, ?> potential = argumentSpecificSubDefinitions.get(argument); if (potential == null) { final StatementSupport<?, ?, ?> argumentSpecificSupport = support.getSupportSpecificForArgument(argument); potential = argumentSpecificSupport != null ? new StatementDefinitionContext<>(argumentSpecificSupport) : this; argumentSpecificSubDefinitions.put(argument, potential); } return potential; }
@Override public final String toString() { return addToStringAttributes(MoreObjects.toStringHelper(this).omitNullValues()).toString(); }
@Override protected void checkLocalNamespaceAllowed(final Class<? extends IdentifierNamespace<?, ?>> type) { definition().checkNamespaceAllowed(type); }
final StatementSupport<?, ?, ?> extension = qnameToStmtDefMap.get(name); if (extension != null) { def = new StatementDefinitionContext<>(extension); currentContext.putModelDefinedStatementDefinition(name, def); def = checkNotNull(current.definition().getAsUnknownStatementDefinition(def), "Unable to create unknown statement definition of yang statement %s in unknown statement %s", def, current); .hasArgument()) { SourceException.throwIfNull(argument, ref, "Statement %s requires an argument", name); } else { if (def.hasArgumentSpecificSubDefinitions()) { def = def.getSubDefinitionSpecificForArgument(argument); root.getRootIdentifier()); } else { final QName rootStatement = root.definition().getStatementName(); final String rootArgument = root.rawStatementArgument(); checkState(Objects.equals(def.getStatementName(), rootStatement) && Objects.equals(argument, rootArgument), "Root statement was already defined as '%s %s'.", rootStatement, rootArgument);
/** * 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; }
StatementDefinitionContext<?, ?, ?> getStatementDefinition(final YangVersion version, final QName name) { StatementDefinitionContext<?, ?, ?> potential = definitions.get(version, name); if (potential == null) { final StatementSupport<?, ?, ?> potentialRaw = supports.get(currentPhase).getStatementDefinition(version, name); if (potentialRaw != null) { potential = new StatementDefinitionContext<>(potentialRaw); definitions.put(version, name, potential); } } return potential; }
@Override public D buildDeclared() { checkArgument(completedPhase == ModelProcessingPhase.FULL_DECLARATION || completedPhase == ModelProcessingPhase.EFFECTIVE_MODEL); if (declaredInstance == null) { declaredInstance = definition().getFactory().createDeclared(this); } return declaredInstance; }
/** * See {@link StatementSupport#getPublicView()}. */ @Override public StatementDefinition getPublicDefinition() { return definition().getPublicView(); }
protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) { return toStringHelper.add("statement", getStatementName()); }
SubstatementContext(final StatementContextBase<A, D, E> original, final StatementContextBase<?, ?, ?> parent, final CopyType copyType, final QNameModule targetModule) { super(original, copyType); this.parent = requireNonNull(parent); this.argument = targetModule == null ? original.getStatementArgument() : original.definition().adaptArgumentValue(original, targetModule); }
private StatementContextBase<?, ?, ?> createImplicitParent(final int offset, final StatementSupport<?, ?, ?> implicitParent, final StatementSourceReference ref, final String argument) { final StatementDefinitionContext<?, ?, ?> def = new StatementDefinitionContext<>(implicitParent); return createSubstatement(offset, def, ImplicitSubstatement.of(ref), argument); }
@Override public E buildEffective() { if (effectiveInstance == null) { effectiveInstance = definition().getFactory().createEffective(this); } return effectiveInstance; }
StatementDefinitionContext<?, ?, ?> getAsUnknownStatementDefinition( final StatementDefinitionContext<?, ?, ?> yangStmtDef) { if (unknownStmtDefsOfYangStmts != null) { final StatementDefinitionContext<?, ?, ?> existing = unknownStmtDefsOfYangStmts.get(yangStmtDef); if (existing != null) { return existing; } } else { unknownStmtDefsOfYangStmts = new HashMap<>(); } @SuppressWarnings("unchecked") final StatementDefinitionContext<?, ?, ?> ret = support.getUnknownStatementDefinitionOf( yangStmtDef.getPublicView()).map(StatementDefinitionContext::new).orElse(null); if (ret != null) { unknownStmtDefsOfYangStmts.put(yangStmtDef, ret); } return ret; }
public void appendImplicitStatement(final StatementSupport<?, ?, ?> statementToAdd) { createSubstatement(substatements.capacity(), new StatementDefinitionContext<>(statementToAdd), ImplicitSubstatement.of(getStatementSourceReference()), null); }