ChangeReportFormatter: Convert Input to use AutoValue.Builder
Change-Id: I5e1a4550701a9eaad2bbfdb9e7183a21dfda7cec Signed-off-by: David Pursehouse <dpursehouse@collab.net> Helped-by: Patrick Hiesel <hiesel@google.com>
This commit is contained in:
@@ -14,48 +14,55 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.git;
|
package com.google.gerrit.server.git;
|
||||||
|
|
||||||
|
import com.google.auto.value.AutoValue;
|
||||||
|
import com.google.gerrit.common.Nullable;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
|
|
||||||
public interface ChangeReportFormatter {
|
public interface ChangeReportFormatter {
|
||||||
public static class Input {
|
@AutoValue
|
||||||
private final Change change;
|
public abstract static class Input {
|
||||||
private String subject;
|
public abstract Change change();
|
||||||
private Boolean draft;
|
|
||||||
private Boolean edit;
|
|
||||||
|
|
||||||
public Input(Change change) {
|
@Nullable
|
||||||
this.change = change;
|
public abstract String subject();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isDraft();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isEdit();
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new AutoValue_ChangeReportFormatter_Input.Builder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Input setDraft(boolean draft) {
|
@AutoValue.Builder
|
||||||
this.draft = draft;
|
public abstract static class Builder {
|
||||||
return this;
|
public abstract Builder setChange(Change val);
|
||||||
}
|
|
||||||
|
|
||||||
public Input setEdit(boolean edit) {
|
public abstract Builder setSubject(String val);
|
||||||
this.edit = edit;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Input setSubject(String subject) {
|
public abstract Builder setIsDraft(Boolean val);
|
||||||
this.subject = subject;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Change getChange() {
|
public abstract Builder setIsEdit(Boolean val);
|
||||||
return change;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSubject() {
|
abstract Change change();
|
||||||
return subject == null ? change.getSubject() : subject;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDraft() {
|
abstract String subject();
|
||||||
return draft == null ? Change.Status.DRAFT == change.getStatus() : draft;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEdit() {
|
abstract Boolean isDraft();
|
||||||
return edit == null ? false : edit;
|
|
||||||
|
abstract Boolean isEdit();
|
||||||
|
|
||||||
|
abstract Input autoBuild();
|
||||||
|
|
||||||
|
public Input build() {
|
||||||
|
setChange(change());
|
||||||
|
setSubject(subject() == null ? change().getSubject() : subject());
|
||||||
|
setIsDraft(isDraft() == null ? Change.Status.DRAFT == change().getStatus() : isDraft());
|
||||||
|
setIsEdit(isEdit() == null ? false : isEdit());
|
||||||
|
return autoBuild();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -39,16 +39,16 @@ public class DefaultChangeReportFormatter implements ChangeReportFormatter {
|
|||||||
@Override
|
@Override
|
||||||
public String changeClosed(ChangeReportFormatter.Input input) {
|
public String changeClosed(ChangeReportFormatter.Input input) {
|
||||||
return String.format(
|
return String.format(
|
||||||
"change %s closed", ChangeUtil.formatChangeUrl(canonicalWebUrl, input.getChange()));
|
"change %s closed", ChangeUtil.formatChangeUrl(canonicalWebUrl, input.change()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String formatChangeUrl(String url, Input input) {
|
private String formatChangeUrl(String url, Input input) {
|
||||||
StringBuilder m =
|
StringBuilder m =
|
||||||
new StringBuilder()
|
new StringBuilder()
|
||||||
.append(" ")
|
.append(" ")
|
||||||
.append(ChangeUtil.formatChangeUrl(url, input.getChange()))
|
.append(ChangeUtil.formatChangeUrl(url, input.change()))
|
||||||
.append(" ")
|
.append(" ")
|
||||||
.append(ChangeUtil.cropSubject(input.getSubject()));
|
.append(ChangeUtil.cropSubject(input.subject()));
|
||||||
if (input.isDraft()) {
|
if (input.isDraft()) {
|
||||||
m.append(" [DRAFT]");
|
m.append(" [DRAFT]");
|
||||||
}
|
}
|
||||||
|
@@ -687,7 +687,9 @@ public class ReceiveCommits {
|
|||||||
addMessage("");
|
addMessage("");
|
||||||
addMessage("New Changes:");
|
addMessage("New Changes:");
|
||||||
for (CreateRequest c : created) {
|
for (CreateRequest c : created) {
|
||||||
addMessage(changeFormatter.newChange(new ChangeReportFormatter.Input(c.change)));
|
addMessage(
|
||||||
|
changeFormatter.newChange(
|
||||||
|
ChangeReportFormatter.Input.builder().setChange(c.change).build()));
|
||||||
}
|
}
|
||||||
addMessage("");
|
addMessage("");
|
||||||
}
|
}
|
||||||
@@ -718,10 +720,12 @@ public class ReceiveCommits {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ChangeReportFormatter.Input input =
|
ChangeReportFormatter.Input input =
|
||||||
new ChangeReportFormatter.Input(u.notes.getChange())
|
ChangeReportFormatter.Input.builder()
|
||||||
|
.setChange(u.notes.getChange())
|
||||||
.setSubject(subject)
|
.setSubject(subject)
|
||||||
.setDraft(u.replaceOp != null && u.replaceOp.getPatchSet().isDraft())
|
.setIsDraft(u.replaceOp != null && u.replaceOp.getPatchSet().isDraft())
|
||||||
.setEdit(edit);
|
.setIsEdit(edit)
|
||||||
|
.build();
|
||||||
addMessage(changeFormatter.changeUpdated(input));
|
addMessage(changeFormatter.changeUpdated(input));
|
||||||
}
|
}
|
||||||
addMessage("");
|
addMessage("");
|
||||||
@@ -1677,7 +1681,10 @@ public class ReceiveCommits {
|
|||||||
private boolean requestReplace(
|
private boolean requestReplace(
|
||||||
ReceiveCommand cmd, boolean checkMergedInto, Change change, RevCommit newCommit) {
|
ReceiveCommand cmd, boolean checkMergedInto, Change change, RevCommit newCommit) {
|
||||||
if (change.getStatus().isClosed()) {
|
if (change.getStatus().isClosed()) {
|
||||||
reject(cmd, changeFormatter.changeClosed(new ChangeReportFormatter.Input(change)));
|
reject(
|
||||||
|
cmd,
|
||||||
|
changeFormatter.changeClosed(
|
||||||
|
ChangeReportFormatter.Input.builder().setChange(change).build()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user