Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,7 @@ dependencies {
api("org.eclipse.lsp4j", "org.eclipse.lsp4j.websocket.jakarta", "0.24.0")

// 1c-syntax
api("io.github.1c-syntax", "bsl-parser", "0.30.0") {
exclude("com.ibm.icu", "*")
exclude("org.antlr", "ST4")
exclude("org.antlr", "antlr-runtime")
}
api("io.github.1c-syntax", "bsl-parser", "0.31.0-rc.1")
Comment thread
nixel2007 marked this conversation as resolved.
api("io.github.1c-syntax", "utils", "0.6.9")
api("io.github.1c-syntax", "mdclasses", "0.17.4")
api("io.github.1c-syntax", "bsl-common-library", "0.9.2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private CompletableFuture<MessageActionItem> askUserForPermission(LanguageClient
return languageClient.showMessageRequest(requestParams);
}

@Nullable private MessageActionItem waitForPermission(CompletableFuture<MessageActionItem> sendQuestion) {
private @Nullable MessageActionItem waitForPermission(CompletableFuture<MessageActionItem> sendQuestion) {
try {
return sendQuestion.get();
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import io.sentry.protocol.Geo;
import io.sentry.protocol.User;
import lombok.RequiredArgsConstructor;
import org.eclipse.lsp4j.ClientInfo;
import org.eclipse.lsp4j.ServerInfo;
import org.jspecify.annotations.Nullable;
import org.springframework.boot.context.event.ApplicationReadyEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public ControlFlowGraph buildGraph(BSLParser.CodeBlockContext block) {
// Если это тело модуля, то самую первую инструкцию препроцессора сожрет грамматика file
// надо ее тоже посетить принудительно.
var parent = block.getParent();
if (parent instanceof BSLParser.FileCodeBlockContext fileBlock) {
if (parent instanceof BSLParser.FileCodeBlockContext fileBlock && fileBlock.getParent() != null) {
var probablyPreprocessor = Trees.getPreviousNode(fileBlock.getParent(), fileBlock,
BSLParser.RULE_preprocessor);

Expand Down Expand Up @@ -210,15 +210,15 @@ public ParseTree visitElsifBranch(BSLParser.ElsifBranchContext ctx) {
if (currentIfBlock == null) {
throw new IllegalStateException(
"Cannot process elsif branch: there is no active condition block. " +
"This may occur when preprocessor directives modify the block stack.");
"This may occur when preprocessor directives modify the block stack.");
}

var buildParts = currentIfBlock.getBuildParts();
if (buildParts.isEmpty()) {
throw new IllegalStateException(
"Cannot process elsif branch: build parts stack is empty. " +
"Expected previous condition on stack. " +
"This may occur when preprocessor conditions modify the stack inside if statement body.");
"Expected previous condition on stack. " +
"This may occur when preprocessor conditions modify the stack inside if statement body.");
}
var previousCondition = buildParts.pop();

Expand Down Expand Up @@ -256,7 +256,7 @@ public ParseTree visitElseBranch(BSLParser.ElseBranchContext ctx) {
if (currentIfBlock == null) {
throw new IllegalStateException(
"Cannot process else branch: there is no active condition block. " +
"This may occur when preprocessor directives modify the block stack.");
"This may occur when preprocessor directives modify the block stack.");
}
var condition = currentIfBlock.getBuildParts().pop();
graph.addEdge(condition, block.begin(), CfgEdgeType.FALSE_BRANCH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Predicate;

/**
Expand Down Expand Up @@ -85,7 +86,7 @@ public List<CodeAction> getCodeActions(CodeActionParams params, DocumentContext

var parameters = maybeDoCall
.map(BSLParser.DoCallContext::callParamList)
.map(callParamListContext -> callParamListContext.children)
.map(ParserRuleContext::getChildren)
.orElse(Collections.emptyList())
.stream()
.filter(Predicate.not(TerminalNode.class::isInstance))
Expand Down Expand Up @@ -163,9 +164,14 @@ public List<CodeAction> getCodeActions(CodeActionParams params, DocumentContext
}

private static boolean isParentAssignment(BSLParser.DoCallContext doCall, BSLParser.AssignmentContext assignment) {
return assignment.expression().member().stream()
var expression = assignment.expression();
if (expression == null) {
return false;
}
return expression.member().stream()
.map(BSLParser.MemberContext::complexIdentifier)
.map(BSLParser.ComplexIdentifierContext::newExpression)
.map(ctx -> ctx != null ? ctx.newExpression() : null)
.filter(Objects::nonNull)
.filter(newExpressionContext -> newExpressionContext == doCall.getParent())
.findAny().isEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private Optional<ParserRuleContext> checkElseIfClauseExitingNode(ConditionalVert

var expression = v.getExpression();
if (expression.getParent() instanceof BSLParser.ElsifBranchContext elsifBranch && !ignoreMissingElseOnExit) {
return Optional.of(elsifBranch.getParent());
return Optional.ofNullable(elsifBranch.getParent());
}

return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticType;
import com.github._1c_syntax.bsl.parser.SDBLParser;
import org.antlr.v4.runtime.tree.ParseTree;
import org.jspecify.annotations.Nullable;

@DiagnosticMetadata(
type = DiagnosticType.CODE_SMELL,
Expand All @@ -44,9 +45,9 @@
public class AssignAliasFieldsInQueryDiagnostic extends AbstractSDBLVisitorDiagnostic {

@Override
public ParseTree visitQuery(SDBLParser.QueryContext ctx) {
public @Nullable ParseTree visitQuery(SDBLParser.QueryContext ctx) {

if (ctx.getParent().getRuleIndex() != SDBLParser.RULE_subquery) {
if (ctx.getParent() != null && ctx.getParent().getRuleIndex() != SDBLParser.RULE_subquery) {
return super.visitQuery(ctx);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private static String getComplexPathName(
}

@Override
public ParseTree visitFile(BSLParser.FileContext ctx) {
public @Nullable ParseTree visitFile(BSLParser.FileContext ctx) {
currentScope = new VariableScope();
currentScope.enterScope(GLOBAL_SCOPE);
ParseTree result = super.visitFile(ctx);
Expand All @@ -154,31 +154,31 @@ public ParseTree visitFile(BSLParser.FileContext ctx) {
}

@Override
public ParseTree visitFileCodeBlock(BSLParser.FileCodeBlockContext ctx) {
public @Nullable ParseTree visitFileCodeBlock(BSLParser.FileCodeBlockContext ctx) {
currentScope.enterScope(MODULE_SCOPE);
ParseTree result = super.visitFileCodeBlock(ctx);
currentScope.leaveScope();
return result;
}

@Override
public ParseTree visitProcedure(BSLParser.ProcedureContext ctx) {
public @Nullable ParseTree visitProcedure(BSLParser.ProcedureContext ctx) {
currentScope.enterScope(ctx.procDeclaration().subName().getText());
ParseTree result = super.visitProcedure(ctx);
currentScope.leaveScope();
return result;
}

@Override
public ParseTree visitFunction(BSLParser.FunctionContext ctx) {
public @Nullable ParseTree visitFunction(BSLParser.FunctionContext ctx) {
currentScope.enterScope(ctx.funcDeclaration().subName().getText());
ParseTree result = super.visitFunction(ctx);
currentScope.leaveScope();
return result;
}

@Override
public ParseTree visitAssignment(AssignmentContext ctx) {
public @Nullable ParseTree visitAssignment(AssignmentContext ctx) {
if (ctx.expression() == null) {
return super.visitAssignment(ctx);
}
Expand Down Expand Up @@ -217,14 +217,14 @@ private Set<String> getTypesFromComplexIdentifier(BSLParser.ComplexIdentifierCon

private void visitDescendantCodeBlock(BSLParser.@Nullable CodeBlockContext ctx) {
Optional.ofNullable(ctx)
.map(e -> e.children)
.map(ParserRuleContext::getChildren)
.stream()
.flatMap(Collection::stream)
.forEach(t -> t.accept(this));
}

@Override
public ParseTree visitAccessCall(BSLParser.AccessCallContext ctx) {
public @Nullable ParseTree visitAccessCall(BSLParser.AccessCallContext ctx) {
if (!EXECUTE_CALL_PATTERN.matcher(ctx.methodCall().methodName().getText()).matches()) {
return super.visitAccessCall(ctx);
}
Expand Down Expand Up @@ -273,7 +273,7 @@ public ParseTree visitForEachStatement(BSLParser.ForEachStatementContext ctx) {
}

@Override
public ParseTree visitWhileStatement(BSLParser.WhileStatementContext ctx) {
public @Nullable ParseTree visitWhileStatement(BSLParser.WhileStatementContext ctx) {
currentScope.flowMode.push(CodeFlowType.CYCLE);
ParseTree result = super.visitWhileStatement(ctx);
currentScope.flowMode.pop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ private static boolean isNegationOperator(BslExpression parent) {
}

private void addDiagnostic(BinaryOperationNode node) {
var startToken = Trees.getTokens(node.getParent().getRepresentingAst())
Comment thread
theshadowco marked this conversation as resolved.
var parent = node.getParent();
if (parent == null) {
return;
}

var startToken = Trees.getTokens(parent.getRepresentingAst())
.stream()
.findFirst()
.orElseThrow();
Expand All @@ -100,7 +105,11 @@ private void addDiagnostic(BinaryOperationNode node) {
}

private void addDiagnostic(UnaryOperationNode node) {
var startToken = Trees.getTokens(node.getParent().getRepresentingAst())
var parent = node.getParent();
if (parent == null) {
return;
}
var startToken = Trees.getTokens(parent.getRepresentingAst())
.stream()
.findFirst()
.orElseThrow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ private static Stream<String> joinedTables(SDBLParser.JoinPartContext joinPartCt

private static List<SDBLParser.DataSourceContext> joinedDataSourceContext(SDBLParser.JoinPartContext joinPartCtx) {
final List<SDBLParser.DataSourceContext> result;
if (joinPartCtx.LEFT() != null) {
if (joinPartCtx.leftJoin() != null) {
result = Collections.singletonList(joinPartCtx.dataSource());
} else if (joinPartCtx.RIGHT() != null) {
} else if (joinPartCtx.rightJoin() != null) {
result = Collections.singletonList(((SDBLParser.DataSourceContext) joinPartCtx.getParent()));
} else if (joinPartCtx.FULL() != null) {
} else if (joinPartCtx.fullJoin() != null) {
result = Arrays.asList(((SDBLParser.DataSourceContext) joinPartCtx.getParent()),
joinPartCtx.dataSource());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public class FullOuterJoinQueryDiagnostic extends AbstractSDBLVisitorDiagnostic

@Override
public ParseTree visitJoinPart(SDBLParser.JoinPartContext ctx) {
if (ctx.FULL() != null && ctx.JOIN() != null) {
diagnosticStorage.addDiagnostic(ctx.FULL(), ctx.JOIN());
if (ctx.fullJoin() != null) {
diagnosticStorage.addDiagnostic(ctx.fullJoin());
}

return super.visitJoinPart(ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import jakarta.annotation.PostConstruct;
import org.antlr.v4.runtime.tree.ParseTree;
import org.eclipse.lsp4j.DiagnosticRelatedInformation;
import org.jspecify.annotations.Nullable;

import java.util.ArrayList;
import java.util.HashSet;
Expand Down Expand Up @@ -61,7 +62,7 @@ public void init() {
}

@Override
public ParseTree visitIfStatement(BSLParser.IfStatementContext ctx) {
public @Nullable ParseTree visitIfStatement(BSLParser.IfStatementContext ctx) {
Comment thread
theshadowco marked this conversation as resolved.
checkedBlocks.clear();
List<BSLParser.CodeBlockContext> codeBlocks = new ArrayList<>();

Expand Down Expand Up @@ -96,7 +97,7 @@ private void checkCodeBlock(List<BSLParser.CodeBlockContext> codeBlockContexts,
.skip(i)
.filter(codeBlockContext ->
!codeBlockContext.equals(currentCodeBlock)
&& !(currentCodeBlock.children == null && codeBlockContext.children == null)
&& !(currentCodeBlock.getChildren().isEmpty() && codeBlockContext.getChildren().isEmpty())
&& DiagnosticHelper.equalNodes(currentCodeBlock, codeBlockContext))
.toList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private static Optional<BSLParser.ConstValueContext> getConstValue(Optional<BSLP
.flatMap(memberContext -> calcStringForMemberContext(memberContext, isFullSearch));
}

private static Optional<BSLParser.ConstValueContext> calcStringForMemberContext(BSLParser.MemberContext memberContext,
private static Optional<BSLParser.ConstValueContext> calcStringForMemberContext(BSLParser.MemberContext memberContext,
boolean isFullSearch) {
final var constValue = memberContext.constValue();
if (constValue != null) {
Expand All @@ -161,8 +161,8 @@ private static Optional<BSLParser.ConstValueContext> calcStringForMemberContext(
}

private static Optional<BSLParser.ConstValueContext> calcAssignedValueForIdentifier(
BSLParser.ComplexIdentifierContext complexIdentifier) {
BSLParser.ComplexIdentifierContext complexIdentifier) {

final var identifier = complexIdentifier.IDENTIFIER();
if (identifier == null) {
return Optional.empty();
Expand All @@ -172,9 +172,9 @@ private static Optional<BSLParser.ConstValueContext> calcAssignedValueForIdentif
var prevStatement = (BSLParser.StatementContext) Objects.requireNonNull(Trees.getRootParent(complexIdentifier,
BSLParser.RULE_statement));
while (true) {
prevStatement = (BSLParser.StatementContext) getPreviousNode(Objects.requireNonNull(prevStatement),
prevStatement = (BSLParser.StatementContext) getPreviousNode(Objects.requireNonNull(prevStatement),
BSLParser.RULE_statement);

if (prevStatement == null) {
break;
}
Expand All @@ -191,8 +191,12 @@ private static Optional<BSLParser.ConstValueContext> calcAssignedValueForIdentif

@Nullable
private static ParserRuleContext getPreviousNode(ParserRuleContext node, int ruleStatement) {
var parent = node.getParent();
if (parent == null) {
return null;
}

final var children = node.getParent().children;
final var children = parent.getChildren();
final var pos = children.indexOf(node);
if (pos > 0) {
for (int i = pos - 1; i >= 0; i--) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
scope = DiagnosticScope.BSL
)
public class MultilineStringInQueryDiagnostic extends AbstractSDBLVisitorDiagnostic {
private static final int MULTI_STRING_MIN_SIZE = 2; // see SDBLParser grammar
private static final int MULTI_STRING_MIN_SIZE = 1; // see SDBLParser grammar

@Override
public ParseTree visitMultiString(SDBLParser.MultiStringContext ctx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,15 @@ public void enterFile(BSLParser.FileContext ctx) {
}

private static String getTokenName(int tokenType) {
String value = BSLLexer.VOCABULARY.getLiteralName(tokenType);
var value = BSLLexer.VOCABULARY.getLiteralName(tokenType);
if (value == null) {
value = BSLLexer.VOCABULARY.getSymbolicName(tokenType);
}

if (value == null) { // вероятность равна нолю
value = "";
}

return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public ParseTree visitQueryPackage(SDBLParser.QueryPackageContext ctx) {
}

@Override
public ParseTree visitQuery(SDBLParser.QueryContext ctx) {
public @Nullable ParseTree visitQuery(SDBLParser.QueryContext ctx) {
checkQuery(ctx).forEach(diagnosticStorage::addDiagnostic);
return super.visitQuery(ctx);
}
Expand Down Expand Up @@ -312,7 +312,7 @@ private static int findLastRef(List<ParseTree> children) {

private static List<ParseTree> extractFirstMetadataTypeName(SDBLParser.ColumnContext ctx) {
final var mdoName = ctx.mdoName;
final var children = ctx.children;
final var children = ctx.getChildren();
if (mdoName == null || children.size() < COUNT_OF_TABLE_DOT_REF_DOT_REF
|| !METADATA_TYPES.contains(mdoName.getStart().getType())) {
return children;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticType;
import com.github._1c_syntax.bsl.parser.SDBLParser;
import org.antlr.v4.runtime.tree.ParseTree;
import org.jspecify.annotations.Nullable;

@DiagnosticMetadata(
type = DiagnosticType.CODE_SMELL,
Expand All @@ -43,8 +44,8 @@
public class UnionAllDiagnostic extends AbstractSDBLVisitorDiagnostic {

@Override
public ParseTree visitUnion(SDBLParser.UnionContext ctx) {
if (ctx.UNION() != null && ctx.ALL() != null) {
public @Nullable ParseTree visitUnion(SDBLParser.UnionContext ctx) {
if (ctx.UNION_ALL() != null) {
return super.visitUnion(ctx);
}

Expand Down
Loading
Loading