From 94fbe4c75aae54f38dcb1ba50bf348f9a1e57d85 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Fri, 15 Aug 2014 13:02:53 +0400 Subject: [PATCH] [git] cleanup: remove trivial javadocs, add @Override, @NotNull --- .../annotate/GitAnnotationProvider.java | 46 +----- .../git4idea/annotate/GitFileAnnotation.java | 143 +++++------------- 2 files changed, 40 insertions(+), 149 deletions(-) diff --git a/plugins/git4idea/src/git4idea/annotate/GitAnnotationProvider.java b/plugins/git4idea/src/git4idea/annotate/GitAnnotationProvider.java index 46875b9d8c23..5ebdefd74b3a 100644 --- a/plugins/git4idea/src/git4idea/annotate/GitAnnotationProvider.java +++ b/plugins/git4idea/src/git4idea/annotate/GitAnnotationProvider.java @@ -46,45 +46,20 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -/** - * Git annotation provider implementation. - *

- * Based on the JetBrains SVNAnnotationProvider. - */ public class GitAnnotationProvider implements AnnotationProvider, VcsCacheableAnnotationProvider { - /** - * the context project - */ private final Project myProject; - /** - * The author key for annotations - */ @NonNls private static final String AUTHOR_KEY = "author"; - /** - * The committer time key for annotations - */ @NonNls private static final String COMMITTER_TIME_KEY = "committer-time"; private static final Logger LOG = Logger.getInstance(GitAnnotationProvider.class); - /** - * A constructor - * - * @param project a context project - */ public GitAnnotationProvider(@NotNull Project project) { myProject = project; } - /** - * {@inheritDoc} - */ public FileAnnotation annotate(@NotNull VirtualFile file) throws VcsException { return annotate(file, null); } - /** - * {@inheritDoc} - */ public FileAnnotation annotate(@NotNull final VirtualFile file, final VcsFileRevision revision) throws VcsException { if (file.isDirectory()) { throw new VcsException("Cannot annotate a directory"); @@ -119,8 +94,8 @@ public class GitAnnotationProvider implements AnnotationProvider, VcsCacheableAn } }; if (ApplicationManager.getApplication().isDispatchThread()) { - ProgressManager.getInstance() - .runProcessWithProgressSynchronously(command, GitBundle.getString("annotate.action.name"), false, myProject); + ProgressManager.getInstance().runProcessWithProgressSynchronously(command, GitBundle.getString("annotate.action.name"), false, + myProject); } else { command.run(); @@ -132,16 +107,6 @@ public class GitAnnotationProvider implements AnnotationProvider, VcsCacheableAn return annotation[0]; } - /** - * Calculate annotations - * - * @param repositoryFilePath the file path in the repository - * @param revision the revision to checkout - * @param revisions the revision list from history - * @param file a virtual file for the action - * @return a file annotation object - * @throws VcsException if there is a problem with running git - */ private GitFileAnnotation annotate(final FilePath repositoryFilePath, final VcsFileRevision revision, final List revisions, @@ -159,7 +124,7 @@ public class GitAnnotationProvider implements AnnotationProvider, VcsCacheableAn h.endOptions(); h.addRelativePaths(repositoryFilePath); String output = h.run(); - GitFileAnnotation annotation = new GitFileAnnotation(myProject, file, revision == null, revision == null ? null : revision.getRevisionNumber()); + GitFileAnnotation annotation = new GitFileAnnotation(myProject, file, revision == null ? null : revision.getRevisionNumber()); class CommitInfo { Date date; String author; @@ -229,7 +194,7 @@ public class GitAnnotationProvider implements AnnotationProvider, VcsCacheableAn String annotatedContent, boolean forCurrentRevision, VcsRevisionNumber revisionNumber) { final GitFileAnnotation gitFileAnnotation = - new GitFileAnnotation(myProject, vcsAnnotation.getFilePath().getVirtualFile(), forCurrentRevision, revisionNumber); + new GitFileAnnotation(myProject, vcsAnnotation.getFilePath().getVirtualFile(), revisionNumber); gitFileAnnotation.addLogEntries(session.getRevisionList()); final VcsLineAnnotationData basicAnnotation = vcsAnnotation.getBasicAnnotation(); final int size = basicAnnotation.getNumLines(); @@ -252,9 +217,6 @@ public class GitAnnotationProvider implements AnnotationProvider, VcsCacheableAn return gitFileAnnotation; } - /** - * {@inheritDoc} - */ public boolean isAnnotationValid(VcsFileRevision rev) { return true; } diff --git a/plugins/git4idea/src/git4idea/annotate/GitFileAnnotation.java b/plugins/git4idea/src/git4idea/annotate/GitFileAnnotation.java index 4dfe4da19de0..0c1df6a50a5b 100644 --- a/plugins/git4idea/src/git4idea/annotate/GitFileAnnotation.java +++ b/plugins/git4idea/src/git4idea/annotate/GitFileAnnotation.java @@ -15,7 +15,6 @@ */ package git4idea.annotate; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vcs.VcsKey; @@ -23,6 +22,7 @@ import com.intellij.openapi.vcs.annotate.*; import com.intellij.openapi.vcs.history.VcsFileRevision; import com.intellij.openapi.vcs.history.VcsRevisionNumber; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.ObjectUtils; import com.intellij.util.text.DateFormatUtil; import git4idea.GitRevisionNumber; import git4idea.GitVcs; @@ -32,45 +32,24 @@ import org.jetbrains.annotations.Nullable; import java.util.*; -/** - * Git file annotation implementation - *

- * Based on the JetBrains SVNAnnotationProvider. - */ public class GitFileAnnotation extends FileAnnotation { - private final static Logger LOG = Logger.getInstance("#git4idea.annotate.GitFileAnnotation"); - - /** - * annotated content - */ - private final StringBuffer myContentBuffer = new StringBuffer(); - /** - * The currently annotated lines - */ - private final ArrayList myLines = new ArrayList(); - /** - * The project reference - */ + private final StringBuffer myContentBuffer = new StringBuffer(); // annotated content + private final ArrayList myLines = new ArrayList(); // The currently annotated lines private final Project myProject; private final VcsRevisionNumber myBaseRevision; - /** - * Map from revision numbers to revisions - */ - private final Map myRevisionMap = new HashMap(); + @NotNull private final Map myRevisionMap = new HashMap(); + @NotNull private final VirtualFile myFile; + @NotNull private final GitVcs myVcs; - /** - * the virtual file for which annotations are generated - */ - private final VirtualFile myFile; - - private final LineAnnotationAspect DATE_ASPECT = new GitAnnotationAspect(GitAnnotationAspect.DATE, true) { + private final LineAnnotationAspect DATE_ASPECT = new GitAnnotationAspect(LineAnnotationAspect.DATE, true) { + @Override public String doGetValue(LineInfo info) { final Date date = info.getDate(); return date == null ? "" : DateFormatUtil.formatPrettyDate(date); } }; - private final LineAnnotationAspect REVISION_ASPECT = new GitAnnotationAspect(GitAnnotationAspect.REVISION, false) { + private final LineAnnotationAspect REVISION_ASPECT = new GitAnnotationAspect(LineAnnotationAspect.REVISION, false) { @Override protected String doGetValue(LineInfo lineInfo) { final GitRevisionNumber revision = lineInfo.getRevision(); @@ -78,101 +57,78 @@ public class GitFileAnnotation extends FileAnnotation { } }; - private final LineAnnotationAspect AUTHOR_ASPECT = new GitAnnotationAspect(GitAnnotationAspect.AUTHOR, true) { + private final LineAnnotationAspect AUTHOR_ASPECT = new GitAnnotationAspect(LineAnnotationAspect.AUTHOR, true) { @Override protected String doGetValue(LineInfo lineInfo) { final String author = lineInfo.getAuthor(); return author == null ? "" : author; } }; - private final GitVcs myVcs; - /** - * A constructor - * - * @param project the project of annotation provider - * @param file the git root - * @param monitorFlag if false the file system will not be listened for changes (used for annotated files from the repository). - * @param revision - */ - public GitFileAnnotation(@NotNull final Project project, @NotNull VirtualFile file, final boolean monitorFlag, final VcsRevisionNumber revision) { + public GitFileAnnotation(@NotNull final Project project, + @NotNull VirtualFile file, + final VcsRevisionNumber revision) { super(project); myProject = project; - myVcs = GitVcs.getInstance(myProject); + myVcs = ObjectUtils.assertNotNull(GitVcs.getInstance(myProject)); myFile = file; myBaseRevision = revision == null ? (myVcs.getDiffProvider().getCurrentRevision(file)) : revision; } - /** - * Add revisions to the list (from log) - * - * @param revisions revisions to add - */ public void addLogEntries(List revisions) { for (VcsFileRevision vcsFileRevision : revisions) { myRevisionMap.put(vcsFileRevision.getRevisionNumber(), vcsFileRevision); } } - /** - * {@inheritDoc} - */ + @Override public void dispose() { } - /** - * {@inheritDoc} - */ + @Override public LineAnnotationAspect[] getAspects() { return new LineAnnotationAspect[]{REVISION_ASPECT, DATE_ASPECT, AUTHOR_ASPECT}; } - /** - * {@inheritDoc} - */ + @Override public String getToolTip(final int lineNumber) { if (myLines.size() <= lineNumber || lineNumber < 0) { return ""; } final LineInfo info = myLines.get(lineNumber); - if (info == null) { - return ""; - } VcsFileRevision fileRevision = myRevisionMap.get(info.getRevision()); if (fileRevision != null) { - return GitBundle - .message("annotation.tool.tip", info.getRevision().asString(), info.getAuthor(), info.getDate(), - fileRevision.getCommitMessage()); + return GitBundle.message("annotation.tool.tip", info.getRevision().asString(), info.getAuthor(), info.getDate(), + fileRevision.getCommitMessage()); } else { return ""; } } - /** - * {@inheritDoc} - */ + @Override public String getAnnotatedContent() { return myContentBuffer.toString(); } - /** - * {@inheritDoc} - */ + @Override public List getRevisions() { final List result = new ArrayList(myRevisionMap.values()); Collections.sort(result, new Comparator() { - public int compare(final VcsFileRevision o1, final VcsFileRevision o2) { + @Override + public int compare(@NotNull VcsFileRevision o1, @NotNull VcsFileRevision o2) { return -1 * o1.getRevisionNumber().compareTo(o2.getRevisionNumber()); } }); return result; } + @Override public boolean revisionsNotEmpty() { return ! myRevisionMap.isEmpty(); } + @Override public AnnotationSourceSwitcher getAnnotationSourceSwitcher() { return null; } @@ -182,19 +138,16 @@ public class GitFileAnnotation extends FileAnnotation { return myLines.size(); } - /** - * {@inheritDoc} - */ + @Override public VcsRevisionNumber getLineRevisionNumber(final int lineNumber) { if (lineNumberCheck(lineNumber)) { return null; } - final LineInfo lineInfo = myLines.get(lineNumber); - return lineInfo == null ? null : lineInfo.getRevision(); + return myLines.get(lineNumber).getRevision(); } private boolean lineNumberCheck(int lineNumber) { - return myLines.size() <= lineNumber || lineNumber < 0 || myLines.get(lineNumber) == null; + return myLines.size() <= lineNumber || lineNumber < 0; } @Override @@ -202,13 +155,13 @@ public class GitFileAnnotation extends FileAnnotation { if (lineNumberCheck(lineNumber)) { return null; } - final LineInfo lineInfo = myLines.get(lineNumber); - return lineInfo == null ? null : lineInfo.getDate(); + return myLines.get(lineNumber).getDate(); } /** * Get revision number for the line. */ + @Override public VcsRevisionNumber originalRevision(int lineNumber) { return getLineRevisionNumber(lineNumber); } @@ -248,6 +201,7 @@ public class GitFileAnnotation extends FileAnnotation { super(id, showByDefault); } + @Override public String getValue(int lineNumber) { if (lineNumberCheck(lineNumber)) { return ""; @@ -262,10 +216,8 @@ public class GitFileAnnotation extends FileAnnotation { @Override protected void showAffectedPaths(int lineNum) { if (lineNum >= 0 && lineNum < myLines.size()) { - final LineInfo info = myLines.get(lineNum); - if (info != null) { - ShowAllAffectedGenericAction.showSubmittedFiles(myProject, info.getRevision(), myFile, GitVcs.getKey()); - } + LineInfo info = myLines.get(lineNum); + ShowAllAffectedGenericAction.showSubmittedFiles(myProject, info.getRevision(), myFile, GitVcs.getKey()); } } } @@ -274,54 +226,31 @@ public class GitFileAnnotation extends FileAnnotation { * Line information */ static class LineInfo { - /** - * date of the change - */ private final Date myDate; - /** - * revision number - */ private final GitRevisionNumber myRevision; - /** - * the author of the change - */ private final String myAuthor; - /** - * A constructor - * - * @param date date of the change - * @param revision revision number - * @param author the author of the change - */ - public LineInfo(final Date date, final GitRevisionNumber revision, final String author) { + public LineInfo(Date date, GitRevisionNumber revision, String author) { myDate = date; myRevision = revision; myAuthor = author; } - /** - * @return the revision date - */ public Date getDate() { return myDate; } - /** - * @return the revision number - */ public GitRevisionNumber getRevision() { return myRevision; } - /** - * @return the author of the change - */ public String getAuthor() { return myAuthor; } } + @NotNull + @Override public VirtualFile getFile() { return myFile; }