Skip to content

Commit b7bd706

Browse files
Copilotnixel2007
andcommitted
Fix jspecify issues: use Optional instead of null returns
- Changed extractMethodNameFromModifier to return Optional<String> - Refactored hasMatchingModifierMethodCall to use stream API - Refactored extractModuleNameFromMatchingModifier to use map-chain - Added explicit import for TerminalNode - Added package-info.java with @NullMarked for configuration.references All 24 tests pass. Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com>
1 parent 277132d commit b7bd706

File tree

2 files changed

+47
-37
lines changed

2 files changed

+47
-37
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* This file is a part of BSL Language Server.
3+
*
4+
* Copyright (c) 2018-2025
5+
* Alexey Sosnoviy <labotamy@gmail.com>, Nikita Fedkin <nixel2007@gmail.com> and contributors
6+
*
7+
* SPDX-License-Identifier: LGPL-3.0-or-later
8+
*
9+
* BSL Language Server is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 3.0 of the License, or (at your option) any later version.
13+
*
14+
* BSL Language Server is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with BSL Language Server.
21+
*/
22+
/**
23+
* Пакет содержит настройки для построения индекса ссылок.
24+
*/
25+
@NullMarked
26+
package com.github._1c_syntax.bsl.languageserver.configuration.references;
27+
28+
import org.jspecify.annotations.NullMarked;

src/main/java/com/github/_1c_syntax/bsl/languageserver/utils/ModuleReference.java

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.github._1c_syntax.bsl.types.ModuleType;
2727
import lombok.NonNull;
2828
import lombok.experimental.UtilityClass;
29+
import org.antlr.v4.runtime.tree.TerminalNode;
2930

3031
import java.util.List;
3132
import java.util.Locale;
@@ -205,32 +206,17 @@ private static boolean hasMatchingModifierMethodCall(
205206
String moduleName,
206207
List<String> commonModuleAccessors
207208
) {
208-
for (var modifier : complexId.modifier()) {
209-
var methodName = extractMethodNameFromModifier(modifier);
210-
if (methodName != null && isModuleMethodMatch(methodName, moduleName, commonModuleAccessors)) {
211-
return true;
212-
}
213-
}
214-
return false;
209+
return complexId.modifier().stream()
210+
.flatMap(modifier -> extractMethodNameFromModifier(modifier).stream())
211+
.anyMatch(methodName -> isModuleMethodMatch(methodName, moduleName, commonModuleAccessors));
215212
}
216213

217-
private static String extractMethodNameFromModifier(BSLParser.ModifierContext modifier) {
218-
var accessCall = modifier.accessCall();
219-
if (accessCall == null) {
220-
return null;
221-
}
222-
223-
var methodCall = accessCall.methodCall();
224-
if (methodCall == null) {
225-
return null;
226-
}
227-
228-
var methodName = methodCall.methodName();
229-
if (methodName == null || methodName.IDENTIFIER() == null) {
230-
return null;
231-
}
232-
233-
return methodName.IDENTIFIER().getText();
214+
private static Optional<String> extractMethodNameFromModifier(BSLParser.ModifierContext modifier) {
215+
return Optional.ofNullable(modifier.accessCall())
216+
.map(BSLParser.AccessCallContext::methodCall)
217+
.map(BSLParser.MethodCallContext::methodName)
218+
.map(BSLParser.MethodNameContext::IDENTIFIER)
219+
.map(TerminalNode::getText);
234220
}
235221

236222
private static Optional<String> extractCommonModuleNameFromMember(
@@ -267,19 +253,15 @@ private static Optional<String> extractModuleNameFromMatchingModifier(
267253
String moduleName,
268254
List<String> commonModuleAccessors
269255
) {
270-
for (var modifier : complexId.modifier()) {
271-
var accessCall = modifier.accessCall();
272-
if (accessCall == null || accessCall.methodCall() == null) {
273-
continue;
274-
}
275-
276-
var methodCall = accessCall.methodCall();
277-
var methodName = extractMethodNameFromModifier(modifier);
278-
if (methodName != null && isModuleMethodMatch(methodName, moduleName, commonModuleAccessors)) {
279-
return extractParameterFromDoCall(methodCall.doCall());
280-
}
281-
}
282-
return Optional.empty();
256+
return complexId.modifier().stream()
257+
.filter(modifier -> extractMethodNameFromModifier(modifier)
258+
.filter(methodName -> isModuleMethodMatch(methodName, moduleName, commonModuleAccessors))
259+
.isPresent())
260+
.findFirst()
261+
.flatMap(modifier -> Optional.ofNullable(modifier.accessCall())
262+
.map(BSLParser.AccessCallContext::methodCall)
263+
.map(BSLParser.MethodCallContext::doCall)
264+
.flatMap(ModuleReference::extractParameterFromDoCall));
283265
}
284266

285267
private static Optional<String> extractModuleNameFromGlobalMethodCall(

0 commit comments

Comments
 (0)