From e542d1bc5f4869107ab9b455f72675eb48eee7dd Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 4 Jan 2024 10:53:18 +0100 Subject: [PATCH] Move message formatting to StatementSourceException It would be nice to have consistent formatting relevant things -- and SourceException already does something nice for typing message and source together. JIRA: YANGTOOLS-1150 Change-Id: Ib4b941fe4035edf887d9644a6b68570747b9d937 Signed-off-by: Robert Varga --- .../yang/model/api/meta/StatementSourceException.java | 11 +++++++---- .../yang/parser/spi/source/SourceException.java | 10 ++-------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/meta/StatementSourceException.java b/model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/meta/StatementSourceException.java index 9f05648018..324d16858a 100644 --- a/model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/meta/StatementSourceException.java +++ b/model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/meta/StatementSourceException.java @@ -27,20 +27,23 @@ public class StatementSourceException extends RuntimeException { private final @NonNull StatementSourceReference sourceRef; public StatementSourceException(final StatementSourceReference sourceRef, final String message) { - super(message); + super(createMessage(sourceRef, message)); this.sourceRef = requireNonNull(sourceRef); } public StatementSourceException(final StatementSourceReference sourceRef, final String message, final Throwable cause) { - super(message, cause); + super(createMessage(sourceRef, message), cause); this.sourceRef = requireNonNull(sourceRef); } public StatementSourceException(final StatementSourceReference sourceRef, final String format, final Object... args) { - super(format.formatted(args)); - this.sourceRef = requireNonNull(sourceRef); + this(sourceRef, format.formatted(args)); + } + + private static String createMessage(final StatementSourceReference sourceRef, final String message) { + return requireNonNull(message) + " [at " + requireNonNull(sourceRef) + ']'; } /** diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/SourceException.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/SourceException.java index 7bc37cff85..ec3ce2ab72 100644 --- a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/SourceException.java +++ b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/SourceException.java @@ -7,8 +7,6 @@ */ package org.opendaylight.yangtools.yang.parser.spi.source; -import static java.util.Objects.requireNonNull; - import java.util.Optional; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; @@ -31,7 +29,7 @@ public class SourceException extends StatementSourceException { * @param sourceRef Statement source */ public SourceException(final @NonNull String message, final @NonNull StatementSourceReference sourceRef) { - super(sourceRef, createMessage(message, sourceRef)); + super(sourceRef, message); } /** @@ -44,7 +42,7 @@ public class SourceException extends StatementSourceException { */ public SourceException(final @NonNull String message, final @NonNull StatementSourceReference sourceRef, final Throwable cause) { - super(sourceRef, createMessage(message, sourceRef), cause); + super(sourceRef, message, cause); } /** @@ -228,8 +226,4 @@ public class SourceException extends StatementSourceException { throwIf(opt.isEmpty(), stmt, format, args); return opt.orElseThrow(); } - - private static String createMessage(final @NonNull String message, final @NonNull StatementSourceReference source) { - return requireNonNull(message) + " [at " + requireNonNull(source) + ']'; - } } -- 2.36.6