Compare commits

...

1 Commits

Author SHA1 Message Date
Ilya Gorbunov
e078030792 Use properly typed default values for Byte and Short
Co-authored-by: Mikhail Zarechenskiy <mikhail.zarechenskiy@jetbrains.com>
2020-03-30 08:25:53 +03:00
3 changed files with 46 additions and 2 deletions

View File

@@ -1270,10 +1270,10 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
}
private fun getDefaultValue(type: Type): Any? = when (type) {
Type.BYTE_TYPE -> 0
Type.BYTE_TYPE -> 0.toByte()
Type.BOOLEAN_TYPE -> false
Type.CHAR_TYPE -> '\u0000'
Type.SHORT_TYPE -> 0
Type.SHORT_TYPE -> 0.toShort()
Type.INT_TYPE -> 0
Type.LONG_TYPE -> 0L
Type.FLOAT_TYPE -> 0.0F

View File

@@ -1,27 +1,33 @@
object PrimitiveTypes {
const val booleanFalse: Boolean = false
const val booleanTrue: Boolean = true
val someBoolean: Boolean = System.getProperty("boolean").toBoolean()
const val int0: Int = 0
const val intMinus1000: Int = -1000
const val intMinValue: Int = Int.MIN_VALUE
const val intMaxValue: Int = Int.MAX_VALUE
const val intHex: Int = 0xffffffff.toInt()
val someInt: Int = System.getProperty("int").toInt()
const val byte0: Byte = 0.toByte()
const val byte50: Byte = 50.toByte()
val someByte: Byte = System.getProperty("byte").toByte()
const val short5: Short = 5.toShort()
val someShort: Short = System.getProperty("short").toShort()
const val charC: Char = 'C'
const val char0: Char = 0.toChar()
const val char10: Char = 10.toChar()
const val char13: Char = 13.toChar()
val someChar = System.getProperty("char").first()
const val long0: Long = 0L
const val longMaxValue: Long = Long.MAX_VALUE
const val longMinValue: Long = Long.MIN_VALUE
const val longHex: Long = 0xffffffff
val someLong = System.getProperty("long").toLong()
const val float54 = 5.4f
val floatMaxValue = Float.MAX_VALUE
@@ -38,4 +44,5 @@ object PrimitiveTypes {
const val stringHelloWorld: String = "Hello, world!"
const val stringQuotes: String = "quotes \" ''quotes"
const val stringRN: String = "\r\n"
val someString: String = System.getProperty("string")
}

View File

@@ -4,22 +4,28 @@ import java.lang.System;
public final class PrimitiveTypes {
public static final boolean booleanFalse = false;
public static final boolean booleanTrue = true;
private static final boolean someBoolean = false;
public static final int int0 = 0;
public static final int intMinus1000 = -1000;
public static final int intMinValue = -2147483648;
public static final int intMaxValue = 2147483647;
public static final int intHex = -1;
private static final int someInt = 0;
public static final byte byte0 = (byte)0;
public static final byte byte50 = (byte)50;
private static final byte someByte = (byte)0;
public static final short short5 = (short)5;
private static final short someShort = (short)0;
public static final char charC = 'C';
public static final char char0 = '\u0000';
public static final char char10 = '\n';
public static final char char13 = '\r';
private static final char someChar = '\u0000';
public static final long long0 = 0L;
public static final long longMaxValue = 9223372036854775807L;
public static final long longMinValue = -9223372036854775808L;
public static final long longHex = 4294967295L;
private static final long someLong = 0L;
public static final float float54 = 5.4F;
private static final float floatMaxValue = 0.0F;
private static final float floatNan = 0.0F;
@@ -36,8 +42,34 @@ public final class PrimitiveTypes {
public static final java.lang.String stringQuotes = "quotes \" \'\'quotes";
@org.jetbrains.annotations.NotNull()
public static final java.lang.String stringRN = "\r\n";
@org.jetbrains.annotations.NotNull()
private static final java.lang.String someString = null;
public static final PrimitiveTypes INSTANCE = null;
public final boolean getSomeBoolean() {
return false;
}
public final int getSomeInt() {
return 0;
}
public final byte getSomeByte() {
return (byte)0;
}
public final short getSomeShort() {
return (short)0;
}
public final char getSomeChar() {
return '\u0000';
}
public final long getSomeLong() {
return 0L;
}
public final float getFloatMaxValue() {
return 0.0F;
}
@@ -70,6 +102,11 @@ public final class PrimitiveTypes {
return 0.0;
}
@org.jetbrains.annotations.NotNull()
public final java.lang.String getSomeString() {
return null;
}
private PrimitiveTypes() {
super();
}