Search in sources :

Example 11 with Builder

use of com.squareup.javapoet.MethodSpec.Builder in project glide by bumptech.

the class RequestManagerGenerator method generateRequestManagerRequestBuilderMethodOverride.

/**
 * Generates overrides of existing RequestManager methods so that they return our generated
 * RequestBuilder subtype.
 */
private MethodSpec generateRequestManagerRequestBuilderMethodOverride(ExecutableElement methodToOverride) {
    // We've already verified that this method returns a RequestBuilder and RequestBuilders have
    // exactly one type argument, so this is safe unless those assumptions change.
    TypeMirror typeArgument = ((DeclaredType) methodToOverride.getReturnType()).getTypeArguments().get(0);
    ParameterizedTypeName generatedRequestBuilderOfType = ParameterizedTypeName.get(generatedRequestBuilderClassName, ClassName.get(typeArgument));
    MethodSpec.Builder builder = ProcessorUtil.overriding(methodToOverride).returns(generatedRequestBuilderOfType);
    builder.addCode(ProcessorUtil.generateCastingSuperCall(generatedRequestBuilderOfType, builder.build()));
    for (AnnotationMirror mirror : methodToOverride.getAnnotationMirrors()) {
        builder.addAnnotation(AnnotationSpec.get(mirror));
    }
    return builder.build();
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeMirror(javax.lang.model.type.TypeMirror) MethodSpec(com.squareup.javapoet.MethodSpec) Builder(com.squareup.javapoet.MethodSpec.Builder) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName)

Aggregations

Builder (com.squareup.javapoet.MethodSpec.Builder)11 MethodSpec (com.squareup.javapoet.MethodSpec)4 ArrayList (java.util.ArrayList)3 ArrayTypeName (com.squareup.javapoet.ArrayTypeName)2 ClassName (com.squareup.javapoet.ClassName)2 ParameterSpec (com.squareup.javapoet.ParameterSpec)2 TypeName (com.squareup.javapoet.TypeName)2 ConstructorInfo (com.airbnb.epoxy.ClassToGenerateInfo.ConstructorInfo)1 MethodInfo (com.airbnb.epoxy.ClassToGenerateInfo.MethodInfo)1 MethodSpec.constructorBuilder (com.squareup.javapoet.MethodSpec.constructorBuilder)1 ParameterizedTypeName (com.squareup.javapoet.ParameterizedTypeName)1 TypeSpec.classBuilder (com.squareup.javapoet.TypeSpec.classBuilder)1 AnnotationMirror (javax.lang.model.element.AnnotationMirror)1 TypeElement (javax.lang.model.element.TypeElement)1 TypeMirror (javax.lang.model.type.TypeMirror)1