mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
EA-33799 (IOE: PsiJavaParserFacadeImpl.createExpressionFromText)
This commit is contained in:
@@ -52,7 +52,7 @@ public class ConvertDoubleToFloatFix implements IntentionAction {
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
if (myExpression.isValid()) {
|
||||
if (!StringUtil.endsWithIgnoreCase(myExpression.getText(), "d")) {
|
||||
if (!StringUtil.endsWithIgnoreCase(myExpression.getText(), "f")) {
|
||||
final PsiLiteralExpression expression = (PsiLiteralExpression)createFloatingPointExpression(project);
|
||||
final Object value = expression.getValue();
|
||||
return value instanceof Float && !((Float)value).isInfinite() && !(((Float)value).floatValue() == 0 && !HighlightUtil.isFPZero(expression.getText()));
|
||||
@@ -67,7 +67,12 @@ public class ConvertDoubleToFloatFix implements IntentionAction {
|
||||
}
|
||||
|
||||
private PsiExpression createFloatingPointExpression(Project project) {
|
||||
return JavaPsiFacade.getElementFactory(project).createExpressionFromText(myExpression.getText() + "f", myExpression);
|
||||
final String text = myExpression.getText();
|
||||
if (StringUtil.endsWithIgnoreCase(text, "d")) {
|
||||
return JavaPsiFacade.getElementFactory(project).createExpressionFromText(text.substring(0, text.length() - 1) + "f", myExpression);
|
||||
} else {
|
||||
return JavaPsiFacade.getElementFactory(project).createExpressionFromText(text + "f", myExpression);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// "Convert '1e-9d' to float" "true"
|
||||
class Test {
|
||||
void bar() {
|
||||
foo(1e-9f);
|
||||
}
|
||||
void foo(float f){}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Convert '1e-9d' to float" "false"
|
||||
// "Convert '1e-9d' to float" "true"
|
||||
class Test {
|
||||
void bar() {
|
||||
foo(1e-9<caret>d);
|
||||
|
||||
Reference in New Issue
Block a user