All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.airbnb.epoxy.processor.ViewAttributeInfo.kt Maven / Gradle / Ivy

The newest version!
package com.airbnb.epoxy.processor

import androidx.annotation.NonNull
import androidx.annotation.Nullable
import androidx.room.compiler.processing.XElement
import androidx.room.compiler.processing.XFieldElement
import androidx.room.compiler.processing.XMethodElement
import androidx.room.compiler.processing.XNullability
import androidx.room.compiler.processing.XProcessingEnv
import androidx.room.compiler.processing.XTypeElement
import androidx.room.compiler.processing.XVariableElement
import androidx.room.compiler.processing.isField
import androidx.room.compiler.processing.isMethod
import com.airbnb.epoxy.CallbackProp
import com.airbnb.epoxy.ModelProp
import com.airbnb.epoxy.ModelProp.Option
import com.airbnb.epoxy.TextProp
import com.airbnb.epoxy.processor.Utils.capitalizeFirstLetter
import com.airbnb.epoxy.processor.Utils.getDefaultValue
import com.airbnb.epoxy.processor.Utils.isFieldPackagePrivate
import com.airbnb.epoxy.processor.Utils.removeSetPrefix
import com.airbnb.epoxy.processor.resourcescanning.ResourceScanner
import com.squareup.javapoet.AnnotationSpec
import com.squareup.javapoet.ArrayTypeName
import com.squareup.javapoet.ClassName
import com.squareup.javapoet.CodeBlock
import com.squareup.javapoet.ParameterizedTypeName
import com.squareup.javapoet.TypeName
import com.squareup.javapoet.TypeVariableName
import java.util.HashSet

internal val NON_NULL_ANNOTATION_SPEC = AnnotationSpec.builder(NonNull::class.java).build()
internal val NULLABLE_ANNOTATION_SPEC = AnnotationSpec.builder(Nullable::class.java).build()

sealed class ViewAttributeType {
    object Method : ViewAttributeType()
    object Field : ViewAttributeType()
}

class ViewAttributeInfo(
    private val viewElement: XTypeElement,
    viewPackage: String,
    val hasDefaultKotlinValue: Boolean,
    val viewAttributeElement: XElement,
    logger: Logger,
    resourceProcessor: ResourceScanner,
    memoizer: Memoizer
) : AttributeInfo(memoizer) {
    val propName: String
    val viewAttributeName: String
    val resetWithNull: Boolean
    val generateStringOverloads: Boolean
    val viewAttributeTypeName: ViewAttributeType?
    var constantFieldNameForDefaultValue: String? = null

    init {
        val propAnnotation = viewAttributeElement.getAnnotation(ModelProp::class)
        val textAnnotation = viewAttributeElement.getAnnotation(TextProp::class)
        val callbackAnnotation = viewAttributeElement.getAnnotation(CallbackProp::class)

        val options = HashSet

\n") } if (isRequired) { builder.add("Required.") } else { builder.add("Optional: ") when { hasDefaultKotlinValue -> { builder.add("View function has a Kotlin default argument") } constantFieldNameForDefaultValue == null -> { builder.add("Default value is \$L", codeToSetDefault.value()) } else -> { builder.add( "Default value is {@value \$T#\$L}", viewElement.className, constantFieldNameForDefaultValue ) } } } if (viewAttributeTypeName == ViewAttributeType.Field) { builder.add( "\n\n@see \$T#\$L", viewElement.type.typeNameWithWorkaround(memoizer), viewAttributeName ) } else { builder.add( "\n\n@see \$T#\$L(\$T)", viewElement.type.typeNameWithWorkaround(memoizer), viewAttributeName, attributeTypeName ) } javaDoc = builder .add("\n").build() } override fun generatedSetterName(): String = propName override fun generatedGetterName(isOverload: Boolean): String { if (isOverload) { // Avoid method name collisions for overloaded method by appending the return type return propName + getSimpleName(typeName)!! } else if (generateStringOverloads) { return "get" + capitalizeFirstLetter(propName) } return propName } override fun toString(): String { return ( "View Prop {" + "view='" + viewElement.name + '\'' + ", name='" + viewAttributeName + '\'' + ", type=" + typeName + ", hasDefaultKotlinValue=" + hasDefaultKotlinValue + '}' ) } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy