Skip to content

Commit

Permalink
Merge pull request #3041 from 1c-syntax/fix/unusedparameters-npe
Browse files Browse the repository at this point in the history
#3040 npe fix
  • Loading branch information
nixel2007 authored Apr 17, 2023
2 parents bffba9c + 8af25b1 commit 35f6c0a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.github._1c_syntax.bsl.parser.BSLParser;
import com.github._1c_syntax.utils.CaseInsensitivePattern;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.TerminalNode;

import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -62,9 +63,16 @@ public ParseTree visitSubCodeBlock(BSLParser.SubCodeBlockContext ctx) {
return ctx;
}

List<String> paramsNames = Trees.findAllRuleNodes(ctx.getParent(), BSLParser.RULE_param)
List<TerminalNode> params = Trees.findAllRuleNodes(ctx.getParent(), BSLParser.RULE_param)
.stream()
.map(node -> ((BSLParser.ParamContext) node).IDENTIFIER().getText().toLowerCase(Locale.getDefault()))
.map(BSLParser.ParamContext.class::cast)
.map(BSLParser.ParamContext::IDENTIFIER)
.filter(Objects::nonNull)
.collect(Collectors.toList());

List<String> paramsNames = params
.stream()
.map(ind -> ind.getText().toLowerCase(Locale.getDefault()))
.collect(Collectors.toList());

Trees.findAllTokenNodes(ctx, BSLParser.IDENTIFIER)
Expand All @@ -74,9 +82,8 @@ public ParseTree visitSubCodeBlock(BSLParser.SubCodeBlockContext ctx) {
paramsNames.remove((node.getText().toLowerCase(Locale.getDefault())))
);

Trees.findAllRuleNodes(ctx.getParent(), BSLParser.RULE_param)
params
.stream()
.map(param -> ((BSLParser.ParamContext) param).IDENTIFIER())
.filter(param -> paramsNames.contains(param.getText().toLowerCase(Locale.getDefault())))
.forEach(param ->
diagnosticStorage.addDiagnostic(param, info.getMessage(param.getText()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@
Объект.Поле = 1;
Объект2.Поле.Метод(2);
Чтото[Объект3];
КонецПроцедуры
КонецПроцедуры

Процедура нпе( , знач "")
Объект.Поле = 1;
КонецПроцедуры

0 comments on commit 35f6c0a

Please sign in to comment.