Fix for KT-11375, KT-9710, KT-8161

This commit is contained in:
Simon Ogorodnik
2016-10-11 11:39:13 +03:00
parent df0dddedc2
commit 25b9542c06
12 changed files with 72 additions and 13 deletions
@@ -124,8 +124,8 @@ class CodeConverter(
if (expectedTypeStr == "float") {
text += "f"
}
else {
if (!text.contains(".")) {
if (expectedTypeStr == "double") {
if (!text.contains(".") && !text.contains("e", true)) {
text += ".0"
}
}
@@ -283,15 +283,16 @@ class DefaultExpressionConverter : JavaElementVisitor(), ExpressionConverter {
if (type != null) {
val typeStr = type.canonicalText
if (typeStr == "double") {
text = text.replace("D", "").replace("d", "")
if (!text.contains(".")) {
text += ".0"
text = text.replace("d", "", true)
if (!text.contains(".") && !text.contains("e", true))
text += "."
if (text.endsWith(".")) {
text += "0"
}
}
if (typeStr == "float") {
text = text.replace("F", "f")
text = text.replace(".f", "f", true).replace("F", "f")
}
if (typeStr == "long") {
+6 -3
View File
@@ -5,7 +5,10 @@ class A {
private double d4 = 1.0d;
private double d5 = 1.0D;
private double d6 = 1.0F;
private double d7 = Math.sqrt(2) - 1
private double d7 = Math.sqrt(2) - 1;
private double d8 = 1.;
private double d9 = 1.d;
private double x = 1 / (1. + 0);
void foo1(double d){}
void foo2(Double d){}
@@ -15,7 +18,7 @@ class A {
foo1(1f);
foo1(1.0);
foo2(1.0);
d1 = 1.0
d2 = 1
d1 = 1.0;
d2 = 1;
}
}
+4 -1
View File
@@ -6,6 +6,9 @@ internal class A {
private val d5 = 1.0
private val d6 = 1.0
private val d7 = Math.sqrt(2.0) - 1
private val d8 = 1.0
private val d9 = 1.0
private val x = 1 / (1.0 + 0)
fun foo1(d: Double) {
}
@@ -21,4 +24,4 @@ internal class A {
d1 = 1.0
d2 = 1.0
}
}
}
@@ -0,0 +1,9 @@
public class Exponent {
private final double[] doubles = {
5e5, +5e5, -5e5, 5e+5, 5e-5,
5E5, +5E5, -5E5, 5E+5, 5E-5,
2.5e5, +2.5e5, -2.5e5, 2.5e+5, 2.5e-5,
2.5E5, +2.5E5, -2.5E5, 2.5E+5, 2.5E-5,
5e5f, 5e5F, 5e5d, 5e5D
};
}
@@ -0,0 +1,3 @@
class Exponent {
private val doubles = doubleArrayOf(5e5, +5e5, -5e5, 5e+5, 5e-5, 5E5, +5E5, -5E5, 5E+5, 5E-5, 2.5e5, +2.5e5, -2.5e5, 2.5e+5, 2.5e-5, 2.5E5, +2.5E5, -2.5E5, 2.5E+5, 2.5E-5, 5e5, 5e5, 5e5, 5e5)
}
@@ -0,0 +1,9 @@
public class Exponent {
private final float[] floats = {
5e5f, +5e5f, -5e5f, 5e+5f, 5e-5f,
5E5f, +5E5f, -5E5f, 5E+5f, 5E-5f,
2.5e5f, +2.5e5f, -2.5e5f, 2.5e+5f, 2.5e-5f,
2.5E5f, +2.5E5f, -2.5E5f, 2.5E+5f, 2.5E-5f,
5e5f, 5e5F
};
}
@@ -0,0 +1,3 @@
class Exponent {
private val floats = floatArrayOf(5e5f, +5e5f, -5e5f, 5e+5f, 5e-5f, 5E5f, +5E5f, -5E5f, 5E+5f, 5E-5f, 2.5e5f, +2.5e5f, -2.5e5f, 2.5e+5f, 2.5e-5f, 2.5E5f, +2.5E5f, -2.5E5f, 2.5E+5f, 2.5E-5f, 5e5f, 5e5f)
}
+4 -2
View File
@@ -7,6 +7,8 @@ class A {
private float f6 = -1;
private float f7 = -1F;
private float f8 = +1;
private float f9 = 1.f;
private float f10 = 1.F;
void foo1(float f){}
void foo2(Float f){}
@@ -18,7 +20,7 @@ class A {
foo1(1L);
foo1(-1);
foo1(-1L);
f1 = 1
f4 = 1.0f
f1 = 1;
f4 = 1.0f;
}
}
+2
View File
@@ -7,6 +7,8 @@ internal class A {
private val f6 = -1f
private val f7 = -1f
private val f8 = +1f
private val f9 = 1f
private val f10 = 1f
fun foo1(f: Float) {
}
@@ -3196,6 +3196,18 @@ public class JavaToKotlinConverterForWebDemoTestGenerated extends AbstractJavaTo
doTest(fileName);
}
@TestMetadata("exponentDouble.java")
public void testExponentDouble() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/literalExpression/exponentDouble.java");
doTest(fileName);
}
@TestMetadata("exponentFloat.java")
public void testExponentFloat() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/literalExpression/exponentFloat.java");
doTest(fileName);
}
@TestMetadata("float.java")
public void testFloat() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/literalExpression/float.java");
@@ -3196,6 +3196,18 @@ public class JavaToKotlinConverterSingleFileTestGenerated extends AbstractJavaTo
doTest(fileName);
}
@TestMetadata("exponentDouble.java")
public void testExponentDouble() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/literalExpression/exponentDouble.java");
doTest(fileName);
}
@TestMetadata("exponentFloat.java")
public void testExponentFloat() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/literalExpression/exponentFloat.java");
doTest(fileName);
}
@TestMetadata("float.java")
public void testFloat() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/literalExpression/float.java");