in artist-core/src/main/kotlin/com/uber/artist/JavaArtistCodeGenerator.kt [96:154]
override fun generateConstructorsFor(stencil: JavaViewStencil, type: TypeSpec.Builder, rClass: ClassName) {
val count = stencil.constructorCount
for (i in 1..count) {
when (i) {
1 -> // Context constructor
type.addMethod(MethodSpec.constructorBuilder()
.addModifiers(Modifier.PUBLIC)
.addParameter(ParameterSpec.builder(TypeNames.Android.Context, "context")
.build())
.addCode(constructorBlock(stencil, rClass, count, i))
.build())
2 -> // Context, AttributeSet constructor
type.addMethod(MethodSpec.constructorBuilder()
.addModifiers(Modifier.PUBLIC)
.addParameter(ParameterSpec.builder(TypeNames.Android.Context, "context")
.build())
.addParameter(ParameterSpec.builder(TypeNames.Android.AttributeSet, "attrs")
.addAnnotation(TypeNames.Annotations.Nullable)
.build())
.addCode(constructorBlock(stencil, rClass, count, i))
.build())
3 -> // Context, AttributeSet, defStyleAttr constructor
type.addMethod(MethodSpec.constructorBuilder()
.addModifiers(Modifier.PUBLIC)
.addParameter(ParameterSpec.builder(TypeNames.Android.Context, "context")
.build())
.addParameter(ParameterSpec.builder(TypeNames.Android.AttributeSet, "attrs")
.addAnnotation(TypeNames.Annotations.Nullable)
.build())
.addParameter(ParameterSpec.builder(ClassName.INT, "defStyleAttr")
.addAnnotation(TypeNames.Annotations.AttrRes)
.build())
.addCode(constructorBlock(stencil, rClass, count, i))
.build())
4 -> // Context, AttributeSet, defStyleAttr, defStyleRes constructor
type.addMethod(MethodSpec.constructorBuilder()
.addModifiers(Modifier.PUBLIC)
.addParameter(ParameterSpec.builder(TypeNames.Android.Context, "context")
.build())
.addParameter(ParameterSpec.builder(TypeNames.Android.AttributeSet, "attrs")
.addAnnotation(TypeNames.Annotations.Nullable)
.build())
.addParameter(ParameterSpec.builder(ClassName.INT, "defStyleAttr")
.addAnnotation(TypeNames.Annotations.AttrRes)
.build())
.addParameter(ParameterSpec.builder(ClassName.INT, "defStyleRes")
.addAnnotation(TypeNames.Annotations.StyleRes)
.build())
.addAnnotation(AnnotationSpec.builder(TypeNames.Annotations.TargetApi)
.addMember("value", "\$T.\$L.\$L",
ClassName.get("android.os", "Build"),
"VERSION_CODES",
"LOLLIPOP")
.build())
.addCode(constructorBlock(stencil, rClass, count, i))
.build())
}
}
}