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();
}
Aggregations