Generate constant expression initializers for special fp values in kapt
Update new constant values propagated in kapt class-to-stub test
This commit is contained in:
+13
-1
@@ -70,6 +70,7 @@ import org.jetbrains.org.objectweb.asm.Type
|
||||
import org.jetbrains.org.objectweb.asm.tree.*
|
||||
import java.io.File
|
||||
import javax.lang.model.element.ElementKind
|
||||
import kotlin.math.sign
|
||||
import com.sun.tools.javac.util.List as JavacList
|
||||
|
||||
class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGeneration, val generateNonExistentClass: Boolean) {
|
||||
@@ -1178,11 +1179,22 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
|
||||
}
|
||||
|
||||
private fun convertValueOfPrimitiveTypeOrString(value: Any?): JCExpression? {
|
||||
fun specialFpValueNumerator(value: Double): Double = if (value.isNaN()) 0.0 else 1.0 * value.sign
|
||||
return when (value) {
|
||||
is Char -> treeMaker.Literal(TypeTag.CHAR, value.toInt())
|
||||
is Byte -> treeMaker.TypeCast(treeMaker.TypeIdent(TypeTag.BYTE), treeMaker.Literal(TypeTag.INT, value.toInt()))
|
||||
is Short -> treeMaker.TypeCast(treeMaker.TypeIdent(TypeTag.SHORT), treeMaker.Literal(TypeTag.INT, value.toInt()))
|
||||
is Boolean, is Int, is Long, is Float, is Double, is String -> treeMaker.Literal(value)
|
||||
is Boolean, is Int, is Long, is String -> treeMaker.Literal(value)
|
||||
is Float ->
|
||||
when {
|
||||
value.isFinite() -> treeMaker.Literal(value)
|
||||
else -> treeMaker.Binary(Tag.DIV, treeMaker.Literal(specialFpValueNumerator(value.toDouble()).toFloat()), treeMaker.Literal(0.0F))
|
||||
}
|
||||
is Double ->
|
||||
when {
|
||||
value.isFinite() -> treeMaker.Literal(value)
|
||||
else -> treeMaker.Binary(Tag.DIV, treeMaker.Literal(specialFpValueNumerator(value)), treeMaker.Literal(0.0))
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,15 +21,15 @@ public final class PrimitiveTypes {
|
||||
public static final long longMinValue = -9223372036854775808L;
|
||||
public static final long longHex = 4294967295L;
|
||||
public static final float float54 = 5.4F;
|
||||
private static final float floatMaxValue = 0.0F;
|
||||
private static final float floatNan = 0.0F;
|
||||
private static final float floatPositiveInfinity = 0.0F;
|
||||
private static final float floatNegativeInfinity = 0.0F;
|
||||
private static final float floatMaxValue = 3.4028235E38F;
|
||||
private static final float floatNan = 0.0F / 0.0F;
|
||||
private static final float floatPositiveInfinity = 1.0F / 0.0F;
|
||||
private static final float floatNegativeInfinity = -1.0F / 0.0F;
|
||||
public static final double double54 = 5.4;
|
||||
private static final double doubleMaxValue = 0.0;
|
||||
private static final double doubleNan = 0.0;
|
||||
private static final double doublePositiveInfinity = 0.0;
|
||||
private static final double doubleNegativeInfinity = 0.0;
|
||||
private static final double doubleMaxValue = 1.7976931348623157E308;
|
||||
private static final double doubleNan = 0.0 / 0.0;
|
||||
private static final double doublePositiveInfinity = 1.0 / 0.0;
|
||||
private static final double doubleNegativeInfinity = -1.0 / 0.0;
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public static final java.lang.String stringHelloWorld = "Hello, world!";
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
|
||||
Reference in New Issue
Block a user