-
Notifications
You must be signed in to change notification settings - Fork 121
Исправление замечаний к коду. Продолжение 25.12.12. Часть 2 #3659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
de2f6d8
f00e40f
2c2eb6e
23d7dcd
4f5354e
ab8f5d4
4be9da8
b7d5df3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,23 +52,27 @@ | |
| public class UselessTernaryOperatorDiagnostic extends AbstractVisitorDiagnostic implements QuickFixProvider { | ||
|
|
||
| private static final int SKIPPED_RULE_INDEX = 0; | ||
| private static final int COUNT_EXPRESSIONS = 3; | ||
| private static final int INDEX_CONDITION = 0; | ||
| private static final int INDEX_TRUE_BRANCH = 1; | ||
| private static final int INDEX_FALSE_BRANCH = 2; | ||
|
|
||
| @Override | ||
| public ParseTree visitTernaryOperator(BSLParser.TernaryOperatorContext ctx) { | ||
| var exp = ctx.expression(); | ||
|
|
||
| if (exp != null && exp.size() >= 3) { | ||
| var condition = getBooleanToken(exp.get(0)); | ||
| var trueBranch = getBooleanToken(exp.get(1)); | ||
| var falseBranch = getBooleanToken(exp.get(2)); | ||
| if (exp != null && exp.size() >= COUNT_EXPRESSIONS) { | ||
| var condition = getBooleanToken(exp.get(INDEX_CONDITION)); | ||
| var trueBranch = getBooleanToken(exp.get(INDEX_TRUE_BRANCH)); | ||
| var falseBranch = getBooleanToken(exp.get(INDEX_FALSE_BRANCH)); | ||
|
Comment on lines
+64
to
+67
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Harden null-safety: If - private static int getBooleanToken(BSLParser.ExpressionContext expCtx) {
+ private static int getBooleanToken(@org.jetbrains.annotations.Nullable BSLParser.ExpressionContext expCtx) {
var tmpCtx = Optional.of(expCtx)
+ // or: Optional.ofNullable(expCtx)
.filter(ctx -> ctx.children.size() == 1)
.map(ctx -> ctx.member(0))
.map(ctx -> ctx.getChild(0))
.filter(BSLParser.ConstValueContext.class::isInstance)
.map(BSLParser.ConstValueContext.class::cast);
🤖 Prompt for AI Agents |
||
|
|
||
| if (condition != SKIPPED_RULE_INDEX) { | ||
| diagnosticStorage.addDiagnostic(ctx); | ||
| } else if (trueBranch == BSLParser.TRUE && falseBranch == BSLParser.FALSE) { | ||
| diagnosticStorage.addDiagnostic(ctx, DiagnosticStorage.createAdditionalData(exp.get(0).getText())); | ||
| diagnosticStorage.addDiagnostic(ctx, DiagnosticStorage.createAdditionalData(exp.get(INDEX_CONDITION).getText())); | ||
| } else if (trueBranch == BSLParser.FALSE && falseBranch == BSLParser.TRUE) { | ||
| diagnosticStorage.addDiagnostic(ctx, | ||
| DiagnosticStorage.createAdditionalData(getAdaptedText(exp.get(0).getText()))); | ||
| DiagnosticStorage.createAdditionalData(getAdaptedText(exp.get(INDEX_CONDITION).getText()))); | ||
| } else if (trueBranch != SKIPPED_RULE_INDEX || falseBranch != SKIPPED_RULE_INDEX) { | ||
| diagnosticStorage.addDiagnostic(ctx); | ||
| } else { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.