Skip to content

Commit adee9b2

Browse files
committed
исключил невыполняющие условия
1 parent 6562946 commit adee9b2

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/RewriteMethodParameterDiagnostic.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import com.github._1c_syntax.bsl.languageserver.utils.RelatedInformation;
3535
import com.github._1c_syntax.bsl.languageserver.utils.Trees;
3636
import com.github._1c_syntax.bsl.parser.BSLParser;
37-
import com.github._1c_syntax.bsl.parser.BSLParserRuleContext;
3837
import lombok.RequiredArgsConstructor;
3938
import org.antlr.v4.runtime.tree.RuleNode;
4039
import org.antlr.v4.runtime.tree.TerminalNode;
@@ -47,7 +46,6 @@
4746
import java.util.ArrayList;
4847
import java.util.List;
4948
import java.util.Optional;
50-
import java.util.Set;
5149
import java.util.stream.Collectors;
5250
import java.util.stream.Stream;
5351

@@ -62,10 +60,6 @@
6260

6361
@RequiredArgsConstructor
6462
public class RewriteMethodParameterDiagnostic extends AbstractDiagnostic {
65-
public static final int RULE_ASSIGNMENT = BSLParser.RULE_assignment;
66-
private static final Set<Integer> ROOTS_OF_DEF_OR_REFS = Set.of(
67-
RULE_ASSIGNMENT, BSLParser.RULE_statement, BSLParser.RULE_subCodeBlock, BSLParser.RULE_fileCodeBlock
68-
);
6963
private final ReferenceIndex referenceIndex;
7064

7165
@Override
@@ -147,9 +141,9 @@ private boolean noneWritingToDefOrSelfAssign(Reference defRef, Reference nextRef
147141
final var assignment = defNode
148142
.map(TerminalNode::getParent)
149143
.filter(BSLParser.LValueContext.class::isInstance)
150-
.map(BSLParser.LValueContext.class::cast)
151-
.map(context -> Trees.getRootParent(context, ROOTS_OF_DEF_OR_REFS))
152-
.filter(rootContext -> rootContext.getRuleIndex() == RULE_ASSIGNMENT);
144+
.map(RuleNode::getParent)
145+
.filter(BSLParser.AssignmentContext.class::isInstance)
146+
.map(BSLParser.AssignmentContext.class::cast);
153147
if (assignment.isEmpty()) {
154148
return true;
155149
}
@@ -159,22 +153,20 @@ private boolean noneWritingToDefOrSelfAssign(Reference defRef, Reference nextRef
159153
if (refContext.isEmpty()){
160154
return true;
161155
}
162-
return isVarNameOnlyIntoExpression(assignment.get(), refContext);
156+
return isVarNameOnlyIntoExpression(refContext);
163157
}
164158

165-
private static boolean isVarNameOnlyIntoExpression(BSLParserRuleContext assignment, Optional<RuleNode> refContext) {
159+
private static boolean isVarNameOnlyIntoExpression(Optional<RuleNode> refContext) {
166160
return refContext
167161
.filter(BSLParser.ComplexIdentifierContext.class::isInstance)
168162
.map(BSLParser.ComplexIdentifierContext.class::cast)
169163
.filter(node -> node.getChildCount() == 1)
170164
.map(RuleNode::getParent)
171-
.filter(node -> node.getChildCount() == 1)
165+
.filter(memberContext -> memberContext.getChildCount() == 1)
172166
.filter(BSLParser.MemberContext.class::isInstance)
173167
.map(RuleNode::getParent)
174-
.filter(node -> node.getChildCount() == 1)
168+
.filter(expression -> expression.getChildCount() == 1)
175169
.filter(BSLParser.ExpressionContext.class::isInstance)
176-
.map(RuleNode::getParent)
177-
.filter(ruleNode -> ruleNode == assignment)
178170
.isPresent();
179171
}
180172

src/test/resources/diagnostics/RewriteMethodParameterDiagnostic.bsl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,3 @@
5555
Парам131 = 1 + Парам131; // не ошибка
5656
Возврат Парам131;
5757
КонецПроцедуры
58-

0 commit comments

Comments
 (0)