blob: 881e63e95fd41dbbe2cb74c748e2855e304f7890 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#include "yql_warning.h"
#include <util/string/cast.h>
#include <util/string/join.h>
namespace NYql {
TWarningRule::EParseResult TWarningRule::ParseFrom(const TString& codePattern, const TString& action,
TWarningRule& result, TString& errorMessage)
{
errorMessage.clear();
result.IssueCodePattern.clear();
result.Action = EWarningAction::DEFAULT;
if (!TryFromString<EWarningAction>(to_upper(action), result.Action)) {
errorMessage = "unknown warning action '" + action + "', expecting one of " +
Join(", ", EWarningAction::DEFAULT, EWarningAction::ERROR, EWarningAction::DISABLE);
return EParseResult::PARSE_ACTION_FAIL;
}
if (codePattern != "*") {
ui32 code;
if (!TryFromString(codePattern, code)) {
errorMessage = "unknown warning code '" + codePattern + "', expecting integer or '*'";
return EParseResult::PARSE_PATTERN_FAIL;
}
}
result.IssueCodePattern = codePattern;
return EParseResult::PARSE_OK;
}
void TWarningPolicy::AddRule(const TWarningRule& rule)
{
TString pattern = rule.GetPattern();
if (pattern.empty()) {
return;
}
Rules.push_back(rule);
EWarningAction action = rule.GetAction();
if (pattern == "*") {
BaseAction = action;
Overrides.clear();
return;
}
TIssueCode code;
Y_ENSURE(TryFromString(pattern, code));
if (action == BaseAction) {
Overrides.erase(Overrides.find(code));
} else {
Overrides[code] = action;
}
}
EWarningAction TWarningPolicy::GetAction(TIssueCode code) const
{
auto it = Overrides.find(code);
return (it == Overrides.end()) ? BaseAction : it->second;
}
void TWarningPolicy::Clear()
{
BaseAction = EWarningAction::DEFAULT;
Overrides.clear();
Rules.clear();
}
}
|