X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=parser%2Fyang-parser-reactor%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Fstmt%2Freactor%2FStatementContextBase.java;h=570e7a54f6a82b53c9ca5fb308a177989c848e6a;hb=68228ffdae8f6528dddae59bc80e77df679680f1;hp=c7bd79a01adc534bd35adac7fbf69b5c53ca7428;hpb=a7e76e2eb4601830e12aab76fcca99ed800967d7;p=yangtools.git diff --git a/parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java b/parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java index c7bd79a01a..570e7a54f6 100644 --- a/parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java +++ b/parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java @@ -13,7 +13,6 @@ import static com.google.common.base.Verify.verify; import static com.google.common.base.Verify.verifyNotNull; import static java.util.Objects.requireNonNull; -import com.google.common.base.VerifyException; import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMultimap; @@ -150,12 +149,6 @@ abstract class StatementContextBase, E extends */ private byte executionOrder; - /** - * This field should live in AbstractResumedStatement, but is placed here for memory efficiency to squat in the - * alignment shadow of {@link #bitsAight} and {@link #executionOrder}. - */ - private boolean implicitDeclaredFlag; - // TODO: we a single byte of alignment shadow left, we should think how we can use it to cache information we build // during InferredStatementContext.tryToReusePrototype(). We usually end up being routed to // copyAsChildOfImpl() -- which performs an eager instantiation and checks for changes afterwards. We should @@ -198,18 +191,12 @@ abstract class StatementContextBase, E extends } private static byte historyFlags(final CopyType copyType) { - switch (copyType) { - case ADDED_BY_AUGMENTATION: - return COPY_ADDED_BY_AUGMENTATION; - case ADDED_BY_USES: - return COPY_ADDED_BY_USES; - case ADDED_BY_USES_AUGMENTATION: - return COPY_ADDED_BY_AUGMENTATION | COPY_ADDED_BY_USES; - case ORIGINAL: - return COPY_ORIGINAL; - default: - throw new VerifyException("Unhandled type " + copyType); - } + return switch (copyType) { + case ADDED_BY_AUGMENTATION -> COPY_ADDED_BY_AUGMENTATION; + case ADDED_BY_USES -> COPY_ADDED_BY_USES; + case ADDED_BY_USES_AUGMENTATION -> COPY_ADDED_BY_AUGMENTATION | COPY_ADDED_BY_USES; + case ORIGINAL -> COPY_ORIGINAL; + }; } @Override @@ -331,13 +318,12 @@ abstract class StatementContextBase, E extends @Override public final , Z extends EffectiveStatement> - Mutable addUndeclaredSubstatement(final StatementSupport support, final X arg) { + Mutable createUndeclaredSubstatement(final StatementSupport support, final X arg) { requireNonNull(support); checkArgument(support instanceof UndeclaredStatementFactory, "Unsupported statement support %s", support); final var ret = new UndeclaredStmtCtx<>(this, support, arg); support.onStatementAdded(ret); - addEffectiveSubstatement(ret); return ret; } @@ -352,6 +338,19 @@ abstract class StatementContextBase, E extends return resized; } + static final void afterAddEffectiveSubstatement(final Mutable substatement) { + // Undeclared statements still need to have 'onDeclarationFinished()' triggered + if (substatement instanceof UndeclaredStmtCtx) { + finishDeclaration((UndeclaredStmtCtx) substatement); + } + } + + // Split out to keep generics working without a warning + private static , Z extends EffectiveStatement> void finishDeclaration( + final UndeclaredStmtCtx substatement) { + substatement.definition().onDeclarationFinished(substatement, ModelProcessingPhase.FULL_DECLARATION); + } + @Override public final void addEffectiveSubstatements(final Collection> statements) { if (!statements.isEmpty()) { @@ -433,19 +432,6 @@ abstract class StatementContextBase, E extends abstract @NonNull E createEffective(@NonNull StatementFactory factory); - /** - * Routing of the request to build an effective statement from {@link InferredStatementContext} towards the original - * definition site. This is needed to pick the correct instantiation method: for declared statements we will - * eventually land in {@link AbstractResumedStatement}, for underclared statements that will be - * {@link UndeclaredStmtCtx}. - * - * @param factory Statement factory - * @param ctx Inferred statement context, i.e. where the effective statement is instantiated - * @return Built effective stateue - */ - abstract @NonNull E createInferredEffective(@NonNull StatementFactory factory, - @NonNull InferredStatementContext ctx); - /** * Return a stream of declared statements which can be built into an {@link EffectiveStatement}, as per * {@link StmtContext#buildEffective()} contract. @@ -778,7 +764,7 @@ abstract class StatementContextBase, E extends return null; } - parent.ensureCompletedPhase(copy); + parent.ensureCompletedExecution(copy); return canReuseCurrent(copy) ? this : copy; } @@ -812,22 +798,14 @@ abstract class StatementContextBase, E extends if (implicitParent.isPresent()) { result = new UndeclaredStmtCtx(this, implicitParent.orElseThrow(), original, type); - final CopyType childCopyType; - switch (type) { - case ADDED_BY_AUGMENTATION: - childCopyType = CopyType.ORIGINAL; - break; - case ADDED_BY_USES_AUGMENTATION: - childCopyType = CopyType.ADDED_BY_USES; - break; - case ADDED_BY_USES: - case ORIGINAL: - default: - childCopyType = type; - } - + final CopyType childCopyType = switch (type) { + case ADDED_BY_AUGMENTATION -> CopyType.ORIGINAL; + case ADDED_BY_USES_AUGMENTATION -> CopyType.ADDED_BY_USES; + case ADDED_BY_USES, ORIGINAL -> type; + }; copy = new InferredStatementContext<>(result, original, childCopyType, type, targetModule); result.addEffectiveSubstatement(copy); + result.definition.onStatementAdded(result); } else { result = copy = new InferredStatementContext<>(this, original, type, type, targetModule); } @@ -877,13 +855,4 @@ abstract class StatementContextBase, E extends * @return True if {@link #allSubstatements()} and {@link #allSubstatementsStream()} would return an empty stream. */ abstract boolean hasEmptySubstatements(); - - // Note: these two are exposed for AbstractResumedStatement only - final boolean getImplicitDeclaredFlag() { - return implicitDeclaredFlag; - } - - final void setImplicitDeclaredFlag() { - implicitDeclaredFlag = true; - } }