+ @Override
+ public final Parent effectiveParent() {
+ return getParentContext();
+ }
+
+ @Override
+ public final QName moduleName() {
+ final RootStatementContext<?, ?, ?> root = getRoot();
+ return QName.create(StmtContextUtils.getRootModuleQName(root), root.getRawArgument());
+ }
+
+ @Override
+ public final EffectiveStatement<?, ?> original() {
+ return getOriginalCtx().map(StmtContext::buildEffective).orElse(null);
+ }
+
+ //
+ // In the next two methods we are looking for an effective statement. If we already have an effective instance,
+ // defer to it's implementation of the equivalent search. Otherwise we search our substatement contexts.
+ //
+ // Note that the search function is split, so as to allow InferredStatementContext to do its own thing first.
+ //
+
+ @Override
+ public final <X, Z extends EffectiveStatement<X, ?>> @NonNull Optional<X> findSubstatementArgument(
+ final @NonNull Class<Z> 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 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.
+ <X, Z extends EffectiveStatement<X, ?>> @NonNull Optional<X> findSubstatementArgumentImpl(
+ final @NonNull Class<Z> type) {
+ return allSubstatementsStream()
+ .filter(ctx -> ctx.isSupportedToBuildEffective() && ctx.producesEffective(type))
+ .findAny()
+ .map(ctx -> (X) ctx.getArgument());
+ }
+
+ // Visible due to InferredStatementContext's override. At this point we do not have an effective instance available.
+ boolean hasSubstatementImpl(final @NonNull Class<? extends EffectiveStatement<?, ?>> type) {
+ return allSubstatementsStream()
+ .anyMatch(ctx -> ctx.isSupportedToBuildEffective() && ctx.producesEffective(type));
+ }
+
+ @Override
+ @Deprecated
+ @SuppressWarnings("unchecked")
+ public final <Z extends EffectiveStatement<A, D>> StmtContext<A, D, Z> caerbannog() {
+ return (StmtContext<A, D, Z>) this;
+ }
+