26
26
import com .github ._1c_syntax .bsl .languageserver .diagnostics .metadata .DiagnosticSeverity ;
27
27
import com .github ._1c_syntax .bsl .languageserver .diagnostics .metadata .DiagnosticTag ;
28
28
import com .github ._1c_syntax .bsl .languageserver .diagnostics .metadata .DiagnosticType ;
29
+ import com .github ._1c_syntax .bsl .languageserver .utils .DiagnosticHelper ;
29
30
import com .github ._1c_syntax .utils .CaseInsensitivePattern ;
30
31
31
32
import java .util .HashSet ;
@@ -68,8 +69,7 @@ public class IncorrectLineBreakDiagnostic extends AbstractDiagnostic {
68
69
type = String .class ,
69
70
defaultValue = "" + DEFAULT_LIST_FOR_CHECK_START
70
71
)
71
- private String listOfIncorrectFirstSymbol = DEFAULT_LIST_FOR_CHECK_START ;
72
- private Pattern INCORRECT_START_LINE_PATTERN = getPatternSearch ("^\\ s*(:?" , listOfIncorrectFirstSymbol , ")" );
72
+ private Pattern listOfIncorrectFirstSymbol = createPatternIncorrectStartLine (DEFAULT_LIST_FOR_CHECK_START );
73
73
74
74
@ DiagnosticParameter (
75
75
type = Boolean .class ,
@@ -81,22 +81,18 @@ public class IncorrectLineBreakDiagnostic extends AbstractDiagnostic {
81
81
type = String .class ,
82
82
defaultValue = "" + DEFAULT_LIST_FOR_CHECK_END
83
83
)
84
- private String listOfIncorrectLastSymbol = DEFAULT_LIST_FOR_CHECK_END ;
85
- private Pattern INCORRECT_END_LINE_PATTERN = getPatternSearch ("\\ s+(:?" , listOfIncorrectLastSymbol , ")\\ s*(?://.*)?$" );
84
+ private Pattern listOfIncorrectLastSymbol = createPatternIncorrectEndLine (DEFAULT_LIST_FOR_CHECK_END );
86
85
87
86
@ Override
88
87
public void configure (Map <String , Object > configuration ) {
89
-
90
- super .configure (configuration );
91
-
92
- listOfIncorrectFirstSymbol = (String ) configuration .getOrDefault ("listOfIncorrectFirstSymbol" , DEFAULT_LIST_FOR_CHECK_START );
93
- listOfIncorrectLastSymbol = (String ) configuration .getOrDefault ("listOfIncorrectLastSymbol" , DEFAULT_LIST_FOR_CHECK_END );
94
- INCORRECT_START_LINE_PATTERN = getPatternSearch ("^\\ s*(:?" , listOfIncorrectFirstSymbol , ")" );
95
- INCORRECT_END_LINE_PATTERN = getPatternSearch ("\\ s+(:?" , listOfIncorrectLastSymbol , ")\\ s*(?://.*)?$" );
96
- }
97
-
98
- private static Pattern getPatternSearch (String StartPattern , String SearchSymbols , String EndPattern ) {
99
- return CaseInsensitivePattern .compile (StartPattern + SearchSymbols + EndPattern );
88
+ DiagnosticHelper .configureDiagnostic (this , configuration , "checkFirstSymbol" , "checkLastSymbol" );
89
+
90
+ listOfIncorrectFirstSymbol = createPatternIncorrectStartLine (
91
+ (String ) configuration .getOrDefault ("listOfIncorrectFirstSymbol" , DEFAULT_LIST_FOR_CHECK_START )
92
+ );
93
+ listOfIncorrectLastSymbol = createPatternIncorrectEndLine (
94
+ (String ) configuration .getOrDefault ("listOfIncorrectLastSymbol" , DEFAULT_LIST_FOR_CHECK_END )
95
+ );
100
96
}
101
97
102
98
@ Override
@@ -105,10 +101,10 @@ protected void check() {
105
101
findQueryFirstLines ();
106
102
107
103
if (checkFirstSymbol ){
108
- checkContent (INCORRECT_START_LINE_PATTERN );
104
+ checkContent (listOfIncorrectFirstSymbol );
109
105
}
110
106
if (checkLastSymbol ) {
111
- checkContent (INCORRECT_END_LINE_PATTERN );
107
+ checkContent (listOfIncorrectLastSymbol );
112
108
}
113
109
}
114
110
@@ -130,4 +126,24 @@ private void checkContent(Pattern pattern) {
130
126
}
131
127
}
132
128
}
129
+
130
+ private static Pattern getPatternSearch (String startPattern , String searchSymbols , String endPattern ) {
131
+ return CaseInsensitivePattern .compile (startPattern + searchSymbols + endPattern );
132
+ }
133
+
134
+ private static Pattern createPatternIncorrectStartLine (String listOfSymbols ) {
135
+ return getPatternSearch (
136
+ "^\\ s*(:?" ,
137
+ listOfSymbols ,
138
+ ")"
139
+ );
140
+ }
141
+
142
+ private static Pattern createPatternIncorrectEndLine (String listOfSymbols ) {
143
+ return getPatternSearch (
144
+ "\\ s+(:?" ,
145
+ listOfSymbols ,
146
+ ")\\ s*(?://.*)?$"
147
+ );
148
+ }
133
149
}
0 commit comments