diff --git a/src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java b/src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java index b0f4df368f8..85cb1298e90 100644 --- a/src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java +++ b/src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java @@ -71,16 +71,6 @@ public class MagicDateDiagnostic extends AbstractVisitorDiagnostic { ) private final Set authorizedDates = new HashSet<>(Arrays.asList(DEFAULT_AUTHORIZED_DATES.split(","))); - @Override - public void configure(Map configuration) { - var authorizedDatesString = (String) configuration.getOrDefault("authorizedDates", DEFAULT_AUTHORIZED_DATES); - Set authD = Arrays.stream(authorizedDatesString.split(",")) - .map(String::trim) - .collect(Collectors.toSet()); - authorizedDates.clear(); - authorizedDates.addAll(authD); - } - private static Optional getExpression(Optional contextOptional) { return contextOptional .map(BSLParserRuleContext::getParent) @@ -119,28 +109,36 @@ private static boolean insideAssignmentWithDateMethodForSimpleDate(Optional configuration) { + var authorizedDatesString = (String) configuration.getOrDefault("authorizedDates", DEFAULT_AUTHORIZED_DATES); + Set authD = Arrays.stream(authorizedDatesString.split(",")) + .map(String::trim) + .collect(Collectors.toSet()); + authorizedDates.clear(); + authorizedDates.addAll(authD); + } + @Override public ParseTree visitConstValue(BSLParser.ConstValueContext ctx) { var tNode = ctx.DATETIME(); var sNode = ctx.string(); if ((tNode != null || sNode != null) && isAccepted(ctx)) { - var contextOptional = Optional.of(ctx); - if (sNode != null) { - contextOptional = contextOptional - .filter(constValueContext -> paramPattern.matcher(constValueContext.getText()).matches()); + if (sNode != null && !paramPattern.matcher(ctx.getText()).matches()) { + return defaultResult(); } - final var expressionContext = getExpression(contextOptional); + final var expressionContext = getExpression(Optional.of(ctx)); if (!insideSimpleDateAssignment(expressionContext) && !insideAssignmentWithDateMethodForSimpleDate(expressionContext)) { diagnosticStorage.addDiagnostic(ctx, info.getMessage(ctx.getText())); } } - return ctx; + return defaultResult(); } - private boolean isAccepted(BSLParserRuleContext ctx) { + private boolean isAccepted(BSLParser.ConstValueContext ctx) { String text = ctx.getText(); return text != null && !text.isEmpty() && !isExcluded(text); } diff --git a/src/test/resources/diagnostics/MagicDateDiagnostic.bsl b/src/test/resources/diagnostics/MagicDateDiagnostic.bsl index 7f47f947fcd..cc1fd04b908 100644 --- a/src/test/resources/diagnostics/MagicDateDiagnostic.bsl +++ b/src/test/resources/diagnostics/MagicDateDiagnostic.bsl @@ -18,3 +18,8 @@ Настройки = Настройки('12350101'); // замечание Настройки.Свойство("00020501121314", ЗначениеЕдиничногоПараметра); // замечание Выполнить("00020501121314" + '12350101'); // замечание + +Значение = Метод("%1/%2"); +Если Условие Тогда + ВызватьИсключение "Не указано значение константы ХХХ"; +КонецЕсли; \ No newline at end of file