提交 b39a9dbf 编写于 作者: S Sam Judd

Call clone() before calling extension methods if auto clone is enabled.

Otherwise when our extension methods mutate the RequestOptions we pass 
them, the mutations create a new RequestOptions object that’s dropped
at the end of the extension method, which causes any options applied in
the extension method to be ignored. Cloning first matches the behavior
of other RequestOptions methods and ensures that the RequestOptions 
object passed into the extension method is mutable. 
上级 48754e61
...@@ -231,21 +231,28 @@ final class RequestOptionsGenerator { ...@@ -231,21 +231,28 @@ final class RequestOptionsGenerator {
List<? extends VariableElement> parameters = List<? extends VariableElement> parameters =
element.getParameters().subList(1, element.getParameters().size()); element.getParameters().subList(1, element.getParameters().size());
// Add the correct super() call. // Generates the String and list of arguments to pass in when calling this method or super.
if (overrideType == OVERRIDE_EXTEND) { // IE centerCrop(context) creates methodLiterals="%L" and methodArgs=[centerCrop, context].
String callSuper = "super.$L("; List<Object> methodArgs = new ArrayList<>();
List<Object> args = new ArrayList<>(); methodArgs.add(element.getSimpleName().toString());
args.add(element.getSimpleName().toString()); String methodLiterals = "";
if (!parameters.isEmpty()) { if (!parameters.isEmpty()) {
for (VariableElement variable : parameters) { for (VariableElement variable : parameters) {
callSuper += "$L, "; methodLiterals += "$L, ";
args.add(variable.getSimpleName().toString()); methodArgs.add(variable.getSimpleName().toString());
}
callSuper = callSuper.substring(0, callSuper.length() - 2);
} }
callSuper += ")"; methodLiterals = methodLiterals.substring(0, methodLiterals.length() - 2);
}
builder.beginControlFlow("if (isAutoCloneEnabled())")
.addStatement(
"return clone().$N(" + methodLiterals + ")", methodArgs.toArray(new Object[0]))
.endControlFlow();
builder.addStatement(callSuper, args.toArray(new Object[0])) // Add the correct super() call.
if (overrideType == OVERRIDE_EXTEND) {
String callSuper = "super.$L(" + methodLiterals + ")";
builder.addStatement(callSuper, methodArgs.toArray(new Object[0]))
.addJavadoc(processorUtil.generateSeeMethodJavadoc( .addJavadoc(processorUtil.generateSeeMethodJavadoc(
requestOptionsName, methodName, parameters)) requestOptionsName, methodName, parameters))
.addAnnotation(Override.class); .addAnnotation(Override.class);
......
...@@ -1288,6 +1288,10 @@ public class RequestOptions implements Cloneable { ...@@ -1288,6 +1288,10 @@ public class RequestOptions implements Cloneable {
return this; return this;
} }
protected boolean isAutoCloneEnabled() {
return isAutoCloneEnabled;
}
@NonNull @NonNull
public final Map<Class<?>, Transformation<?>> getTransformations() { public final Map<Class<?>, Transformation<?>> getTransformations() {
return transformations; return transformations;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册