From fe7aa9a567521a2aac3caf3f1076a263e1cdc6b4 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 3 May 2022 17:41:20 +0200 Subject: [PATCH] Use switch expressions for CopyType dispatch We have exhaustive switch statements here, use expressions to make that clear to the compiler -- improving density and ditching default case. Change-Id: I5ff3d4de11b39809ba209a70515fccc742ef8e03 Signed-off-by: Robert Varga --- .../stmt/reactor/StatementContextBase.java | 38 ++++++------------- 1 file changed, 11 insertions(+), 27 deletions(-) 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 7e4f2bca1b..d3ce39b693 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; @@ -192,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 @@ -805,20 +798,11 @@ 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); -- 2.36.6