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

@@ -18,13 +18,11 @@ import com.google.gerrit.client.AccountFormatter;
import com.google.gerrit.client.DateFormatter;
import com.google.gerrit.client.RelativeDateFormatter;
import com.google.gerrit.client.info.AccountInfo;
import java.util.Date;
public class FormatUtil {
private static final AccountFormatter accountFormatter =
new AccountFormatter(Plugin.get().getServerInfo().user()
.anonymousCowardName());
new AccountFormatter(Plugin.get().getServerInfo().user().anonymousCowardName());
/** Format a date using a really short format. */
public static String shortFormat(Date dt) {
@@ -52,13 +50,14 @@ public class FormatUtil {
/**
* Formats an account as a name and an email address.
* <p>
* Example output:
*
* <p>Example output:
*
* <ul>
* <li>{@code A U. Thor &lt;author@example.com&gt;}: full populated</li>
* <li>{@code A U. Thor (12)}: missing email address</li>
* <li>{@code Anonymous Coward &lt;author@example.com&gt;}: missing name</li>
* <li>{@code Anonymous Coward (12)}: missing name and email address</li>
* <li>{@code A U. Thor &lt;author@example.com&gt;}: full populated
* <li>{@code A U. Thor (12)}: missing email address
* <li>{@code Anonymous Coward &lt;author@example.com&gt;}: missing name
* <li>{@code Anonymous Coward (12)}: missing name and email address
* </ul>
*/
public static String nameEmail(AccountInfo info) {
@@ -67,9 +66,9 @@ public class FormatUtil {
/**
* Formats an account name.
* <p>
* If the account has a full name, it returns only the full name. Otherwise it
* returns a longer form that includes the email address.
*
* <p>If the account has a full name, it returns only the full name. Otherwise it returns a longer
* form that includes the email address.
*/
public static String name(AccountInfo info) {
return accountFormatter.name(info);

View File

@@ -26,12 +26,11 @@ import com.google.gwt.core.client.JavaScriptObject;
/**
* Wrapper around the plugin instance exposed by Gerrit.
*
* Listeners for events generated by the main UI must be registered
* through this instance.
* <p>Listeners for events generated by the main UI must be registered through this instance.
*/
public final class Plugin extends JavaScriptObject {
private static final Plugin self = install(
GWT.getModuleBaseURL() + GWT.getModuleName() + ".nocache.js");
private static final Plugin self =
install(GWT.getModuleBaseURL() + GWT.getModuleName() + ".nocache.js");
/** Obtain the plugin instance wrapper. */
public static Plugin get() {
@@ -44,65 +43,57 @@ public final class Plugin extends JavaScriptObject {
}
/** Installed name of the plugin. */
public native String getPluginName()
/*-{ return this.getPluginName() }-*/;
public native String getPluginName() /*-{ return this.getPluginName() }-*/;
/** Navigate the UI to the screen identified by the token. */
public native void go(String token)
/*-{ return this.go(token) }-*/;
public native void go(String token) /*-{ return this.go(token) }-*/;
/** Refresh the current UI. */
public native void refresh()
/*-{ return this.refresh() }-*/;
public native void refresh() /*-{ return this.refresh() }-*/;
/** Refresh Gerrit's menu bar. */
public native void refreshMenuBar()
/*-{ return this.refreshMenuBar() }-*/;
public native void refreshMenuBar() /*-{ return this.refreshMenuBar() }-*/;
/** @return the preferences of the currently signed in user, the default preferences if not signed in */
public native GeneralPreferences getUserPreferences()
/*-{ return this.getUserPreferences() }-*/;
/**
* @return the preferences of the currently signed in user, the default preferences if not signed
* in
*/
public native GeneralPreferences getUserPreferences() /*-{ return this.getUserPreferences() }-*/;
/** Refresh the user preferences of the current user. */
public native void refreshUserPreferences()
/*-{ return this.refreshUserPreferences() }-*/;
public native void refreshUserPreferences() /*-{ return this.refreshUserPreferences() }-*/;
/** @return the server info */
public native ServerInfo getServerInfo()
/*-{ return this.getServerInfo() }-*/;
public native ServerInfo getServerInfo() /*-{ return this.getServerInfo() }-*/;
/** @return the current user */
public native AccountInfo getCurrentUser()
/*-{ return this.getCurrentUser() }-*/;
public native AccountInfo getCurrentUser() /*-{ return this.getCurrentUser() }-*/;
/** Check if user is signed in. */
public native boolean isSignedIn()
/*-{ return this.isSignedIn() }-*/;
public native boolean isSignedIn() /*-{ return this.isSignedIn() }-*/;
/** Show message in Gerrit's ErrorDialog. */
public native void showError(String message)
/*-{ return this.showError(message) }-*/;
public native void showError(String message) /*-{ return this.showError(message) }-*/;
/**
* Register a screen displayed at {@code /#/x/plugin/token}.
*
* @param token literal anchor token appearing after the plugin name. For
* regular expression matching use {@code screenRegex()} .
* @param token literal anchor token appearing after the plugin name. For regular expression
* matching use {@code screenRegex()} .
* @param entry callback function invoked to create the screen widgets.
*/
public void screen(String token, Screen.EntryPoint entry) {
screen(token, wrap(entry));
}
private native void screen(String t, JavaScriptObject e)
/*-{ this.screen(t, e) }-*/;
private native void screen(String t, JavaScriptObject e) /*-{ this.screen(t, e) }-*/;
/**
* Register a screen displayed at {@code /#/x/plugin/regex}.
*
* @param regex JavaScript {@code RegExp} expression to match the anchor token
* after the plugin name. Matching groups are exposed through the
* {@code Screen} object passed into the {@code Screen.EntryPoint}.
* @param regex JavaScript {@code RegExp} expression to match the anchor token after the plugin
* name. Matching groups are exposed through the {@code Screen} object passed into the {@code
* Screen.EntryPoint}.
* @param entry callback function invoked to create the screen widgets.
*/
public void screenRegex(String regex, Screen.EntryPoint entry) {
@@ -110,7 +101,7 @@ public final class Plugin extends JavaScriptObject {
}
private native void screenRegex(String p, JavaScriptObject e)
/*-{ this.screen(new $wnd.RegExp(p), e) }-*/;
/*-{ this.screen(new $wnd.RegExp(p), e) }-*/ ;
/**
* Register a settings screen displayed at {@code /#/settings/x/plugin/token}.
@@ -123,29 +114,27 @@ public final class Plugin extends JavaScriptObject {
}
private native void settingsScreen(String t, String m, JavaScriptObject e)
/*-{ this.settingsScreen(t, m, e) }-*/;
/*-{ this.settingsScreen(t, m, e) }-*/ ;
/**
* Register a panel for a UI extension point.
*
* @param extensionPoint the UI extension point for which the panel should be
* registered.
* @param extensionPoint the UI extension point for which the panel should be registered.
* @param entry callback function invoked to create the panel widgets.
*/
public void panel(GerritUiExtensionPoint extensionPoint, Panel.EntryPoint entry) {
panel(extensionPoint.name(), wrap(entry));
}
private native void panel(String i, JavaScriptObject e)
/*-{ this.panel(i, e) }-*/;
private native void panel(String i, JavaScriptObject e) /*-{ this.panel(i, e) }-*/;
protected Plugin() {
}
protected Plugin() {}
native void _initialized() /*-{ this._success = true }-*/;
native void _loaded() /*-{ this._loadedGwt() }-*/;
private static native Plugin install(String u)
/*-{ return $wnd.Gerrit.installGwt(u) }-*/;
private static native Plugin install(String u) /*-{ return $wnd.Gerrit.installGwt(u) }-*/;
private static native JavaScriptObject wrap(Screen.EntryPoint b) /*-{
return $entry(function(c){

View File

@@ -19,16 +19,17 @@ import com.google.gwt.core.client.EntryPoint;
/**
* Base class for writing Gerrit Web UI plugins
*
* Writing a plugin:
* <p>Writing a plugin:
*
* <ol>
* <li>Declare subtype of Plugin</li>
* <li>Bind WebUiPlugin to GwtPlugin implementation in Gerrit-Module</li>
* <li>Declare subtype of Plugin
* <li>Bind WebUiPlugin to GwtPlugin implementation in Gerrit-Module
* </ol>
*/
public abstract class PluginEntryPoint implements EntryPoint {
/**
* The plugin entry point method, called automatically by loading
* a module that declares an implementing class as an entry point.
* The plugin entry point method, called automatically by loading a module that declares an
* implementing class as an entry point.
*/
public abstract void onPluginLoad();

View File

@@ -22,7 +22,7 @@ import com.google.gwt.user.client.ui.SimplePanel;
/**
* Panel that extends a Gerrit core screen contributed by this plugin.
*
* Panel should be registered early at module load:
* <p>Panel should be registered early at module load:
*
* <pre>
* &#064;Override
@@ -42,17 +42,16 @@ public class Panel extends SimplePanel {
public interface EntryPoint {
/**
* Invoked when the panel has been created.
* <p>
* The implementation should create a single widget to define the content of
* this panel and add it to the passed panel instance.
* <p>
* To use multiple widgets, compose them in panels such as {@code FlowPanel}
* and add only the top level widget to the panel.
* <p>
* The panel is already attached to the browser DOM.
* Any widgets added to the screen will immediately receive {@code onLoad()}.
* GWT will fire {@code onUnload()} when the panel is removed from the UI,
* generally caused by the user navigating to another screen.
*
* <p>The implementation should create a single widget to define the content of this panel and
* add it to the passed panel instance.
*
* <p>To use multiple widgets, compose them in panels such as {@code FlowPanel} and add only the
* top level widget to the panel.
*
* <p>The panel is already attached to the browser DOM. Any widgets added to the screen will
* immediately receive {@code onLoad()}. GWT will fire {@code onUnload()} when the panel is
* removed from the UI, generally caused by the user navigating to another screen.
*
* @param panel panel that will contain the panel widget.
*/
@@ -63,15 +62,16 @@ public class Panel extends SimplePanel {
native Element body() /*-{ return this.body }-*/;
native String get(String k) /*-{ return this.p[k]; }-*/;
native int getInt(String k, int d) /*-{
return this.p.hasOwnProperty(k) ? this.p[k] : d
}-*/;
native int getBoolean(String k, boolean d) /*-{
return this.p.hasOwnProperty(k) ? this.p[k] : d
}-*/;
native JavaScriptObject getObject(String k)
/*-{ return this.p[k]; }-*/;
native JavaScriptObject getObject(String k) /*-{ return this.p[k]; }-*/;
native void detach(Panel p) /*-{
this.onUnload($entry(function(){
@@ -79,8 +79,7 @@ public class Panel extends SimplePanel {
}));
}-*/;
protected Context() {
}
protected Context() {}
}
private final Context ctx;

View File

@@ -17,6 +17,5 @@ package com.google.gerrit.plugin.client.rpc;
import com.google.gwt.core.client.JavaScriptObject;
public class NoContent extends JavaScriptObject {
protected NoContent() {
}
protected NoContent() {}
}

View File

@@ -100,8 +100,7 @@ public class RestApi {
return path.toString();
}
public <T extends JavaScriptObject>
void get(AsyncCallback<T> cb) {
public <T extends JavaScriptObject> void get(AsyncCallback<T> cb) {
get(path(), wrap(cb));
}
@@ -109,62 +108,51 @@ public class RestApi {
get(NativeString.unwrap(cb));
}
private static native void get(String p, JavaScriptObject r)
/*-{ $wnd.Gerrit.get_raw(p, r) }-*/;
private static native void get(String p, JavaScriptObject r) /*-{ $wnd.Gerrit.get_raw(p, r) }-*/;
public <T extends JavaScriptObject>
void put(AsyncCallback<T> cb) {
public <T extends JavaScriptObject> void put(AsyncCallback<T> cb) {
put(path(), wrap(cb));
}
private static native void put(String p, JavaScriptObject r)
/*-{ $wnd.Gerrit.put_raw(p, r) }-*/;
private static native void put(String p, JavaScriptObject r) /*-{ $wnd.Gerrit.put_raw(p, r) }-*/;
public <T extends JavaScriptObject>
void put(String content, AsyncCallback<T> cb) {
public <T extends JavaScriptObject> void put(String content, AsyncCallback<T> cb) {
put(path(), content, wrap(cb));
}
private static native
void put(String p, String c, JavaScriptObject r)
/*-{ $wnd.Gerrit.put_raw(p, c, r) }-*/;
private static native void put(String p, String c, JavaScriptObject r)
/*-{ $wnd.Gerrit.put_raw(p, c, r) }-*/ ;
public <T extends JavaScriptObject>
void put(JavaScriptObject content, AsyncCallback<T> cb) {
public <T extends JavaScriptObject> void put(JavaScriptObject content, AsyncCallback<T> cb) {
put(path(), content, wrap(cb));
}
private static native
void put(String p, JavaScriptObject c, JavaScriptObject r)
/*-{ $wnd.Gerrit.put_raw(p, c, r) }-*/;
private static native void put(String p, JavaScriptObject c, JavaScriptObject r)
/*-{ $wnd.Gerrit.put_raw(p, c, r) }-*/ ;
public <T extends JavaScriptObject>
void post(String content, AsyncCallback<T> cb) {
public <T extends JavaScriptObject> void post(String content, AsyncCallback<T> cb) {
post(path(), content, wrap(cb));
}
private static native
void post(String p, String c, JavaScriptObject r)
/*-{ $wnd.Gerrit.post_raw(p, c, r) }-*/;
private static native void post(String p, String c, JavaScriptObject r)
/*-{ $wnd.Gerrit.post_raw(p, c, r) }-*/ ;
public <T extends JavaScriptObject>
void post(JavaScriptObject content, AsyncCallback<T> cb) {
public <T extends JavaScriptObject> void post(JavaScriptObject content, AsyncCallback<T> cb) {
post(path(), content, wrap(cb));
}
private static native
void post(String p, JavaScriptObject c, JavaScriptObject r)
/*-{ $wnd.Gerrit.post_raw(p, c, r) }-*/;
private static native void post(String p, JavaScriptObject c, JavaScriptObject r)
/*-{ $wnd.Gerrit.post_raw(p, c, r) }-*/ ;
public void delete(AsyncCallback<NoContent> cb) {
delete(path(), wrap(cb));
}
private static native void delete(String p, JavaScriptObject r)
/*-{ $wnd.Gerrit.del_raw(p, r) }-*/;
/*-{ $wnd.Gerrit.del_raw(p, r) }-*/ ;
private static native <T extends JavaScriptObject>
JavaScriptObject wrap(AsyncCallback<T> b) /*-{
private static native <T extends JavaScriptObject> JavaScriptObject wrap(
AsyncCallback<T> b) /*-{
return function(r) {
b.@com.google.gwt.user.client.rpc.AsyncCallback::onSuccess(Ljava/lang/Object;)(r)
}

View File

@@ -23,7 +23,7 @@ import com.google.gwt.user.client.ui.Widget;
/**
* Screen contributed by this plugin.
*
* Screens should be registered early at module load:
* <p>Screens should be registered early at module load:
*
* <pre>
* &#064;Override
@@ -43,18 +43,18 @@ public final class Screen extends SimplePanel {
public interface EntryPoint {
/**
* Invoked when the screen has been created, but not yet displayed.
* <p>
* The implementation should create a single widget to define the content of
* this screen and added it to the passed screen instance. When the screen
* is ready to be displayed, call {@link Screen#show()}.
* <p>
* To use multiple widgets, compose them in panels such as {@code FlowPanel}
* and add only the top level widget to the screen.
* <p>
* The screen is already attached to the browser DOM in an invisible area.
* Any widgets added to the screen will immediately receive {@code onLoad()}.
* GWT will fire {@code onUnload()} when the screen is removed from the UI,
* generally caused by the user navigating to another screen.
*
* <p>The implementation should create a single widget to define the content of this screen and
* added it to the passed screen instance. When the screen is ready to be displayed, call {@link
* Screen#show()}.
*
* <p>To use multiple widgets, compose them in panels such as {@code FlowPanel} and add only the
* top level widget to the screen.
*
* <p>The screen is already attached to the browser DOM in an invisible area. Any widgets added
* to the screen will immediately receive {@code onLoad()}. GWT will fire {@code onUnload()}
* when the screen is removed from the UI, generally caused by the user navigating to another
* screen.
*
* @param screen panel that will contain the screen widget.
*/
@@ -63,18 +63,22 @@ public final class Screen extends SimplePanel {
static final class Context extends JavaScriptObject {
native Element body() /*-{ return this.body }-*/;
native JsArrayString token_match() /*-{ return this.token_match }-*/;
native void show() /*-{ this.show() }-*/;
native void setTitle(String t) /*-{ this.setTitle(t) }-*/;
native void setWindowTitle(String t) /*-{ this.setWindowTitle(t) }-*/;
native void detach(Screen s) /*-{
this.onUnload($entry(function(){
s.@com.google.gwt.user.client.ui.Widget::onDetach()();
}));
}-*/;
protected Context() {
}
protected Context() {}
}
private final Context ctx;
@@ -92,8 +96,8 @@ public final class Screen extends SimplePanel {
}
/**
* @param group groups range from 1 to {@code getTokenGroups() - 1}. Token
* group 0 is the entire token, see {@link #getToken()}.
* @param group groups range from 1 to {@code getTokenGroups() - 1}. Token group 0 is the entire
* token, see {@link #getToken()}.
* @return the token from the regex match group.
*/
public String getToken(int group) {

View File

@@ -20,7 +20,6 @@ import com.google.gerrit.plugin.client.rpc.RestApi;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.SuggestOracle;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -30,9 +29,7 @@ public class GroupSuggestOracle extends SuggestOracle {
private final int chars;
/**
* @param chars minimum chars to start suggesting.
*/
/** @param chars minimum chars to start suggesting. */
public GroupSuggestOracle(int chars) {
this.chars = chars;
}
@@ -52,22 +49,23 @@ public class GroupSuggestOracle extends SuggestOracle {
if (req.getLimit() > 0) {
rest.addParameter("n", req.getLimit());
}
rest.get(new AsyncCallback<NativeMap<JavaScriptObject>>() {
@Override
public void onSuccess(NativeMap<JavaScriptObject> result) {
List<String> keys = result.sortedKeys();
List<Suggestion> suggestions = new ArrayList<>(keys.size());
for (String g : keys) {
suggestions.add(new HighlightSuggestion(req.getQuery(), g));
}
done.onSuggestionsReady(req, new Response(suggestions));
}
rest.get(
new AsyncCallback<NativeMap<JavaScriptObject>>() {
@Override
public void onSuccess(NativeMap<JavaScriptObject> result) {
List<String> keys = result.sortedKeys();
List<Suggestion> suggestions = new ArrayList<>(keys.size());
for (String g : keys) {
suggestions.add(new HighlightSuggestion(req.getQuery(), g));
}
done.onSuggestionsReady(req, new Response(suggestions));
}
@Override
public void onFailure(Throwable caught) {
responseEmptySuggestion(req, done);
}
});
@Override
public void onFailure(Throwable caught) {
responseEmptySuggestion(req, done);
}
});
}
private static void responseEmptySuggestion(Request req, Callback done) {

View File

@@ -24,19 +24,18 @@ import com.google.gwt.core.ext.typeinfo.JClassType;
import com.google.gwt.core.ext.typeinfo.TypeOracle;
import com.google.gwt.user.rebind.ClassSourceFileComposerFactory;
import com.google.gwt.user.rebind.SourceWriter;
import java.io.PrintWriter;
/**
* Write the top layer in the Gadget bootstrap sandwich and generate a stub
* manifest that will be completed by the linker.
* Write the top layer in the Gadget bootstrap sandwich and generate a stub manifest that will be
* completed by the linker.
*
* Based on gwt-gadgets GadgetGenerator class
* <p>Based on gwt-gadgets GadgetGenerator class
*/
public class PluginGenerator extends Generator {
@Override
public String generate(TreeLogger logger, GeneratorContext context,
String typeName) throws UnableToCompleteException {
public String generate(TreeLogger logger, GeneratorContext context, String typeName)
throws UnableToCompleteException {
// The TypeOracle knows about all types in the type system
TypeOracle typeOracle = context.getTypeOracle();
@@ -54,18 +53,18 @@ public class PluginGenerator extends Generator {
validateType(logger, sourceType);
// Pick a name for the generated class to not conflict.
String generatedSimpleSourceName = sourceType.getSimpleSourceName()
+ "PluginImpl";
String generatedSimpleSourceName = sourceType.getSimpleSourceName() + "PluginImpl";
// Begin writing the generated source.
ClassSourceFileComposerFactory f = new ClassSourceFileComposerFactory(
sourceType.getPackage().getName(), generatedSimpleSourceName);
ClassSourceFileComposerFactory f =
new ClassSourceFileComposerFactory(
sourceType.getPackage().getName(), generatedSimpleSourceName);
f.addImport(GWT.class.getName());
f.setSuperclass(typeName);
// All source gets written through this Writer
PrintWriter out = context.tryCreate(logger,
sourceType.getPackage().getName(), generatedSimpleSourceName);
PrintWriter out =
context.tryCreate(logger, sourceType.getPackage().getName(), generatedSimpleSourceName);
// If an implementation already exists, we don't need to do any work
if (out != null) {
@@ -78,11 +77,9 @@ public class PluginGenerator extends Generator {
return f.getCreatedClassName();
}
protected void validateType(TreeLogger logger, JClassType type)
throws UnableToCompleteException {
protected void validateType(TreeLogger logger, JClassType type) throws UnableToCompleteException {
if (!type.isDefaultInstantiable()) {
logger.log(TreeLogger.ERROR, "Plugin types must be default instantiable",
null);
logger.log(TreeLogger.ERROR, "Plugin types must be default instantiable", null);
throw new UnableToCompleteException();
}
}