mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-59582 (intention Convert to Plain for double literal does not work)
This commit is contained in:
+28
-14
@@ -28,21 +28,35 @@ import java.text.DecimalFormat;
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class ConvertToEngineeringNotationIntention extends Intention {
|
||||
private static final DecimalFormat FORMAT = new DecimalFormat("0.00000000000000E00");
|
||||
private static final ConvertToEngineeringNotationPredicate PREDICATE = new ConvertToEngineeringNotationPredicate();
|
||||
|
||||
@Override
|
||||
protected void processIntention(@NotNull PsiElement element) throws IncorrectOperationException {
|
||||
String text = FORMAT.format(Double.parseDouble(element.getText())).replace(',', '.');
|
||||
while (text.contains("0E") && !text.contains(".0E")) {
|
||||
text = text.replace("0E", "E");
|
||||
private static final DecimalFormat FORMAT =
|
||||
new DecimalFormat("0.00000000000000E00");
|
||||
private static final ConvertToEngineeringNotationPredicate PREDICATE =
|
||||
new ConvertToEngineeringNotationPredicate();
|
||||
|
||||
@Override
|
||||
protected void processIntention(@NotNull PsiElement element)
|
||||
throws IncorrectOperationException {
|
||||
final String elementText = element.getText();
|
||||
if (elementText.length() == 0) {
|
||||
return;
|
||||
}
|
||||
final int lastIndex = elementText.length() - 1;
|
||||
final char lastChar = elementText.charAt(lastIndex);
|
||||
String text = FORMAT.format(Double.parseDouble(elementText)).replace(',', '.');
|
||||
while (text.contains("0E") && !text.contains(".0E")) {
|
||||
text = text.replace("0E", "E");
|
||||
}
|
||||
if (lastChar == 'f' || lastChar == 'F') {
|
||||
replaceExpression(text + lastChar, (PsiExpression)element);
|
||||
} else {
|
||||
replaceExpression(text, (PsiExpression)element);
|
||||
}
|
||||
}
|
||||
replaceExpression(text, (PsiExpression)element);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected PsiElementPredicate getElementPredicate() {
|
||||
return PREDICATE;
|
||||
}
|
||||
@NotNull
|
||||
@Override
|
||||
protected PsiElementPredicate getElementPredicate() {
|
||||
return PREDICATE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,24 +22,43 @@ import com.siyeh.ipp.base.Intention;
|
||||
import com.siyeh.ipp.base.PsiElementPredicate;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class ConvertToPlainIntention extends Intention {
|
||||
private static final ConvertToPlainPredicate PREDICATE = new ConvertToPlainPredicate();
|
||||
|
||||
@Override
|
||||
protected void processIntention(@NotNull PsiElement element) throws IncorrectOperationException {
|
||||
try {
|
||||
replaceExpression(Double.toString(Double.parseDouble(element.getText())), (PsiExpression)element);
|
||||
}
|
||||
catch (Exception e) {//
|
||||
}
|
||||
}
|
||||
private static final ConvertToPlainPredicate PREDICATE =
|
||||
new ConvertToPlainPredicate();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected PsiElementPredicate getElementPredicate() {
|
||||
return PREDICATE;
|
||||
}
|
||||
@Override
|
||||
protected void processIntention(@NotNull PsiElement element)
|
||||
throws IncorrectOperationException {
|
||||
try {
|
||||
final String elementText = element.getText();
|
||||
if (elementText.length() == 0) {
|
||||
return;
|
||||
}
|
||||
final int lastIndex = elementText.length() - 1;
|
||||
final char lastChar = elementText.charAt(lastIndex);
|
||||
if (lastChar == 'f' || lastChar == 'F') {
|
||||
final BigDecimal bigDecimal =
|
||||
new BigDecimal(elementText.substring(0, lastIndex));
|
||||
replaceExpression(bigDecimal.toPlainString() + lastChar,
|
||||
(PsiExpression) element);
|
||||
} else {
|
||||
final BigDecimal bigDecimal = new BigDecimal(elementText);
|
||||
replaceExpression(bigDecimal.toPlainString(),
|
||||
(PsiExpression) element);
|
||||
}
|
||||
} catch (Exception e) {//
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected PsiElementPredicate getElementPredicate() {
|
||||
return PREDICATE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import com.siyeh.ipp.base.PsiElementPredicate;
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class ConvertToPlainPredicate implements PsiElementPredicate {
|
||||
@Override
|
||||
|
||||
public boolean satisfiedBy(PsiElement element) {
|
||||
if (element instanceof PsiLiteralExpression) {
|
||||
final PsiLiteralExpression expression = (PsiLiteralExpression)element;
|
||||
|
||||
Reference in New Issue
Block a user