[git] minor: add NotNulls
authorJulia Beliaeva <Julia.Beliaeva@jetbrains.com>
Sat, 8 Oct 2016 19:15:09 +0000 (22:15 +0300)
committerJulia Beliaeva <Julia.Beliaeva@jetbrains.com>
Tue, 11 Oct 2016 16:32:30 +0000 (19:32 +0300)
plugins/git4idea/src/git4idea/history/GitHistoryUtils.java

index 4fc4042e214d5b59edba97c3c4c869edd2b06d3b..410148fc7602a2e162eb8749366f6fc0e87350b5 100644 (file)
@@ -112,7 +112,7 @@ public class GitHistoryUtils {
   }
 
   @Nullable
-  public static VcsRevisionDescription getCurrentRevisionDescription(final Project project, FilePath filePath)
+  public static VcsRevisionDescription getCurrentRevisionDescription(@NotNull Project project, @NotNull FilePath filePath)
     throws VcsException {
     filePath = getLastCommitName(project, filePath);
     GitSimpleHandler h = new GitSimpleHandler(project, GitUtil.getGitRoot(filePath), GitCommand.LOG);
@@ -147,7 +147,7 @@ public class GitHistoryUtils {
    * @throws VcsException if there is problem with running git
    */
   @Nullable
-  public static ItemLatestState getLastRevision(final Project project, FilePath filePath) throws VcsException {
+  public static ItemLatestState getLastRevision(@NotNull Project project, @NotNull FilePath filePath) throws VcsException {
     VirtualFile root = GitUtil.getGitRoot(filePath);
     GitBranch c = GitBranchUtil.getCurrentBranch(project, root);
     GitBranch t = c == null ? null : GitBranchUtil.tracked(project, root, c.getName());
@@ -220,12 +220,12 @@ public class GitHistoryUtils {
     history(project, path, root, GitRevisionNumber.HEAD, consumer, exceptionConsumer, parameters);
   }
 
-  public static void history(@NotNull final Project project,
+  public static void history(@NotNull Project project,
                              @NotNull FilePath path,
                              @Nullable VirtualFile root,
                              @NotNull VcsRevisionNumber startingRevision,
-                             @NotNull final Consumer<GitFileRevision> consumer,
-                             @NotNull final Consumer<VcsException> exceptionConsumer,
+                             @NotNull Consumer<GitFileRevision> consumer,
+                             @NotNull Consumer<VcsException> exceptionConsumer,
                              String... parameters) {
     // adjust path using change manager
     final FilePath filePath = getLastCommitName(project, path);
@@ -369,12 +369,13 @@ public class GitHistoryUtils {
     }
   }
 
-  private static GitLineHandler getLogHandler(Project project,
+  @NotNull
+  private static GitLineHandler getLogHandler(@NotNull Project project,
                                               @NotNull GitVersion version,
-                                              VirtualFile root,
-                                              GitLogParser parser,
-                                              FilePath path,
-                                              String lastCommit,
+                                              @NotNull VirtualFile root,
+                                              @NotNull GitLogParser parser,
+                                              @NotNull FilePath path,
+                                              @NotNull String lastCommit,
                                               String... parameters) {
     final GitLineHandler h = new GitLineHandler(project, root, GitCommand.LOG);
     h.setStdoutSuppressed(true);
@@ -396,10 +397,10 @@ public class GitHistoryUtils {
    * If it's not a rename, returns null.
    */
   @Nullable
-  private static Pair<String, FilePath> getFirstCommitParentAndPathIfRename(Project project,
-                                                                            VirtualFile root,
-                                                                            String commit,
-                                                                            FilePath filePath,
+  private static Pair<String, FilePath> getFirstCommitParentAndPathIfRename(@NotNull Project project,
+                                                                            @NotNull VirtualFile root,
+                                                                            @NotNull String commit,
+                                                                            @NotNull FilePath filePath,
                                                                             @NotNull GitVersion version) throws VcsException {
     // 'git show -M --name-status <commit hash>' returns the information about commit and detects renames.
     // NB: we can't specify the filepath, because then rename detection will work only with the '--follow' option, which we don't wanna use.
@@ -432,7 +433,10 @@ public class GitHistoryUtils {
     return null;
   }
 
-  public static List<? extends VcsShortCommitDetails> readMiniDetails(final Project project, final VirtualFile root, List<String> hashes)
+  @NotNull
+  public static List<? extends VcsShortCommitDetails> readMiniDetails(@NotNull Project project,
+                                                                      @NotNull VirtualFile root,
+                                                                      @NotNull List<String> hashes)
     throws VcsException {
     final VcsLogObjectsFactory factory = getObjectsFactoryWithDisposeCheck(project);
     if (factory == null) {
@@ -469,7 +473,7 @@ public class GitHistoryUtils {
 
   @Nullable
   public static List<VcsCommitMetadata> readLastCommits(@NotNull Project project,
-                                                        @NotNull final VirtualFile root,
+                                                        @NotNull VirtualFile root,
                                                         @NotNull String... refs)
     throws VcsException {
     final VcsLogObjectsFactory factory = getObjectsFactoryWithDisposeCheck(project);
@@ -600,12 +604,12 @@ public class GitHistoryUtils {
     processHandlerOutputByLine(h, recordConsumer, 0);
   }
 
-  public static void readCommits(@NotNull final Project project,
-                                 @NotNull final VirtualFile root,
+  public static void readCommits(@NotNull Project project,
+                                 @NotNull VirtualFile root,
                                  @NotNull List<String> parameters,
-                                 @NotNull final Consumer<VcsUser> userConsumer,
-                                 @NotNull final Consumer<VcsRef> refConsumer,
-                                 @NotNull final Consumer<TimedVcsCommit> commitConsumer) throws VcsException {
+                                 @NotNull Consumer<VcsUser> userConsumer,
+                                 @NotNull Consumer<VcsRef> refConsumer,
+                                 @NotNull Consumer<TimedVcsCommit> commitConsumer) throws VcsException {
     final VcsLogObjectsFactory factory = getObjectsFactoryWithDisposeCheck(project);
     if (factory == null) {
       return;
@@ -632,10 +636,10 @@ public class GitHistoryUtils {
   @NotNull
   private static List<TimedVcsCommit> parseCommit(@NotNull GitLogParser parser,
                                                   @NotNull StringBuilder record,
-                                                  @NotNull final Consumer<VcsUser> userRegistry,
-                                                  @NotNull final Consumer<VcsRef> refConsumer,
-                                                  @NotNull final VcsLogObjectsFactory factory,
-                                                  @NotNull final VirtualFile root) {
+                                                  @NotNull Consumer<VcsUser> userRegistry,
+                                                  @NotNull Consumer<VcsRef> refConsumer,
+                                                  @NotNull VcsLogObjectsFactory factory,
+                                                  @NotNull VirtualFile root) {
     List<GitLogRecord> rec = parser.parse(record.toString());
     return ContainerUtil.mapNotNull(rec, new Function<GitLogRecord, TimedVcsCommit>() {
       @Override
@@ -666,9 +670,9 @@ public class GitHistoryUtils {
 
   @NotNull
   private static Collection<VcsRef> parseRefs(@NotNull Collection<String> refs,
-                                              @NotNull final Hash hash,
-                                              @NotNull final VcsLogObjectsFactory factory,
-                                              @NotNull final VirtualFile root) {
+                                              @NotNull Hash hash,
+                                              @NotNull VcsLogObjectsFactory factory,
+                                              @NotNull VirtualFile root) {
     return ContainerUtil.mapNotNull(refs, new Function<String, VcsRef>() {
       @Override
       public VcsRef fun(String refName) {
@@ -680,7 +684,7 @@ public class GitHistoryUtils {
   }
 
   @Nullable
-  private static VcsLogObjectsFactory getObjectsFactoryWithDisposeCheck(@NotNull final Project project) {
+  private static VcsLogObjectsFactory getObjectsFactoryWithDisposeCheck(@NotNull Project project) {
     return ApplicationManager.getApplication().runReadAction(new Computable<VcsLogObjectsFactory>() {
       @Override
       public VcsLogObjectsFactory compute() {
@@ -693,12 +697,12 @@ public class GitHistoryUtils {
   }
 
   private static class MyTokenAccumulator {
-    private final StringBuilder myBuffer = new StringBuilder();
+    @NotNull private final StringBuilder myBuffer = new StringBuilder();
+    @NotNull private final GitLogParser myParser;
 
     private boolean myNotStarted = true;
-    private GitLogParser myParser;
 
-    public MyTokenAccumulator(GitLogParser parser) {
+    public MyTokenAccumulator(@NotNull GitLogParser parser) {
       myParser = parser;
     }
 
@@ -732,11 +736,13 @@ public class GitHistoryUtils {
       }
     }
 
+    @Nullable
     public GitLogRecord processLast() {
       return processResult(myBuffer.toString());
     }
 
-    private GitLogRecord processResult(final String line) {
+    @Nullable
+    private GitLogRecord processResult(@NotNull String line) {
       return myParser.parseOneRecord(line);
     }
   }
@@ -749,11 +755,13 @@ public class GitHistoryUtils {
    * @return the list of the revisions
    * @throws VcsException if there is problem with running git
    */
-  public static List<VcsFileRevision> history(final Project project, final FilePath path, String... parameters) throws VcsException {
+  @NotNull
+  public static List<VcsFileRevision> history(@NotNull Project project, @NotNull FilePath path, String... parameters) throws VcsException {
     final VirtualFile root = GitUtil.getGitRoot(path);
     return history(project, path, root, parameters);
   }
 
+  @NotNull
   public static List<VcsFileRevision> history(@NotNull Project project,
                                               @NotNull FilePath path,
                                               @Nullable VirtualFile root,
@@ -761,6 +769,7 @@ public class GitHistoryUtils {
     return history(project, path, root, GitRevisionNumber.HEAD, parameters);
   }
 
+  @NotNull
   public static List<VcsFileRevision> history(@NotNull Project project,
                                               @NotNull FilePath path,
                                               @Nullable VirtualFile root,
@@ -791,7 +800,8 @@ public class GitHistoryUtils {
    */
   @Deprecated
   @SuppressWarnings("unused")
-  public static List<Pair<SHAHash, Date>> onlyHashesHistory(Project project, FilePath path, final String... parameters)
+  @NotNull
+  public static List<Pair<SHAHash, Date>> onlyHashesHistory(@NotNull Project project, @NotNull FilePath path, String... parameters)
     throws VcsException {
     final VirtualFile root = GitUtil.getGitRoot(path);
     return onlyHashesHistory(project, path, root, parameters);
@@ -801,10 +811,11 @@ public class GitHistoryUtils {
    * @deprecated To remove in IDEA 17
    */
   @Deprecated
-  public static List<Pair<SHAHash, Date>> onlyHashesHistory(Project project,
-                                                            FilePath path,
-                                                            final VirtualFile root,
-                                                            final String... parameters)
+  @NotNull
+  public static List<Pair<SHAHash, Date>> onlyHashesHistory(@NotNull Project project,
+                                                            @NotNull FilePath path,
+                                                            @NotNull VirtualFile root,
+                                                            String... parameters)
     throws VcsException {
     // adjust path using change manager
     path = getLastCommitName(project, path);
@@ -862,7 +873,7 @@ public class GitHistoryUtils {
    * and it can occupy too much memory. The estimate is ~600Kb for 1000 commits.</p>
    */
   @NotNull
-  public static List<GitCommit> history(@NotNull final Project project, @NotNull final VirtualFile root, String... parameters)
+  public static List<GitCommit> history(@NotNull Project project, @NotNull VirtualFile root, String... parameters)
     throws VcsException {
     final VcsLogObjectsFactory factory = getObjectsFactoryWithDisposeCheck(project);
     if (factory == null) {
@@ -877,6 +888,7 @@ public class GitHistoryUtils {
     }, parameters);
   }
 
+  @NotNull
   private static GitLogParser createParserForDetails(@NotNull GitTextHandler h,
                                                      @NotNull Project project,
                                                      boolean withRefs,
@@ -930,6 +942,7 @@ public class GitHistoryUtils {
     return commits;
   }
 
+  @NotNull
   private static GitCommit createCommit(@NotNull Project project, @NotNull VirtualFile root, @NotNull GitLogRecord record,
                                         @NotNull VcsLogObjectsFactory factory) {
     List<Hash> parents = getParentHashes(factory, record);
@@ -940,7 +953,7 @@ public class GitHistoryUtils {
   }
 
   @NotNull
-  private static List<Hash> getParentHashes(@NotNull final VcsLogObjectsFactory factory, @NotNull GitLogRecord record) {
+  private static List<Hash> getParentHashes(@NotNull VcsLogObjectsFactory factory, @NotNull GitLogRecord record) {
     return ContainerUtil.map(record.getParentsHashes(), new Function<String, Hash>() {
       @Override
       public Hash fun(String hash) {
@@ -971,8 +984,8 @@ public class GitHistoryUtils {
   }
 
   @Nullable
-  private static String parseRefs(@Nullable SymbolicRefsI refs, Collection<String> currentRefs, List<String> locals,
-                                  List<String> remotes, List<String> tags) {
+  private static String parseRefs(@Nullable SymbolicRefsI refs, @NotNull Collection<String> currentRefs, @NotNull List<String> locals,
+                                  @NotNull List<String> remotes, @NotNull List<String> tags) {
     if (refs == null) {
       return null;
     }
@@ -997,7 +1010,7 @@ public class GitHistoryUtils {
   @Deprecated
   @NotNull
   public static List<GitHeavyCommit> commitsDetails(@NotNull Project project, @NotNull FilePath path, @Nullable SymbolicRefsI refs,
-                                                    @NotNull final Collection<String> commitsIds) throws VcsException {
+                                                    @NotNull Collection<String> commitsIds) throws VcsException {
     path = getLastCommitName(project, path);     // adjust path using change manager
     VirtualFile root = GitUtil.getGitRoot(path);
     GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.SHOW);
@@ -1017,7 +1030,7 @@ public class GitHistoryUtils {
     return rc;
   }
 
-  public static long getAuthorTime(Project project, FilePath path, final String commitsId) throws VcsException {
+  public static long getAuthorTime(@NotNull Project project, @NotNull FilePath path, @NotNull String commitsId) throws VcsException {
     // adjust path using change manager
     path = getLastCommitName(project, path);
     final VirtualFile root = GitUtil.getGitRoot(path);
@@ -1052,8 +1065,8 @@ public class GitHistoryUtils {
   }
 
   @Nullable
-  public static GitRevisionNumber getMergeBase(final Project project, final VirtualFile root, @NotNull final String first,
-                                               @NotNull final String second)
+  public static GitRevisionNumber getMergeBase(@NotNull Project project, @NotNull VirtualFile root, @NotNull String first,
+                                               @NotNull String second)
     throws VcsException {
     GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.MERGE_BASE);
     h.setSilent(true);