From 212b4d313aa6e20262063955c36fff5b5f8cd2e0 Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Mon, 9 Jul 2018 21:23:44 +0300 Subject: [PATCH] [vcs-log] reuse executeAndCatch --- .../vcs/log/data/index/IndexDataGetter.java | 71 ++++++------------- 1 file changed, 23 insertions(+), 48 deletions(-) diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/IndexDataGetter.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/IndexDataGetter.java index 62b784f3aca9..74b49f4c9d45 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/IndexDataGetter.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/IndexDataGetter.java @@ -15,7 +15,6 @@ */ package com.intellij.vcs.log.data.index; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Condition; @@ -36,6 +35,7 @@ import com.intellij.vcs.log.ui.filter.VcsLogTextFilterImpl; import com.intellij.vcs.log.util.TroveUtil; import com.intellij.vcsUtil.VcsUtil; import gnu.trove.TIntHashSet; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -46,8 +46,6 @@ import java.util.List; import java.util.Set; public class IndexDataGetter { - private static final Logger LOG = Logger.getInstance(IndexDataGetter.class); - @NotNull private final Project myProject; @NotNull private final Set myRoots; @NotNull private final VcsLogPersistentIndex.IndexStorage myIndexStorage; @@ -114,7 +112,7 @@ public class IndexDataGetter { @Nullable public List getParents(int index) { - try { + return executeAndCatch(() -> { List parentsIndexes = myIndexStorage.parents.get(index); if (parentsIndexes == null) return null; List result = ContainerUtil.newArrayList(); @@ -124,11 +122,7 @@ public class IndexDataGetter { result.add(id.getHash()); } return result; - } - catch (IOException e) { - myFatalErrorsConsumer.consume(this, e); - } - return null; + }); } // @@ -179,36 +173,19 @@ public class IndexDataGetter { @NotNull private TIntHashSet filterUsers(@NotNull Set users) { - try { - return myIndexStorage.users.getCommitsForUsers(users); - } - catch (IOException | StorageException e) { - myFatalErrorsConsumer.consume(this, e); - } - catch (RuntimeException e) { - processRuntimeException(e); - } - return new TIntHashSet(); + return executeAndCatch(() -> myIndexStorage.users.getCommitsForUsers(users), new TIntHashSet()); } @NotNull private TIntHashSet filterPaths(@NotNull Collection paths) { - try { - return myIndexStorage.paths.getCommitsForPaths(paths); - } - catch (IOException | StorageException e) { - myFatalErrorsConsumer.consume(this, e); - } - catch (RuntimeException e) { - processRuntimeException(e); - } - return new TIntHashSet(); + return executeAndCatch(() -> myIndexStorage.paths.getCommitsForPaths(paths), new TIntHashSet()); } @NotNull private TIntHashSet filterMessages(@NotNull VcsLogTextFilter filter) { - try { - if (!filter.isRegex()) { + if (!filter.isRegex()) { + TIntHashSet resultByTrigrams = executeAndCatch(() -> { + TIntHashSet commitsForSearch = myIndexStorage.trigrams.getCommitsForSubstring(filter.getText()); if (commitsForSearch != null) { TIntHashSet result = new TIntHashSet(); @@ -229,13 +206,10 @@ public class IndexDataGetter { }); return result; } - } - } - catch (StorageException e) { - myFatalErrorsConsumer.consume(this, e); - } - catch (RuntimeException e) { - processRuntimeException(e); + return null; + }); + + if (resultByTrigrams != null) return resultByTrigrams; } return filter(myIndexStorage.messages, message -> VcsLogTextFilterImpl.matches(filter, message)); @@ -244,7 +218,7 @@ public class IndexDataGetter { @NotNull private TIntHashSet filter(@NotNull PersistentMap map, @NotNull Condition condition) { TIntHashSet result = new TIntHashSet(); - try { + return executeAndCatch(() -> { Processor processor = integer -> { try { T value = map.get(integer); @@ -266,12 +240,8 @@ public class IndexDataGetter { else { myIndexStorage.messages.processKeys(processor); } - } - catch (IOException e) { - myFatalErrorsConsumer.consume(this, e); - } - - return result; + return result; + }, result); } // @@ -282,8 +252,7 @@ public class IndexDataGetter { public Set getFileNames(@NotNull FilePath path, int commit) { VirtualFile root = VcsUtil.getVcsRootFor(myProject, path); if (myRoots.contains(root)) { - Set result = executeAndCatch(() -> myIndexStorage.paths.getFileNames(path, commit)); - if (result != null) return result; + return executeAndCatch(() -> myIndexStorage.paths.getFileNames(path, commit), Collections.emptySet()); } return Collections.emptySet(); @@ -323,6 +292,12 @@ public class IndexDataGetter { @Nullable private T executeAndCatch(@NotNull Throwable2Computable computable) { + return executeAndCatch(computable, null); + } + + @Contract("_, !null -> !null") + @Nullable + private T executeAndCatch(@NotNull Throwable2Computable computable, @Nullable T defaultValue) { try { return computable.compute(); } @@ -333,7 +308,7 @@ public class IndexDataGetter { catch (RuntimeException e) { processRuntimeException(e); } - return null; + return defaultValue; } private void processRuntimeException(@NotNull RuntimeException e) {