Kapt: Add DUMP_DEFAULT_PARAMETER_VALUES flag (KT-29355)

Put initializers on fields when corresponding primary constructor
  parameters have a default value specified. The new behavior
  is available under the new 'DUMP_DEFAULT_PARAMETER_VALUES' flag.

Note that this doesn't affect regular functions with default parameter
  values, as well as primary constructor parameters without a
  'val' or 'var' keyword.
This commit is contained in:
Yan Zhulanow
2020-05-01 17:54:03 +09:00
parent 60aa47553d
commit 2044ece335
22 changed files with 525 additions and 51 deletions
@@ -0,0 +1,29 @@
class Foo(
val z: Boolean = true,
val b: Byte = 0.toByte(),
val c: Char = 'c',
val c2: Char = '\n',
val sh: Short = 10.toShort(),
val i: Int = 10,
val l: Long = -10L,
val f: Float = 1.0f,
val d: Double = -1.0,
val s: String = "foo",
val iarr: IntArray = intArrayOf(1, 2, 3),
val larr: LongArray = longArrayOf(-1L, 0L, 1L),
val darr: DoubleArray = doubleArrayOf(7.3),
val sarr: Array<String> = arrayOf("a", "bc"),
// Sic! Unresolved reference not being reported because of partial resolve
val cl: Class<*> = User::class.java,
val clarr: Array<Class<*>> = arrayOf(User::class.java),
val em: Em = Em.BAR,
val emarr: Array<Em> = arrayOf(Em.FOO, Em.BAR)
) {
fun foo(a: Int = 5) {}
}
enum class Em {
FOO, BAR
}
@@ -0,0 +1,147 @@
import java.lang.System;
@kotlin.Metadata()
public enum Em {
/*public static final*/ FOO /* = new Em() */,
/*public static final*/ BAR /* = new Em() */;
Em() {
}
}
////////////////////
import java.lang.System;
@kotlin.Metadata()
public final class Foo {
private final boolean z = false;
private final byte b = 0;
private final char c = '\u0000';
private final char c2 = '\u0000';
private final short sh = 0;
private final int i = 0;
private final long l = 0L;
private final float f = 0.0F;
private final double d = 0.0;
@org.jetbrains.annotations.NotNull()
private final java.lang.String s = null;
@org.jetbrains.annotations.NotNull()
private final int[] iarr = null;
@org.jetbrains.annotations.NotNull()
private final long[] larr = null;
@org.jetbrains.annotations.NotNull()
private final double[] darr = null;
@org.jetbrains.annotations.NotNull()
private final java.lang.String[] sarr = null;
@org.jetbrains.annotations.NotNull()
private final java.lang.Class<?> cl = null;
@org.jetbrains.annotations.NotNull()
private final java.lang.Class<?>[] clarr = null;
@org.jetbrains.annotations.NotNull()
private final Em em = null;
@org.jetbrains.annotations.NotNull()
private final Em[] emarr = null;
public final void foo(int a) {
}
public final boolean getZ() {
return false;
}
public final byte getB() {
return 0;
}
public final char getC() {
return '\u0000';
}
public final char getC2() {
return '\u0000';
}
public final short getSh() {
return 0;
}
public final int getI() {
return 0;
}
public final long getL() {
return 0L;
}
public final float getF() {
return 0.0F;
}
public final double getD() {
return 0.0;
}
@org.jetbrains.annotations.NotNull()
public final java.lang.String getS() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final int[] getIarr() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final long[] getLarr() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final double[] getDarr() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final java.lang.String[] getSarr() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final java.lang.Class<?> getCl() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final java.lang.Class<?>[] getClarr() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final Em getEm() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final Em[] getEmarr() {
return null;
}
public Foo(boolean z, byte b, char c, char c2, short sh, int i, long l, float f, double d, @org.jetbrains.annotations.NotNull()
java.lang.String s, @org.jetbrains.annotations.NotNull()
int[] iarr, @org.jetbrains.annotations.NotNull()
long[] larr, @org.jetbrains.annotations.NotNull()
double[] darr, @org.jetbrains.annotations.NotNull()
java.lang.String[] sarr, @org.jetbrains.annotations.NotNull()
java.lang.Class<?> cl, @org.jetbrains.annotations.NotNull()
java.lang.Class<?>[] clarr, @org.jetbrains.annotations.NotNull()
Em em, @org.jetbrains.annotations.NotNull()
Em[] emarr) {
super();
}
public Foo() {
super();
}
}
@@ -0,0 +1,28 @@
// DUMP_DEFAULT_PARAMETER_VALUES
class Foo(
val z: Boolean = true,
val b: Byte = 0.toByte(),
val c: Char = 'c',
val c2: Char = '\n',
val sh: Short = 10.toShort(),
val i: Int = 10,
val l: Long = -10L,
val f: Float = 1.0f,
val d: Double = -1.0,
val s: String = "foo",
val iarr: IntArray = intArrayOf(1, 2, 3),
val larr: LongArray = longArrayOf(-1L, 0L, 1L),
val darr: DoubleArray = doubleArrayOf(7.3),
val sarr: Array<String> = arrayOf("a", "bc"),
val cl: Class<*> = Foo::class.java,
val clarr: Array<Class<*>> = arrayOf(Foo::class.java),
val em: Em = Em.BAR,
val emarr: Array<Em> = arrayOf(Em.FOO, Em.BAR)
) {
fun foo(a: Int = 5) {}
}
enum class Em {
FOO, BAR
}
@@ -0,0 +1,147 @@
import java.lang.System;
@kotlin.Metadata()
public enum Em {
/*public static final*/ FOO /* = new Em() */,
/*public static final*/ BAR /* = new Em() */;
Em() {
}
}
////////////////////
import java.lang.System;
@kotlin.Metadata()
public final class Foo {
private final boolean z = true;
private final byte b = (byte)0;
private final char c = 'c';
private final char c2 = '\n';
private final short sh = (short)10;
private final int i = 10;
private final long l = -10L;
private final float f = 1.0F;
private final double d = -1.0;
@org.jetbrains.annotations.NotNull()
private final java.lang.String s = "foo";
@org.jetbrains.annotations.NotNull()
private final int[] iarr = {1, 2, 3};
@org.jetbrains.annotations.NotNull()
private final long[] larr = {-1L, 0L, 1L};
@org.jetbrains.annotations.NotNull()
private final double[] darr = {7.3};
@org.jetbrains.annotations.NotNull()
private final java.lang.String[] sarr = {"a", "bc"};
@org.jetbrains.annotations.NotNull()
private final java.lang.Class<?> cl = null;
@org.jetbrains.annotations.NotNull()
private final java.lang.Class<?>[] clarr = null;
@org.jetbrains.annotations.NotNull()
private final Em em = Em.BAR;
@org.jetbrains.annotations.NotNull()
private final Em[] emarr = {Em.FOO, Em.BAR};
public final void foo(int a) {
}
public final boolean getZ() {
return false;
}
public final byte getB() {
return 0;
}
public final char getC() {
return '\u0000';
}
public final char getC2() {
return '\u0000';
}
public final short getSh() {
return 0;
}
public final int getI() {
return 0;
}
public final long getL() {
return 0L;
}
public final float getF() {
return 0.0F;
}
public final double getD() {
return 0.0;
}
@org.jetbrains.annotations.NotNull()
public final java.lang.String getS() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final int[] getIarr() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final long[] getLarr() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final double[] getDarr() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final java.lang.String[] getSarr() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final java.lang.Class<?> getCl() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final java.lang.Class<?>[] getClarr() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final Em getEm() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final Em[] getEmarr() {
return null;
}
public Foo(boolean z, byte b, char c, char c2, short sh, int i, long l, float f, double d, @org.jetbrains.annotations.NotNull()
java.lang.String s, @org.jetbrains.annotations.NotNull()
int[] iarr, @org.jetbrains.annotations.NotNull()
long[] larr, @org.jetbrains.annotations.NotNull()
double[] darr, @org.jetbrains.annotations.NotNull()
java.lang.String[] sarr, @org.jetbrains.annotations.NotNull()
java.lang.Class<?> cl, @org.jetbrains.annotations.NotNull()
java.lang.Class<?>[] clarr, @org.jetbrains.annotations.NotNull()
Em em, @org.jetbrains.annotations.NotNull()
Em[] emarr) {
super();
}
public Foo() {
super();
}
}
@@ -0,0 +1,42 @@
package error;
public final class NonExistentClass {
}
////////////////////
package test;
import java.lang.System;
@kotlin.Metadata()
@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
public abstract @interface Anno {
}
////////////////////
package test;
import java.lang.System;
@kotlin.Metadata()
@Anno()
public final class User {
@org.jetbrains.annotations.NotNull()
private final java.lang.String name = "John";
@org.jetbrains.annotations.NotNull()
public final java.lang.String getName() {
return null;
}
public User(@org.jetbrains.annotations.NotNull()
java.lang.String name, int age) {
super();
}
public User() {
super();
}
}
@@ -0,0 +1,8 @@
// DUMP_DEFAULT_PARAMETER_VALUES
package test
@Anno
class User(val name: String = "John", age: Int = 18)
internal annotation class Anno