21
21
*/
22
22
package com .github ._1c_syntax .bsl .languageserver .diagnostics ;
23
23
24
- import com .github ._1c_syntax .bsl .languageserver .diagnostics .infrastructure .Disabled ;
25
24
import com .github ._1c_syntax .bsl .languageserver .diagnostics .metadata .DiagnosticMetadata ;
26
25
import com .github ._1c_syntax .bsl .languageserver .diagnostics .metadata .DiagnosticSeverity ;
27
26
import com .github ._1c_syntax .bsl .languageserver .diagnostics .metadata .DiagnosticTag ;
47
46
import java .util .stream .Collectors ;
48
47
import java .util .stream .Stream ;
49
48
50
- @ Disabled
51
49
@ DiagnosticMetadata (
52
50
type = DiagnosticType .ERROR ,
53
51
severity = DiagnosticSeverity .CRITICAL ,
61
59
)
62
60
public class FieldsFromJoinsWithoutIsNullDiagnostic extends AbstractSDBLVisitorDiagnostic {
63
61
64
- private static final Integer SELECT_ROOT = SDBLParser . RULE_selectedField ;
65
- private static final Collection < Integer > SELECT_STATEMENTS = Set . of ( SELECT_ROOT , SDBLParser . RULE_builtInFunctions ,
66
- SDBLParser . RULE_isNullPredicate );
62
+ // схема расчета - находится поле из соединения,
63
+ // далее идет поиск вверх по родительским узлам для проверки вхождения в разных вариациях ЕСТЬNULL или ЕСТЬ NULL
64
+ // для оптимизации ищем вверх не до начального узла всего дерева, а до узла, в котором искать уже нет смысла
67
65
68
- private static final Integer WHERE_ROOT = SDBLParser .RULE_predicate ;
69
- private static final Collection <Integer > WHERE_STATEMENTS = Set .of (WHERE_ROOT , SDBLParser . RULE_builtInFunctions ,
70
- SDBLParser .RULE_isNullPredicate );
66
+ private static final Integer EXCLUDED_TOP_RULE_FOR_SELECT = SDBLParser .RULE_selectedField ;
67
+ private static final Collection <Integer > SELECT_STATEMENTS = Set .of (EXCLUDED_TOP_RULE_FOR_SELECT ,
68
+ SDBLParser .RULE_builtInFunctions , SDBLParser . RULE_isNullPredicate );
71
69
72
- private static final Integer JOIN_ROOT = SDBLParser .RULE_joinPart ;
73
- private static final Collection <Integer > JOIN_STATEMENTS = Set .of (JOIN_ROOT , SDBLParser .RULE_builtInFunctions );
70
+ private static final Integer EXCLUDED_TOP_RULE_FOR_WHERE = SDBLParser .RULE_query ;
71
+ private static final Collection <Integer > WHERE_STATEMENTS = Set .of (EXCLUDED_TOP_RULE_FOR_WHERE ,
72
+ SDBLParser .RULE_builtInFunctions , SDBLParser .RULE_isNullPredicate );
73
+
74
+ private static final Integer EXCLUDED_TOP_RULE_FOR_JOIN = SDBLParser .RULE_joinPart ;
75
+ private static final Collection <Integer > JOIN_STATEMENTS = Set .of (EXCLUDED_TOP_RULE_FOR_JOIN ,
76
+ SDBLParser .RULE_builtInFunctions );
74
77
75
78
public static final Collection <Integer > RULES_OF_PARENT_FOR_SEARCH_CONDITION = Set .of (SDBLParser .RULE_predicate ,
76
79
SDBLParser .RULE_query );
@@ -165,7 +168,7 @@ private static boolean haveExprNotWithParens(SDBLParser.PredicateContext ctx) {
165
168
}
166
169
167
170
private void checkSelect (String tableName , SDBLParser .SelectedFieldsContext columns ) {
168
- checkStatements (tableName , columns , SELECT_STATEMENTS , SELECT_ROOT , true );
171
+ checkStatements (tableName , columns , SELECT_STATEMENTS , EXCLUDED_TOP_RULE_FOR_SELECT , true );
169
172
}
170
173
171
174
private void checkStatements (String tableName , BSLParserRuleContext expression , Collection <Integer > statements ,
@@ -223,7 +226,7 @@ private void checkWhere(String tableName, @Nullable SDBLParser.LogicalExpression
223
226
Optional .ofNullable (where )
224
227
.stream ().flatMap (searchConditionsContext -> searchConditionsContext .condidions .stream ())
225
228
.forEach (searchConditionContext -> checkStatements (tableName , searchConditionContext ,
226
- WHERE_STATEMENTS , WHERE_ROOT , true ));
229
+ WHERE_STATEMENTS , EXCLUDED_TOP_RULE_FOR_WHERE , true ));
227
230
}
228
231
229
232
private void checkAllJoins (String tableName , SDBLParser .JoinPartContext currentJoinPart ) {
@@ -233,7 +236,7 @@ private void checkAllJoins(String tableName, SDBLParser.JoinPartContext currentJ
233
236
.filter (joinPartContext -> joinPartContext != currentJoinPart )
234
237
.map (SDBLParser .JoinPartContext ::logicalExpression )
235
238
.forEach (searchConditionsContext -> checkStatements (tableName , searchConditionsContext ,
236
- JOIN_STATEMENTS , JOIN_ROOT , false ));
239
+ JOIN_STATEMENTS , EXCLUDED_TOP_RULE_FOR_JOIN , false ));
237
240
}
238
241
239
242
private List <DiagnosticRelatedInformation > getRelatedInformation (SDBLParser .JoinPartContext self ) {
0 commit comments