Turn on many more Eclipse warnings, and fix them

- Warn on empty statements, e.g. "for (;;);". These may be
   typos and are easily replaced by "for (;;) {}" which is more
   explicit.
 - Warn on field hiding. This allows cleanup of many acceptance test
   members, at the cost of a couple of renames and the occasional
   suppression (when the field is in a public nested enum that shadows
   a public constant).
 - Warn on unnecessary casts.
 - Warn on unused declared thrown exceptions. In addition to reducing
   method signature length and number of imports, this also eliminated
   some impossible catch blocks.
 - Warn on missing @Override annotations.
 - Warn on unused parameters. This is likely the most controversial,
   as a few relatively common patterns require unused parameters in a
   way that Eclipse can't ignore. However, it also resulted in cleanup
   of a lot of unnecessary injections and method parameters, so I
   think the cost was worth it.

Change-Id: I7224be8b1c798613a127c88507e8cce400679e5d
This commit is contained in:
Dave Borowitz
2014-10-28 12:09:55 -07:00
parent 2e82f2f8a2
commit 8b42ec5bd5
305 changed files with 932 additions and 699 deletions

View File

@@ -69,7 +69,7 @@ public class ServerPlugin extends Plugin {
private Injector sysInjector;
private Injector sshInjector;
private Injector httpInjector;
private LifecycleManager manager;
private LifecycleManager serverManager;
private List<ReloadableRegistrationHandle<?>> reloadableHandles;
public ServerPlugin(String name,
@@ -140,12 +140,14 @@ public class ServerPlugin extends Plugin {
}
}
@Override
@Nullable
public String getVersion() {
Attributes main = manifest.getMainAttributes();
return main.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
}
@Override
boolean canReload() {
Attributes main = manifest.getMainAttributes();
String v = main.getValue("Gerrit-ReloadMode");
@@ -161,6 +163,7 @@ public class ServerPlugin extends Plugin {
}
}
@Override
void start(PluginGuiceEnvironment env) throws Exception {
RequestContext oldContext = env.enter(this);
try {
@@ -172,7 +175,7 @@ public class ServerPlugin extends Plugin {
private void startPlugin(PluginGuiceEnvironment env) throws Exception {
Injector root = newRootInjector(env);
manager = new LifecycleManager();
serverManager = new LifecycleManager();
AutoRegisterModules auto = null;
if (sysModule == null && sshModule == null && httpModule == null) {
@@ -182,10 +185,10 @@ public class ServerPlugin extends Plugin {
if (sysModule != null) {
sysInjector = root.createChildInjector(root.getInstance(sysModule));
manager.add(sysInjector);
serverManager.add(sysInjector);
} else if (auto != null && auto.sysModule != null) {
sysInjector = root.createChildInjector(auto.sysModule);
manager.add(sysInjector);
serverManager.add(sysInjector);
} else {
sysInjector = root;
}
@@ -198,11 +201,11 @@ public class ServerPlugin extends Plugin {
if (sshModule != null) {
modules.add(sysInjector.getInstance(sshModule));
sshInjector = sysInjector.createChildInjector(modules);
manager.add(sshInjector);
serverManager.add(sshInjector);
} else if (auto != null && auto.sshModule != null) {
modules.add(auto.sshModule);
sshInjector = sysInjector.createChildInjector(modules);
manager.add(sshInjector);
serverManager.add(sshInjector);
}
}
@@ -214,15 +217,15 @@ public class ServerPlugin extends Plugin {
if (httpModule != null) {
modules.add(sysInjector.getInstance(httpModule));
httpInjector = sysInjector.createChildInjector(modules);
manager.add(httpInjector);
serverManager.add(httpInjector);
} else if (auto != null && auto.httpModule != null) {
modules.add(auto.httpModule);
httpInjector = sysInjector.createChildInjector(modules);
manager.add(httpInjector);
serverManager.add(httpInjector);
}
}
manager.start();
serverManager.start();
}
private Injector newRootInjector(final PluginGuiceEnvironment env) {
@@ -266,44 +269,49 @@ public class ServerPlugin extends Plugin {
return Guice.createInjector(modules);
}
@Override
void stop(PluginGuiceEnvironment env) {
if (manager != null) {
if (serverManager != null) {
RequestContext oldContext = env.enter(this);
try {
manager.stop();
serverManager.stop();
} finally {
env.exit(oldContext);
}
manager = null;
serverManager = null;
sysInjector = null;
sshInjector = null;
httpInjector = null;
}
}
@Override
public Injector getSysInjector() {
return sysInjector;
}
@Override
@Nullable
public Injector getSshInjector() {
return sshInjector;
}
@Override
@Nullable
public Injector getHttpInjector() {
return httpInjector;
}
@Override
public void add(RegistrationHandle handle) {
if (manager != null) {
if (serverManager != null) {
if (handle instanceof ReloadableRegistrationHandle) {
if (reloadableHandles == null) {
reloadableHandles = Lists.newArrayList();
}
reloadableHandles.add((ReloadableRegistrationHandle<?>) handle);
}
manager.add(handle);
serverManager.add(handle);
}
}