-
Notifications
You must be signed in to change notification settings - Fork 112
Границы обращения к метаданным #1837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 1 commit
cd9ef8b
768ab7d
ea1e7dd
b17d97f
2bc45e1
f06515a
65557a8
fdad879
8912ca2
36f4e78
f05deaa
1248793
1379891
84e4d9d
7171d3f
239f1c0
5ce7014
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,35 +59,35 @@ public class MetadataBordersDiagnostic extends AbstractVisitorDiagnostic { | |
type = String.class, | ||
defaultValue = "" | ||
) | ||
private Map<Pattern, Pattern> metadataBordersParameters = MapFromJSON(METADATA_BORDERS_DEFAULT); | ||
private Map<Pattern, Pattern> metadataBordersParameters = mapFromJSON(METADATA_BORDERS_DEFAULT); | ||
|
||
private List<Pattern> statementPatterns = Collections.emptyList(); | ||
|
||
private static Map<Pattern, Pattern> MapFromJSON(String userSettings) { | ||
private static Map<Pattern, Pattern> mapFromJSON(String userSettings) { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. создание ObjectMapper на каждый configure - довольно дорогая операция. лучше его закэшировать или просто указать его конструкторе - его туда подложит спринг. |
||
MapType mapType = mapper.getTypeFactory().constructMapType(HashMap.class, String.class, String.class); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mapType тоже можно закэшировать в конструторе по принятому инстансу обджект-маппера |
||
try { | ||
Map<String, String> stringMap = mapper.readValue(userSettings, mapType); | ||
return stringMap.entrySet().stream() | ||
.filter(entry -> ! entry.getKey().isBlank() && ! entry.getValue().isBlank()) | ||
.filter(entry -> !entry.getKey().isBlank() && !entry.getValue().isBlank()) | ||
.collect(Collectors.toMap( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. пробовал делать включать замер производительности? диагностика не вырывается в топ? |
||
entry -> CaseInsensitivePattern.compile(entry.getKey()), | ||
entry -> CaseInsensitivePattern.compile(entry.getValue()))); | ||
entry -> CaseInsensitivePattern.compile(entry.getKey()), | ||
entry -> CaseInsensitivePattern.compile(entry.getValue()))); | ||
} catch (JsonProcessingException e) { | ||
return Collections.emptyMap(); | ||
} | ||
} | ||
|
||
@Override | ||
public void configure(Map<String, Object> configuration) { | ||
metadataBordersParameters = MapFromJSON( | ||
metadataBordersParameters = mapFromJSON( | ||
(String) configuration.getOrDefault("metadataBordersParameters", METADATA_BORDERS_DEFAULT)); | ||
} | ||
|
||
@Override | ||
public ParseTree visitFile(BSLParser.FileContext ctx) { | ||
statementPatterns = metadataBordersParameters.entrySet().stream() | ||
.filter(entry -> ! entry.getValue().matcher(this.documentContext.getUri().getPath()).find()) | ||
.filter(entry -> ! entry.getValue().matcher(documentContext.getUri().getPath()).find()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. а почему пути к файлам используются? почему не mdoRef? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ну и стоит проверять заполненность statementPatterns: для пустой делать возврат и не греть воздух There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
вообще у нее scope захватывает OS, а для оскрипта mdoRef сейчас выглядит в виде uri. с другой стороны, вряд ли ее кто-то будет включать на os There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. таки да. по-хорошему, если делать универсальненько и для людей, то надо вообще переделать, как Никита предлагал в телеге - на вхождение в подсистему. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
это сделано при формировании мапы паттернов. из стринговой мапы в мапу щаблонов попадают только те элементы, в которых и ключ, и значение не пустые |
||
.map(Map.Entry::getKey) | ||
.collect(Collectors.toList()); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
diagnosticMessage=Use metadata outside the borders | ||
diagnosticName=Metadata borders | ||
metadataBordersParameters=JSON-structure for pairs "regex for statements":"regex for module names". | ||
metadataBordersParameters={"regex for statements":"regex for module names"} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
diagnosticMessage=Обращение к метаданным за пределами разрешенных границ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. может быть в сообщение стоит добавить регулярку/пару регулярок, на которой произошло срабатывание? |
||
diagnosticName=Границы метаданных | ||
metadataBordersParameters=JSON-структура для пар "регулярное выражение для операторов":"регулярное выражение для имени файла модуля" | ||
metadataBordersParameters={"регулярное выражение для операторов":"регулярное выражение для имени файла модуля"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
стало еще менее понятно :(
Предлагаю что-то вроде:
Пускай пример будет прям в описании параметра, упростит понимание.