diff options
author | David Pursehouse <david.pursehouse@gmail.com> | 2019-10-17 09:01:25 +0900 |
---|---|---|
committer | David Pursehouse <david.pursehouse@gmail.com> | 2019-10-17 10:20:14 +0900 |
commit | 98cdca9b5a830f1c2ceca52379d662a68109d43e (patch) | |
tree | d843141173394b4ea4e435553885749096d4fb79 /org.eclipse.jgit/src/org/eclipse/jgit/lib | |
parent | 762f6212b4692b28f098ac597058bd6a489b8b49 (diff) | |
download | jgit-98cdca9b5a830f1c2ceca52379d662a68109d43e.tar.gz jgit-98cdca9b5a830f1c2ceca52379d662a68109d43e.zip |
Enable and fix "Statement unnecessarily nested within else clause" warnings
Since [1] the gerrit project includes jgit as a submodule, and has this
warning enabled, resulting in 100s of warnings in the console.
Also enable the warning here, and fix them.
At the same time, add missing braces around adjacent and nearby one-line
blocks.
[1] https://gerrit-review.googlesource.com/c/gerrit/+/227897
Change-Id: I81df3fc7ed6eedf6874ce1a3bedfa727a1897e4c
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/lib')
8 files changed, 45 insertions, 46 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/AnyObjectId.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/AnyObjectId.java index 4f90e69008..24850ee44c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/AnyObjectId.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/AnyObjectId.java @@ -302,10 +302,10 @@ public abstract class AnyObjectId implements Comparable<AnyObjectId> { /** {@inheritDoc} */ @Override public final boolean equals(Object o) { - if (o instanceof AnyObjectId) + if (o instanceof AnyObjectId) { return equals((AnyObjectId) o); - else - return false; + } + return false; } /** diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BaseRepositoryBuilder.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BaseRepositoryBuilder.java index 96e50667b3..98a46f3e54 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BaseRepositoryBuilder.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BaseRepositoryBuilder.java @@ -103,25 +103,29 @@ public class BaseRepositoryBuilder<B extends BaseRepositoryBuilder, R extends Re private static File getSymRef(File workTree, File dotGit, FS fs) throws IOException { byte[] content = IO.readFully(dotGit); - if (!isSymRef(content)) + if (!isSymRef(content)) { throw new IOException(MessageFormat.format( JGitText.get().invalidGitdirRef, dotGit.getAbsolutePath())); + } int pathStart = 8; int lineEnd = RawParseUtils.nextLF(content, pathStart); while (content[lineEnd - 1] == '\n' || - (content[lineEnd - 1] == '\r' && SystemReader.getInstance().isWindows())) + (content[lineEnd - 1] == '\r' + && SystemReader.getInstance().isWindows())) { lineEnd--; - if (lineEnd == pathStart) + } + if (lineEnd == pathStart) { throw new IOException(MessageFormat.format( JGitText.get().invalidGitdirRef, dotGit.getAbsolutePath())); + } String gitdirPath = RawParseUtils.decode(content, pathStart, lineEnd); File gitdirFile = fs.resolve(workTree, gitdirPath); - if (gitdirFile.isAbsolute()) + if (gitdirFile.isAbsolute()) { return gitdirFile; - else - return new File(workTree, gitdirPath).getCanonicalFile(); + } + return new File(workTree, gitdirPath).getCanonicalFile(); } private FS fs; @@ -723,9 +727,8 @@ public class BaseRepositoryBuilder<B extends BaseRepositoryBuilder, R extends Re .getAbsolutePath(), err.getMessage())); } return cfg; - } else { - return new Config(); } + return new Config(); } private File guessWorkTreeOrFail() throws IOException { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchConfig.java index be53c4b4f6..cad747bcff 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchConfig.java @@ -232,9 +232,9 @@ public class BranchConfig { private String getRemoteOrDefault() { String remote = getRemote(); - if (remote == null) + if (remote == null) { return Constants.DEFAULT_REMOTE_NAME; - else - return remote; + } + return remote; } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java index 16db717032..938fa2394e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java @@ -1395,12 +1395,11 @@ public class Config { } trailingSpaces.append(cc); continue; - } else { - inLeadingSpace = false; - if (trailingSpaces != null) { - value.append(trailingSpaces); - trailingSpaces.setLength(0); - } + } + inLeadingSpace = false; + if (trailingSpaces != null) { + value.append(trailingSpaces); + trailingSpaces.setLength(0); } if ('\\' == c) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java index e865da83b1..23e8de0e35 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java @@ -134,11 +134,9 @@ public class DefaultTypedConfigGetter implements TypedConfigGetter { throw new IllegalArgumentException( MessageFormat.format(JGitText.get().enumValueNotSupported3, section, subsection, name, value)); - } else { - throw new IllegalArgumentException( - MessageFormat.format(JGitText.get().enumValueNotSupported2, - section, name, value)); } + throw new IllegalArgumentException(MessageFormat.format( + JGitText.get().enumValueNotSupported2, section, name, value)); } /** {@inheritDoc} */ diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java index 88d0859842..b87a031f58 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java @@ -606,16 +606,17 @@ public class IndexDiff { } // consume the remaining work - if (monitor != null) + if (monitor != null) { monitor.endTask(); + } ignored = indexDiffFilter.getIgnoredPaths(); if (added.isEmpty() && changed.isEmpty() && removed.isEmpty() && missing.isEmpty() && modified.isEmpty() - && untracked.isEmpty()) + && untracked.isEmpty()) { return false; - else - return true; + } + return true; } private boolean hasFiles(File directory) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java index 700b9dbe85..e14fb102b7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java @@ -293,9 +293,8 @@ public abstract class ObjectReader implements AutoCloseable { if (idItr.hasNext()) { cur = idItr.next(); return true; - } else { - return false; } + return false; } @Override @@ -383,9 +382,8 @@ public abstract class ObjectReader implements AutoCloseable { cur = idItr.next(); sz = getObjectSize(cur, OBJ_ANY); return true; - } else { - return false; } + return false; } @Override diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java index 68866ea279..0e9cf58cf2 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java @@ -503,9 +503,8 @@ public abstract class Repository implements AutoCloseable { if (resolved instanceof String) { final Ref ref = findRef((String) resolved); return ref != null ? ref.getLeaf().getObjectId() : null; - } else { - return (ObjectId) resolved; } + return (ObjectId) resolved; } } @@ -527,11 +526,12 @@ public abstract class Repository implements AutoCloseable { try (RevWalk rw = new RevWalk(this)) { rw.setRetainBody(true); Object resolved = resolve(rw, revstr); - if (resolved != null) - if (resolved instanceof String) + if (resolved != null) { + if (resolved instanceof String) { return (String) resolved; - else - return ((AnyObjectId) resolved).getName(); + } + return ((AnyObjectId) resolved).getName(); + } return null; } } @@ -760,15 +760,15 @@ public abstract class Repository implements AutoCloseable { if (name == null) throw new RevisionSyntaxException(revstr); } else if (time.matches("^-\\d+$")) { //$NON-NLS-1$ - if (name != null) + if (name != null) { throw new RevisionSyntaxException(revstr); - else { - String previousCheckout = resolveReflogCheckout(-Integer - .parseInt(time)); - if (ObjectId.isId(previousCheckout)) - rev = parseSimple(rw, previousCheckout); - else - name = previousCheckout; + } + String previousCheckout = resolveReflogCheckout( + -Integer.parseInt(time)); + if (ObjectId.isId(previousCheckout)) { + rev = parseSimple(rw, previousCheckout); + } else { + name = previousCheckout; } } else { if (name == null) |