Revert "Kapt: Support default constant values for constructor parameters"

This reverts commit e4d758b6
This commit is contained in:
Yan Zhulanow
2019-03-22 03:58:22 +03:00
parent 215d24e12c
commit 4c794b1302
7 changed files with 12 additions and 55 deletions
@@ -651,28 +651,24 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
val value = field.value
val origin = kaptContext.origins[field]
val initializer = when (val element = origin?.element) {
is KtProperty -> element.initializer
is KtParameter -> element.defaultValue
else -> null
}
val propertyInitializer = (origin?.element as? KtProperty)?.initializer
if (value != null) {
if (initializer != null) {
return convertConstantValueArguments(value, listOf(initializer))
if (propertyInitializer != null) {
return convertConstantValueArguments(value, listOf(propertyInitializer))
}
return convertValueOfPrimitiveTypeOrString(value)
}
val propertyType = (origin?.descriptor as? PropertyDescriptor)?.returnType
if (initializer != null && propertyType != null) {
if (propertyInitializer != null && propertyType != null) {
val moduleDescriptor = kaptContext.generationState.module
val evaluator = ConstantExpressionEvaluator(moduleDescriptor, LanguageVersionSettingsImpl.DEFAULT, kaptContext.project)
val trace = DelegatingBindingTrace(kaptContext.bindingContext, "Kapt")
val const = evaluator.evaluateExpression(initializer, trace, propertyType)
val const = evaluator.evaluateExpression(propertyInitializer, trace, propertyType)
if (const != null && !const.isError && const.canBeUsedInAnnotations && !const.usesNonConstValAsConstant) {
return convertConstantValueArguments(const.getValue(propertyType), listOf(initializer))
return convertConstantValueArguments(const.getValue(propertyType), listOf(propertyInitializer))
}
}
@@ -5,7 +5,7 @@ public final class State {
private final int someInt = 0;
private final long someLong = 0L;
@org.jetbrains.annotations.NotNull()
private final java.lang.String someString = "";
private final java.lang.String someString = null;
public final int getSomeInt() {
return 0;
@@ -38,9 +38,9 @@ import java.lang.System;
@kotlin.Metadata()
public final class State2 {
public final int someInt = 0;
public final long someLong = 2L;
public final long someLong = 0L;
@org.jetbrains.annotations.NotNull()
public final java.lang.String someString = "";
public final java.lang.String someString = null;
public final int test(int someInt, long someLong, @org.jetbrains.annotations.NotNull()
java.lang.String someString) {
+1 -2
View File
@@ -66,8 +66,7 @@ annotation class Anno(
val a8: Double,
val a9: String)
// TODO generate the right default field value for 'p0'
class MyActivity(val p0: Int = lib.R.id.textView, val p1: Int = 5) {
class MyActivity {
@Bind(LibR.id.textView)
@BindField(LibR.id.textView)
val a = 0
@@ -134,8 +134,6 @@ public final class MyActivity {
public final int propD = app.B.id.textView;
public int propE = app.B.id.textView;
private final int propF = 0;
private final int p0 = 0;
private final int p1 = 5;
@Bind(id = lib.R.id.textView)
public static void a$annotations() {
@@ -226,18 +224,6 @@ public final class MyActivity {
return 0;
}
public final int getP0() {
return 0;
}
public final int getP1() {
return 0;
}
public MyActivity(int p0, int p1) {
super();
}
public MyActivity() {
super();
}
@@ -21,6 +21,4 @@ object Foo {
object Boo {
val z = foo()
fun foo() = "abc"
}
class Zoo(val p: Int = 100)
}
@@ -116,25 +116,3 @@ public final class Foo {
super();
}
}
////////////////////
import java.lang.System;
@kotlin.Metadata()
public final class Zoo {
private final int p = 100;
public final int getP() {
return 0;
}
public Zoo(int p) {
super();
}
public Zoo() {
super();
}
}
@@ -26,7 +26,7 @@ public final class State {
private final int someInt = 0;
private final long someLong = 0L;
@org.jetbrains.annotations.NotNull()
private final java.lang.String someString = "";
private final java.lang.String someString = null;
public final int getSomeInt() {
return 0;