Fix some warnings raised by CheckStyle

- Change ordering of 'static', 'final', etc modifiers according to
  the order suggested by JLS.

- Add comments in empty catch blocks for intentionally ignored
  exceptions.

- Add curly braces around if-else blocks.

- Move `catch` to same line as closing brace of preceding `try`
  blocks.

- Wrap long lines.

Note that this change does not fix all instances of the above errors
across the entire code base.

Change-Id: I24bb9649cc5013c249fa5d84e05322a5cdf2ace6
This commit is contained in:
David Pursehouse 2015-01-28 15:50:38 +09:00
parent 8afed4b1e5
commit 6d0ebb8ccb
35 changed files with 88 additions and 68 deletions

View File

@ -42,7 +42,7 @@ class ConfigAnnotationParser {
return cfg;
}
static private void parseAnnotation(Config cfg, GerritConfig c) {
private static void parseAnnotation(Config cfg, GerritConfig c) {
ArrayList<String> l = Lists.newArrayList(splitter.split(c.name()));
if (l.size() == 2) {
cfg.setString(l.get(0), null, l.get(1), c.value());

View File

@ -77,13 +77,13 @@ import java.util.concurrent.atomic.AtomicLong;
public class ChangeEditIT extends AbstractDaemonTest {
private final static String FILE_NAME = "foo";
private final static String FILE_NAME2 = "foo2";
private final static String FILE_NAME3 = "foo3";
private final static byte[] CONTENT_OLD = "bar".getBytes(UTF_8);
private final static byte[] CONTENT_NEW = "baz".getBytes(UTF_8);
private final static String CONTENT_NEW2_STR = "quxÄÜÖßµ";
private final static byte[] CONTENT_NEW2 = CONTENT_NEW2_STR.getBytes(UTF_8);
private static final String FILE_NAME = "foo";
private static final String FILE_NAME2 = "foo2";
private static final String FILE_NAME3 = "foo3";
private static final byte[] CONTENT_OLD = "bar".getBytes(UTF_8);
private static final byte[] CONTENT_NEW = "baz".getBytes(UTF_8);
private static final String CONTENT_NEW2_STR = "quxÄÜÖßµ";
private static final byte[] CONTENT_NEW2 = CONTENT_NEW2_STR.getBytes(UTF_8);
@Inject
private SchemaFactory<ReviewDb> reviewDbProvider;

View File

@ -46,6 +46,7 @@ public final class IoUtil {
try {
src.close();
} catch (IOException e2) {
// Ignore
}
}
}

View File

@ -145,7 +145,7 @@ public class ParameterizedString {
}
}
private static abstract class Format {
private abstract static class Format {
abstract void format(StringBuilder b, Map<String, String> p);
}
@ -200,7 +200,7 @@ public class ParameterizedString {
}
}
private static abstract class Function {
private abstract static class Function {
abstract String apply(String a);
}

View File

@ -182,10 +182,14 @@ public class PermissionRule implements Comparable<PermissionRule> {
}
if (canUseRange && (getMin() != 0 || getMax() != 0)) {
if (0 <= getMin()) r.append('+');
if (0 <= getMin()) {
r.append('+');
}
r.append(getMin());
r.append("..");
if (0 <= getMax()) r.append('+');
if (0 <= getMax()) {
r.append('+');
}
r.append(getMax());
r.append(' ');
}

View File

@ -28,18 +28,18 @@ public interface WebLink {
/**
* Opens the link in a new window or tab
*/
public final static String BLANK = "_blank";
public static final String BLANK = "_blank";
/**
* Opens the link in the frame it was clicked.
*/
public final static String SELF = "_self";
public static final String SELF = "_self";
/**
* Opens link in parent frame.
*/
public final static String PARENT = "_parent";
public static final String PARENT = "_parent";
/**
* Opens link in the full body of the window.
*/
public final static String TOP = "_top";
public static final String TOP = "_top";
}
}

View File

@ -402,7 +402,7 @@ public class SafeHtmlBuilder extends SafeHtml {
return isElementName(name);
}
private static abstract class Impl {
private abstract static class Impl {
abstract void escapeStr(SafeHtmlBuilder b, String in);
}

View File

@ -895,7 +895,7 @@ public class Dispatcher {
return token.substring(prefixlen);
}
private static abstract class AsyncSplit implements RunAsyncCallback {
private abstract static class AsyncSplit implements RunAsyncCallback {
private final boolean isReloadUi;
protected final String token;

View File

@ -56,7 +56,7 @@ public class AccountInfo extends JavaScriptObject {
}
public static class AvatarInfo extends JavaScriptObject {
public final static int DEFAULT_SIZE = 26;
public static final int DEFAULT_SIZE = 26;
public final native String url() /*-{ return this.url }-*/;
public final native int height() /*-{ return this.height || 0 }-*/;
public final native int width() /*-{ return this.width || 0 }-*/;

View File

@ -294,8 +294,8 @@ public final class GerritLauncher {
return name;
}
private volatile static File myArchive;
private volatile static File myHome;
private static volatile File myArchive;
private static volatile File myHome;
/**
* Locate the JAR/WAR file we were launched from.

View File

@ -96,7 +96,7 @@ public final class Plugin extends JavaScriptObject {
native void _initialized() /*-{ this._success = true }-*/;
native void _loaded() /*-{ this._loadedGwt() }-*/;
private static native final Plugin install(String u)
private static final native Plugin install(String u)
/*-{ return $wnd.Gerrit.installGwt(u) }-*/;
private static final native JavaScriptObject wrap(Screen.EntryPoint b) /*-{

View File

@ -109,7 +109,7 @@ public class RestApi {
get(NativeString.unwrap(cb));
}
private native static void get(String p, JavaScriptObject r)
private static native void get(String p, JavaScriptObject r)
/*-{ $wnd.Gerrit.get(p, r) }-*/;
public <T extends JavaScriptObject>
@ -117,7 +117,7 @@ public class RestApi {
put(path(), wrap(cb));
}
private native static void put(String p, JavaScriptObject r)
private static native void put(String p, JavaScriptObject r)
/*-{ $wnd.Gerrit.put(p, r) }-*/;
public <T extends JavaScriptObject>
@ -125,7 +125,7 @@ public class RestApi {
put(path(), content, wrap(cb));
}
private native static
private static native
void put(String p, String c, JavaScriptObject r)
/*-{ $wnd.Gerrit.put(p, c, r) }-*/;
@ -134,7 +134,7 @@ public class RestApi {
put(path(), content, wrap(cb));
}
private native static
private static native
void put(String p, JavaScriptObject c, JavaScriptObject r)
/*-{ $wnd.Gerrit.put(p, c, r) }-*/;
@ -143,7 +143,7 @@ public class RestApi {
post(path(), content, wrap(cb));
}
private native static
private static native
void post(String p, String c, JavaScriptObject r)
/*-{ $wnd.Gerrit.post(p, c, r) }-*/;
@ -152,7 +152,7 @@ public class RestApi {
post(path(), content, wrap(cb));
}
private native static
private static native
void post(String p, JavaScriptObject c, JavaScriptObject r)
/*-{ $wnd.Gerrit.post(p, c, r) }-*/;
@ -160,10 +160,10 @@ public class RestApi {
delete(path(), wrap(cb));
}
private native static void delete(String p, JavaScriptObject r)
private static native void delete(String p, JavaScriptObject r)
/*-{ $wnd.Gerrit.del(p, r) }-*/;
private native static <T extends JavaScriptObject>
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

@ -28,7 +28,7 @@ import java.util.List;
import java.util.Set;
public abstract class PrettyFormatter implements SparseHtmlFile {
public static abstract class EditFilter {
public abstract static class EditFilter {
abstract String getStyleName();
abstract int getBegin(Edit edit);

View File

@ -924,8 +924,7 @@ public class ChangeHookRunner implements ChangeHooks, LifecycleListener {
while ((line = br.readLine()) != null) {
log.info("hook[" + getName() + "] output: " + line);
}
}
catch(IOException iox) {
} catch (IOException iox) {
log.error("Error writing hook output", iox);
}
}

View File

@ -31,7 +31,7 @@ import java.text.SimpleDateFormat;
import java.util.TimeZone;
public class TimestampHandler extends OptionHandler<Timestamp> {
public final static String TIMESTAMP_FORMAT = "yyyyMMdd_HHmm";
public static final String TIMESTAMP_FORMAT = "yyyyMMdd_HHmm";
@Inject
public TimestampHandler(@Assisted CmdLineParser parser,

View File

@ -72,7 +72,7 @@ public class ConsistencyChecker {
LoggerFactory.getLogger(ConsistencyChecker.class);
@AutoValue
public static abstract class Result {
public abstract static class Result {
private static Result create(Change.Id id, List<ProblemInfo> problems) {
return new AutoValue_ConsistencyChecker_Result(id, null, problems);
}

View File

@ -70,7 +70,7 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
public class GetDiff implements RestReadView<FileResource> {
private final static ImmutableMap<Patch.ChangeType, ChangeType> CHANGE_TYPE =
private static final ImmutableMap<Patch.ChangeType, ChangeType> CHANGE_TYPE =
Maps.immutableEnumMap(
new ImmutableMap.Builder<Patch.ChangeType, ChangeType>()
.put(Patch.ChangeType.ADDED, ChangeType.ADDED)
@ -339,11 +339,13 @@ public class GetDiff implements RestReadView<FileResource> {
int lastB = 0;
for (Edit edit : internalEdit) {
if (edit.getBeginA() != edit.getEndA()) {
e.editA.add(ImmutableList.of(edit.getBeginA() - lastA, edit.getEndA() - edit.getBeginA()));
e.editA.add(ImmutableList.of(
edit.getBeginA() - lastA, edit.getEndA() - edit.getBeginA()));
lastA = edit.getEndA();
}
if (edit.getBeginB() != edit.getEndB()) {
e.editB.add(ImmutableList.of(edit.getBeginB() - lastB, edit.getEndB() - edit.getBeginB()));
e.editB.add(ImmutableList.of(
edit.getBeginB() - lastB, edit.getEndB() - edit.getBeginB()));
lastB = edit.getEndB();
}
}

View File

@ -34,8 +34,10 @@ import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
/**
* The suggest oracle may be called many times in rapid succession during the course of one operation.
* It would be easy to have a simple Cache<Boolean, List<Account>> with a short expiration time of 30s.
* The suggest oracle may be called many times in rapid succession during the
* course of one operation.
* It would be easy to have a simple Cache<Boolean, List<Account>> with a short
* expiration time of 30s.
* Cache only has a single key we're just using Cache for the expiration behavior.
*/
@Singleton

View File

@ -537,17 +537,23 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>,
continue;
case REJECT:
if (msg.length() > 0) msg.append("; ");
if (msg.length() > 0) {
msg.append("; ");
}
msg.append("blocked by ").append(lbl.label);
continue;
case NEED:
if (msg.length() > 0) msg.append("; ");
if (msg.length() > 0) {
msg.append("; ");
}
msg.append("needs ").append(lbl.label);
continue;
case IMPOSSIBLE:
if (msg.length() > 0) msg.append("; ");
if (msg.length() > 0) {
msg.append("; ");
}
msg.append("needs ").append(lbl.label)
.append(" (check project access)");
continue;

View File

@ -100,12 +100,13 @@ public final class SitePaths {
if (site_path.exists()) {
final String[] contents = site_path.list();
if (contents != null)
if (contents != null) {
isNew = contents.length == 0;
else if (site_path.isDirectory())
} else if (site_path.isDirectory()) {
throw new FileNotFoundException("Cannot access " + site_path);
else
} else {
throw new FileNotFoundException("Not a directory: " + site_path);
}
} else {
isNew = true;
}

View File

@ -32,7 +32,7 @@ import org.eclipse.jgit.lib.Config;
*/
public abstract class FieldDef<I, T> {
/** Definition of a single (non-repeatable) field. */
public static abstract class Single<I, T> extends FieldDef<I, T> {
public abstract static class Single<I, T> extends FieldDef<I, T> {
Single(String name, FieldType<T> type, boolean stored) {
super(name, type, stored);
}
@ -44,7 +44,7 @@ public abstract class FieldDef<I, T> {
}
/** Definition of a repeatable field. */
public static abstract class Repeatable<I, T>
public abstract static class Repeatable<I, T>
extends FieldDef<I, Iterable<T>> {
Repeatable(String name, FieldType<T> type, boolean stored) {
super(name, type, stored);

View File

@ -182,12 +182,12 @@ public abstract class AbstractChangeUpdate extends VersionedMetaData {
}
/** Writes commit to a BatchMetaDataUpdate without committing the batch. */
abstract public void writeCommit(BatchMetaDataUpdate batch)
public abstract void writeCommit(BatchMetaDataUpdate batch)
throws OrmException, IOException;
/**
* @return the NameKey for the project where the update will be stored,
* which is not necessarily the same as the change's project.
*/
abstract protected Project.NameKey getProjectName();
protected abstract Project.NameKey getProjectName();
}

View File

@ -220,7 +220,7 @@ public class ChangeRebuilder {
&& event.psId.equals(update.getPatchSetId());
}
private static abstract class Event implements Comparable<Event> {
private abstract static class Event implements Comparable<Event> {
final PatchSet.Id psId;
final Account.Id who;
final Timestamp when;

View File

@ -178,10 +178,11 @@ class IntraLineLoader extends CacheLoader<IntraLineDiffKey, IntraLineDiff> {
int nb = lf + 1;
int p = 0;
while (p < ae - ab) {
if (cmp.equals(a, ab + p, a, ab + p))
if (cmp.equals(a, ab + p, a, ab + p)) {
p++;
else
} else {
break;
}
}
if (p == ae - ab) {
ab = nb;
@ -214,10 +215,11 @@ class IntraLineLoader extends CacheLoader<IntraLineDiffKey, IntraLineDiff> {
int nb = lf + 1;
int p = 0;
while (p < be - bb) {
if (cmp.equals(b, bb + p, b, bb + p))
if (cmp.equals(b, bb + p, b, bb + p)) {
p++;
else
} else {
break;
}
}
if (p == be - bb) {
bb = nb;

View File

@ -150,12 +150,13 @@ public class PatchList implements Serializable {
while (low < high) {
final int mid = (low + high) >>> 1;
final int cmp = patches[mid].getNewName().compareTo(fileName);
if (cmp < 0)
if (cmp < 0) {
low = mid + 1;
else if (cmp == 0)
} else if (cmp == 0) {
return mid;
else
} else {
high = mid;
}
}
return -(low + 1);
}

View File

@ -264,7 +264,7 @@ public class JarScanner implements PluginContentScanner {
}
}
private static abstract class AbstractAnnotationVisitor extends
private abstract static class AbstractAnnotationVisitor extends
AnnotationVisitor {
AbstractAnnotationVisitor() {
super(Opcodes.ASM4);

View File

@ -214,7 +214,7 @@ public class PluginLoader implements LifecycleListener {
}
}
synchronized private void unloadPlugin(Plugin plugin) {
private synchronized void unloadPlugin(Plugin plugin) {
persistentCacheFactory.onStop(plugin);
String name = plugin.getName();
log.info(String.format("Unloading plugin %s", name));

View File

@ -47,7 +47,7 @@ public class CommentLinkInfo {
public final String html;
public final Boolean enabled; // null means true
public transient final String name;
public final transient String name;
public CommentLinkInfo(String name, String match, String link, String html,
Boolean enabled) {

View File

@ -119,7 +119,7 @@ public class SectionSortCache {
}
@AutoValue
static abstract class EntryKey {
abstract static class EntryKey {
public abstract String ref();
public abstract List<String> patterns();
public abstract int cachedHashCode();

View File

@ -92,8 +92,9 @@ public class AndPredicate<T> extends Predicate<T> {
@Override
public boolean equals(final Object other) {
if (other == null)
if (other == null) {
return false;
}
return getClass() == other.getClass()
&& getChildren().equals(((Predicate<?>) other).getChildren());
}

View File

@ -23,7 +23,7 @@ import com.google.inject.name.Named;
@Singleton
public class ConflictsCacheImpl implements ConflictsCache {
public final static String NAME = "conflicts";
public static final String NAME = "conflicts";
public static Module module() {
return new CacheModule() {

View File

@ -137,8 +137,9 @@ public class BasicSerializationTest {
private static void assertOutput(final byte[] expect,
final ByteArrayOutputStream out) {
final byte[] buf = out.toByteArray();
for (int i = 0; i < expect.length; i++)
for (int i = 0; i < expect.length; i++) {
assertEquals(expect[i], buf[i]);
}
}
private static InputStream r(final byte[] buf) {

View File

@ -22,7 +22,7 @@ import java.util.List;
public class TempFileUtil {
private static List<File> allDirsCreated = new ArrayList<>();
public synchronized static File createTempDirectory() throws IOException {
public static synchronized File createTempDirectory() throws IOException {
File tmp = File.createTempFile("gerrit_test_", "").getCanonicalFile();
if (!tmp.delete() || !tmp.mkdir()) {
throw new IOException("Cannot create " + tmp.getPath());

View File

@ -253,7 +253,7 @@ class CommandFactoryProvider implements Provider<CommandFactory>,
}
/** Split a command line into a string array. */
static public String[] split(String commandLine) {
public static String[] split(String commandLine) {
final List<String> list = new ArrayList<>();
boolean inquote = false;
boolean inDblQuote = false;

View File

@ -709,7 +709,7 @@ public class QueryShell {
print(help.toString());
}
private static abstract class Function {
private abstract static class Function {
final String name;
Function(final String name) {