Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,22 @@ private void checkColumnNode(SDBLParser.ColumnContext ctx, Set<String> tableName
String penultimateIdentifierName = penultimateChild.getText();

if (REF_PATTERN.matcher(penultimateIdentifierName).matches()
&& !penultimateIdentifierParentIsTabularSection(ctx)
|| (REF_PATTERN.matcher(lastIdentifierName).matches()
&& !tableNames.contains(penultimateIdentifierName))) {
diagnosticStorage.addDiagnostic(ctx);
}
}

private boolean penultimateIdentifierParentIsTabularSection(SDBLParser.ColumnContext ctx) {
var penultimateChildTable = ctx.getChild(0);
var penultimateChildTableName = penultimateChildTable.getText();

return this.dataSourceCollection.stream()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this лишний

.filter(dataSource -> dataSource.getChild(0).getChildCount() > 2)
.anyMatch(dataSource -> dataSource.getChild(1).getChild(1).getText().matches(penultimateChildTableName));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ovcharenko-di возможно, стоит рассмотреть возможность предварительной подготовки доп.коллекции из dataSourceCollection

чтобы для каждого имя реквизита не выполнять повторный и ненужный поиск
dataSourceCollection.stream()
.filter(dataSource -> dataSource.getChild(0).getChildCount() > 2)
.anyMatch((dataSource -> dataSource.getChild(1).getChild(1))

например, отдельный список нужных детей

}

private static String getTableNameOrAlias(ParseTree dataSource) {
return Optional.of(dataSource)
.flatMap(dataSrc -> extractTextFromChild(dataSrc, SDBLParser.RULE_alias))
Expand Down
13 changes: 12 additions & 1 deletion src/test/resources/diagnostics/RefOveruseDiagnostic.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,21 @@
| Контрагенты.Ссылка.ИНН = &ИНН"; // ошибка
КонецПроцедуры

Процедура Тест17()
Процедура Тест16()
ТекстЗапроса =
"ВЫБРАТЬ
| Артикул КАК Артикул // не задано имя таблицы
|ИЗ
| Справочник.Номенклатура КАК Номенклатура";
КонецПроцедуры

Процедура Тест17()
ТекстЗапроса =
"ВЫБРАТЬ
| ДопРеквизиты.Свойство КАК Свойство
|ИЗ
| Справочник.Номенклатура.ДополнительныеРеквизиты КАК ДопРеквизиты
|ГДЕ
| НЕ ДопРеквизиты.Ссылка.ПометкаУдаления";
КонецПроцедуры