Format all Java files with google-java-format

Having a standard tool for formatting saves reviewers' valuable time.
google-java-format is Google's standard formatter and is somewhat
inspired by gofmt[1]. This commit formats everything using
google-java-format version 1.2.

The downside of this one-off formatting is breaking blame. This can be
somewhat hacked around with a tool like git-hyper-blame[2], but it's
definitely not optimal until/unless this kind of feature makes its way
to git core.

Not in this change:
* Tool support, e.g. Eclipse. The command must be run manually [3].
* Documentation of best practice, e.g. new 100-column default.

[1] https://talks.golang.org/2015/gofmt-en.slide#3
[2] https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/git-hyper-blame.html
[3] git ls-files | grep java$ | xargs google-java-format -i

Change-Id: Id5f3c6de95ce0b68b41f0a478b5c99a93675aaa3
Signed-off-by: David Pursehouse <dpursehouse@collab.net>
This commit is contained in:
Dave Borowitz
2016-11-13 09:56:32 -08:00
committed by David Pursehouse
parent 6723b6d0fa
commit 292fa154c1
2443 changed files with 54816 additions and 57825 deletions

View File

@@ -59,18 +59,20 @@ import com.google.gwtexpui.globalkey.client.KeyCommand;
import com.google.gwtexpui.globalkey.client.KeyCommandSet;
import com.google.gwtexpui.safehtml.client.SafeHtml;
import com.google.gwtexpui.safehtml.client.SafeHtmlBuilder;
import java.util.List;
public class Header extends Composite {
interface Binder extends UiBinder<HTMLPanel, Header> {}
private static final Binder uiBinder = GWT.create(Binder.class);
static {
Resources.I.style().ensureInjected();
}
private enum ReviewedState {
AUTO_REVIEW, LOADED
AUTO_REVIEW,
LOADED
}
@UiField CheckBox reviewed;
@@ -100,8 +102,13 @@ public class Header extends Composite {
private PreferencesAction prefsAction;
private ReviewedState reviewedState;
Header(KeyCommandSet keys, DiffObject base, DiffObject patchSetId,
String path, DiffView diffSreenType, DiffPreferences prefs) {
Header(
KeyCommandSet keys,
DiffObject base,
DiffObject patchSetId,
String path,
DiffView diffSreenType,
DiffPreferences prefs) {
initWidget(uiBinder.createAndBindUi(this));
this.keys = keys;
this.base = base;
@@ -115,8 +122,10 @@ public class Header extends Composite {
}
SafeHtml.setInnerHTML(filePath, formatPath(path));
up.setTargetHistoryToken(
PageLinks.toChange(patchSetId.asPatchSetId().getParentKey(),
base.asString(), patchSetId.asPatchSetId().getId()));
PageLinks.toChange(
patchSetId.asPatchSetId().getParentKey(),
base.asString(),
patchSetId.asPatchSetId().getId()));
}
public static SafeHtml formatPath(String path) {
@@ -148,36 +157,39 @@ public class Header extends Composite {
@Override
protected void onLoad() {
DiffApi.list(patchSetId, base.asPatchSetId(),
DiffApi.list(
patchSetId,
base.asPatchSetId(),
new GerritCallback<NativeMap<FileInfo>>() {
@Override
public void onSuccess(NativeMap<FileInfo> result) {
files = result.values();
FileInfo.sortFileInfoByPath(files);
fileNumber.setInnerText(Integer
.toString(Natives.asList(files).indexOf(result.get(path)) + 1));
fileNumber.setInnerText(
Integer.toString(Natives.asList(files).indexOf(result.get(path)) + 1));
fileCount.setInnerText(Integer.toString(files.length()));
}
});
if (Gerrit.isSignedIn()) {
ChangeApi.revision(patchSetId).view("files")
.addParameterTrue("reviewed")
.get(new AsyncCallback<JsArrayString>() {
@Override
public void onSuccess(JsArrayString result) {
boolean b = Natives.asList(result).contains(path);
reviewed.setValue(b, false);
if (!b && reviewedState == ReviewedState.AUTO_REVIEW) {
postAutoReviewed();
}
reviewedState = ReviewedState.LOADED;
}
ChangeApi.revision(patchSetId)
.view("files")
.addParameterTrue("reviewed")
.get(
new AsyncCallback<JsArrayString>() {
@Override
public void onSuccess(JsArrayString result) {
boolean b = Natives.asList(result).contains(path);
reviewed.setValue(b, false);
if (!b && reviewedState == ReviewedState.AUTO_REVIEW) {
postAutoReviewed();
}
reviewedState = ReviewedState.LOADED;
}
@Override
public void onFailure(Throwable caught) {
}
});
@Override
public void onFailure(Throwable caught) {}
});
}
}
@@ -193,8 +205,7 @@ public class Header extends Composite {
project.setInnerText(info.project());
}
void init(PreferencesAction pa, List<InlineHyperlink> links,
List<WebLinkInfo> webLinks) {
void init(PreferencesAction pa, List<InlineHyperlink> links, List<WebLinkInfo> webLinks) {
prefsAction = pa;
prefsAction.setPartner(preferences);
@@ -209,30 +220,29 @@ public class Header extends Composite {
@UiHandler("reviewed")
void onValueChange(ValueChangeEvent<Boolean> event) {
if (event.getValue()) {
reviewed().put(CallbackGroup.<ReviewInfo> emptyCallback());
reviewed().put(CallbackGroup.<ReviewInfo>emptyCallback());
} else {
reviewed().delete(CallbackGroup.<ReviewInfo> emptyCallback());
reviewed().delete(CallbackGroup.<ReviewInfo>emptyCallback());
}
}
private void postAutoReviewed() {
reviewed().background().put(new AsyncCallback<ReviewInfo>() {
@Override
public void onSuccess(ReviewInfo result) {
reviewed.setValue(true, false);
}
reviewed()
.background()
.put(
new AsyncCallback<ReviewInfo>() {
@Override
public void onSuccess(ReviewInfo result) {
reviewed.setValue(true, false);
}
@Override
public void onFailure(Throwable caught) {
}
});
@Override
public void onFailure(Throwable caught) {}
});
}
private RestApi reviewed() {
return ChangeApi.revision(patchSetId)
.view("files")
.id(path)
.view("reviewed");
return ChangeApi.revision(patchSetId).view("files").id(path).view("reviewed");
}
@UiHandler("preferences")
@@ -250,15 +260,16 @@ public class Header extends Composite {
if (info != null) {
final String url = url(info);
link.setTargetHistoryToken(url);
link.setTitle(PatchUtil.M.fileNameWithShortcutKey(
FileInfo.getFileName(info.path()),
Character.toString(key)));
KeyCommand k = new KeyCommand(0, key, help) {
@Override
public void onKeyPress(KeyPressEvent event) {
Gerrit.display(url);
}
};
link.setTitle(
PatchUtil.M.fileNameWithShortcutKey(
FileInfo.getFileName(info.path()), Character.toString(key)));
KeyCommand k =
new KeyCommand(0, key, help) {
@Override
public void onKeyPress(KeyPressEvent event) {
Gerrit.display(url);
}
};
keys.add(k);
if (link == prev) {
hasPrev = true;
@@ -298,10 +309,8 @@ public class Header extends Composite {
nextInfo = curr;
break;
}
KeyCommand p = setupNav(prev, '[', PatchUtil.C.previousFileHelp(),
prevInfo);
KeyCommand n = setupNav(next, ']', PatchUtil.C.nextFileHelp(),
nextInfo);
KeyCommand p = setupNav(prev, '[', PatchUtil.C.previousFileHelp(), prevInfo);
KeyCommand n = setupNav(next, ']', PatchUtil.C.nextFileHelp(), nextInfo);
if (p != null && n != null) {
keys.pair(p, n);
}
@@ -336,8 +345,7 @@ public class Header extends Composite {
default:
return new Runnable() {
@Override
public void run() {
}
public void run() {}
};
}
}
@@ -363,8 +371,7 @@ public class Header extends Composite {
UIObject.setVisible(noDiff, false); // Don't bother showing "No Differences"
} else {
JsArray<Region> regions = diff.content();
boolean b = regions.length() == 0
|| (regions.length() == 1 && regions.get(0).ab() != null);
boolean b = regions.length() == 0 || (regions.length() == 1 && regions.get(0).ab() != null);
UIObject.setVisible(noDiff, b);
}
}