Skip to content

Commit

Permalink
Поправил замечания sonarqube
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPCRus committed Nov 23, 2023
1 parent deecc29 commit 2fd0f7d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,15 @@

import com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol;
import com.github._1c_syntax.bsl.languageserver.context.symbol.ParameterDefinition;
import com.github._1c_syntax.bsl.languageserver.context.symbol.description.MethodDescription;
import com.github._1c_syntax.bsl.languageserver.context.symbol.description.ParameterDescription;
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticMetadata;
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticParameter;
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticSeverity;
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticTag;
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticType;
import org.apache.commons.collections4.map.CaseInsensitiveMap;

import com.github._1c_syntax.utils.CaseInsensitivePattern;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
import java.util.stream.Collectors;

import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -59,37 +49,37 @@ public class ReservedParameterNamesDiagnostic extends AbstractSymbolTreeDiagnost

private static final String RESERVED_WORDS_DEFAULT = "";

@DiagnosticParameter(
type = String.class,
defaultValue = RESERVED_WORDS_DEFAULT
)
@DiagnosticParameter(type = String.class)
private Pattern reservedWords = CaseInsensitivePattern.compile(RESERVED_WORDS_DEFAULT);

@Override
public void configure(Map<String, Object> configuration) {
this.reservedWords = CaseInsensitivePattern.compile("^" + (String) configuration.getOrDefault("reservedWords", RESERVED_WORDS_DEFAULT) + "$");

this.reservedWords = CaseInsensitivePattern.compile("^"
+ (String) configuration.getOrDefault("reservedWords", RESERVED_WORDS_DEFAULT)
+ "$");
}

@Override
public void visitMethod(MethodSymbol methodSymbol) {

if (reservedWords.pattern().isBlank()) {
return;
}

List<ParameterDefinition> parameters = methodSymbol.getParameters();
checkParameterName(methodSymbol, parameters);
checkParameterName(parameters);
}

private void checkParameterName(MethodSymbol methodSymbol,
List<ParameterDefinition> parameters) {
private void checkParameterName(List<ParameterDefinition> parameters) {

parameters.forEach((ParameterDefinition parameter) -> {

Matcher matcher = reservedWords.matcher(parameter.getName());
var matcher = reservedWords.matcher(parameter.getName());
if (matcher.find()) {
diagnosticStorage.addDiagnostic(parameter.getRange(), info.getMessage(parameter.getName()));
}
});
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ReservedParameterNamesDiagnosticTest extends AbstractDiagnosticTest<Reserv
void test() {

List<Diagnostic> diagnostics = getDiagnostics();
assertThat(diagnostics).hasSize(0);
assertThat(diagnostics).isEmpty();

}

Expand Down Expand Up @@ -66,7 +66,7 @@ void testConfigureNegative() {
diagnosticInstance.configure(configuration);

List<Diagnostic> diagnostics = getDiagnostics();
assertThat(diagnostics).hasSize(0);
assertThat(diagnostics).isEmpty();

}

Expand All @@ -78,7 +78,7 @@ void testConfigureNegative2() {
diagnosticInstance.configure(configuration);

List<Diagnostic> diagnostics = getDiagnostics();
assertThat(diagnostics).hasSize(0);
assertThat(diagnostics).isEmpty();

}

Expand Down

0 comments on commit 2fd0f7d

Please sign in to comment.