IDEA-151267 ('Convert to Plain' adds redundant zero at the end)
authorBas Leijdekkers <basleijdekkers@gmail.com>
Fri, 5 Feb 2016 14:33:23 +0000 (15:33 +0100)
committerBas Leijdekkers <basleijdekkers@gmail.com>
Fri, 5 Feb 2016 14:35:44 +0000 (15:35 +0100)
plugins/IntentionPowerPak/src/com/siyeh/ipp/integer/ConvertToPlainIntention.java
plugins/IntentionPowerPak/test/com/siyeh/ipp/float/NoTrailingZeros.java [new file with mode: 0644]
plugins/IntentionPowerPak/test/com/siyeh/ipp/float/NoTrailingZeros_after.java [new file with mode: 0644]
plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/integer/ConvertToPlainTest.java

index 8540850ba4c82cd159e0c7f3face32744784c4a9..b43729ff74d5996998aeb46e7ae2bc0c660fad10 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2010 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@ import java.math.BigDecimal;
 public class ConvertToPlainIntention extends ConvertNumberIntentionBase {
   @Override
   protected String convertValue(final Number value, final PsiType type, final boolean negated) {
-    String text = new BigDecimal(value.toString()).toPlainString();
+    String text = new BigDecimal(value.toString()).stripTrailingZeros().toPlainString();
     if (negated) text = "-" + text;
     if (PsiType.FLOAT.equals(type)) text += "f";
     return text;
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/float/NoTrailingZeros.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/float/NoTrailingZeros.java
new file mode 100644 (file)
index 0000000..5f7554f
--- /dev/null
@@ -0,0 +1,3 @@
+class C {
+  double EPS = <caret>5E-8;
+}
\ No newline at end of file
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/float/NoTrailingZeros_after.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/float/NoTrailingZeros_after.java
new file mode 100644 (file)
index 0000000..2fb2e74
--- /dev/null
@@ -0,0 +1,3 @@
+class C {
+  double EPS = 0.00000005;
+}
\ No newline at end of file
index 5ae518088806019118c1e174f367b06d1dec74e8..de6a34fb1c1cc4067fac686a302c62efe7150797 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2011 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -18,10 +18,14 @@ package com.siyeh.ipp.integer;
 import com.siyeh.IntentionPowerPackBundle;
 import com.siyeh.ipp.IPPTestCase;
 
+/**
+ * @see ConvertToPlainIntention
+ */
 public class ConvertToPlainTest extends IPPTestCase {
   public void testToPlain() { doTest(); }
   public void testNegatedFloatToPlain() { doTest(); }
   public void testWithUnderscoresToPlain() { doTest(); }
+  public void testNoTrailingZeros() { doTest(); }
 
   @Override
   protected String getIntentionName() {