-
Notifications
You must be signed in to change notification settings - Fork 109
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
Add useless ternary operator diagnostic #1820
base: develop
Are you sure you want to change the base?
Add useless ternary operator diagnostic #1820
Conversation
Забыл досаду приатачить, как исправить? |
@EvgSychev отредактировать первый пост. но вроде @otymko уже поправил |
...a/com/github/_1c_syntax/bsl/languageserver/diagnostics/UselessTernaryOperatorDiagnostic.java
Outdated
Show resolved
Hide resolved
...a/com/github/_1c_syntax/bsl/languageserver/diagnostics/UselessTernaryOperatorDiagnostic.java
Show resolved
Hide resolved
...a/com/github/_1c_syntax/bsl/languageserver/diagnostics/UselessTernaryOperatorDiagnostic.java
Outdated
Show resolved
Hide resolved
...a/com/github/_1c_syntax/bsl/languageserver/diagnostics/UselessTernaryOperatorDiagnostic.java
Show resolved
Hide resolved
...a/com/github/_1c_syntax/bsl/languageserver/diagnostics/UselessTernaryOperatorDiagnostic.java
Show resolved
Hide resolved
...a/com/github/_1c_syntax/bsl/languageserver/diagnostics/UselessTernaryOperatorDiagnostic.java
Outdated
Show resolved
Hide resolved
...a/com/github/_1c_syntax/bsl/languageserver/diagnostics/UselessTernaryOperatorDiagnostic.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
похоже на ошибку
...a/com/github/_1c_syntax/bsl/languageserver/diagnostics/UselessTernaryOperatorDiagnostic.java
Show resolved
Hide resolved
3 варианта потому, что это не один и тот же optinal, два преобразуются и каждый по своему, третий на тот случае если ничего не найдено, тесты код прошёл |
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/DiagnosticStorage.java
Outdated
Show resolved
Hide resolved
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/DiagnosticStorage.java
Outdated
Show resolved
Hide resolved
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/DiagnosticStorage.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
private String getAdaptedText(String text) { | ||
if(documentContext.getServerContext().getConfiguration().getDefaultLanguage() == MDLanguage.ENGLISH) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
лучше заменить на вызов documentContext.getScriptVariantLocale()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ну и вообще бы это перевесить на работу с Resources#getResourceString
.filter(BSLParser.ConstValueContext.class::isInstance) | ||
.map(BSLParser.ConstValueContext.class::cast); | ||
|
||
return tmpCtx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тэкс, а зачем все это ниже, если можно просто tmpCtx.filter(ctx -> ctx.TRUE() || ctx.FALSE).isPresent()
и сменить возвращаемое значение с int на boolean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Дальше по коду нужно знать в какой ветке у нас Истина, в какой ложь
|
||
var tmpCtx = Optional.of(expCtx) | ||
.filter(ctx -> ctx.children.size() == 1) | ||
.map(ctx -> (BSLParser.MemberContext) ctx.getChild(0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
просто .map(ctx -> ctx.member())
или сразу .map(BSLParser.ExpressionContext::member))
, нет нужды работать с детьми в грязную
var tmpCtx = Optional.of(expCtx) | ||
.filter(ctx -> ctx.children.size() == 1) | ||
.map(ctx -> (BSLParser.MemberContext) ctx.getChild(0)) | ||
.map(ctx -> ctx.getChild(0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
вместо этого вызова и двух вызовов ниже можно взять .map(ctx -> ctx.constValue()
. если constValue в этом expression нет, то метод вернет null и Optional станет empty
var exp = ctx.expression(); | ||
var condition = getBooleanToken(exp.get(0)); | ||
var trueBranch = getBooleanToken(exp.get(1)); | ||
var falseBranch = getBooleanToken(exp.get(2)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
я бы на всякий случай перед всеми этими дерганиями по индексу проверил, что exp.size() == 3
. опасаюсь IndexOutOfBoundException при наборе текста
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Если не 3 падаем?
...a/com/github/_1c_syntax/bsl/languageserver/diagnostics/UselessTernaryOperatorDiagnostic.java
Outdated
Show resolved
Hide resolved
…tics/UselessTernaryOperatorDiagnostic.java
/rebase |
@EvgSychev мерж поломал addDiagnostic |
@nixel2007 ошибочно сделал pull, будет исправлено |
Описание
Связанные задачи
Closes #203
Чеклист
Общие
gradlew precommit
)Для диагностик
Дополнительно