Skip to content

Commit

Permalink
ошибочно обрабатывались строки
Browse files Browse the repository at this point in the history
  • Loading branch information
artbear committed Dec 14, 2023
1 parent 9858fb7 commit 76ddd28
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,6 @@ public class MagicDateDiagnostic extends AbstractVisitorDiagnostic {
)
private final Set<String> authorizedDates = new HashSet<>(Arrays.asList(DEFAULT_AUTHORIZED_DATES.split(",")));

@Override
public void configure(Map<String, Object> configuration) {
var authorizedDatesString = (String) configuration.getOrDefault("authorizedDates", DEFAULT_AUTHORIZED_DATES);
Set<String> authD = Arrays.stream(authorizedDatesString.split(","))
.map(String::trim)
.collect(Collectors.toSet());
authorizedDates.clear();
authorizedDates.addAll(authD);
}

private static Optional<BSLParserRuleContext> getExpression(Optional<BSLParser.ConstValueContext> contextOptional) {
return contextOptional
.map(BSLParserRuleContext::getParent)
Expand Down Expand Up @@ -119,28 +109,36 @@ private static boolean insideAssignmentWithDateMethodForSimpleDate(Optional<BSLP
.isPresent();
}

@Override
public void configure(Map<String, Object> configuration) {
var authorizedDatesString = (String) configuration.getOrDefault("authorizedDates", DEFAULT_AUTHORIZED_DATES);
Set<String> 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);
}
Expand Down
5 changes: 5 additions & 0 deletions src/test/resources/diagnostics/MagicDateDiagnostic.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@
Настройки = Настройки('12350101'); // замечание
Настройки.Свойство("00020501121314", ЗначениеЕдиничногоПараметра); // замечание
Выполнить("00020501121314" + '12350101'); // замечание

Значение = Метод("%1/%2");
Если Условие Тогда
ВызватьИсключение "Не указано значение константы ХХХ";
КонецЕсли;

0 comments on commit 76ddd28

Please sign in to comment.