From 98784b9d0638ca3dd1e87f042f22b800589214f1 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 25 Jul 2018 12:53:35 +0300 Subject: [PATCH] cleanup --- .../openapi/actionSystem/AnActionEvent.java | 7 +++++-- .../openapi/actionSystem/DataProvider.java | 1 + .../codeInsight/hint/LineTooltipRenderer.java | 19 +++++++++---------- .../openapi/vfs/newvfs/impl/VfsData.java | 12 +++++++++--- .../openapi/roots/impl/FileIndexBase.java | 2 +- .../openapi/roots/impl/RootIndex.java | 19 +++++++++---------- .../util/indexing/containers/SortedIdSet.java | 16 +++++++++++----- 7 files changed, 45 insertions(+), 31 deletions(-) diff --git a/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnActionEvent.java b/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnActionEvent.java index 8cf6110defc3..cd564990deed 100644 --- a/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnActionEvent.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnActionEvent.java @@ -139,18 +139,21 @@ public class AnActionEvent implements PlaceProvider { } @NonNls - public static String injectedId(String dataId) { + @NotNull + public static String injectedId(@NotNull String dataId) { synchronized(ourInjectedIds) { return ourInjectedIds.computeIfAbsent(dataId, i -> ourInjectedPrefix + i); } } @NonNls + @NotNull public static String uninjectedId(@NotNull String dataId) { return StringUtil.trimStart(dataId, ourInjectedPrefix); } - public static DataContext getInjectedDataContext(final DataContext context) { + @NotNull + public static DataContext getInjectedDataContext(@NotNull DataContext context) { return new DataContextWrapper(context) { @Nullable @Override diff --git a/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/DataProvider.java b/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/DataProvider.java index 5bf8a710a525..5327e98f2ca6 100644 --- a/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/DataProvider.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/DataProvider.java @@ -28,6 +28,7 @@ import org.jetbrains.annotations.Nullable; * * @see DataContext */ +@FunctionalInterface public interface DataProvider { /** * Returns the object corresponding to the specified data identifier. Some of the supported diff --git a/platform/platform-impl/src/com/intellij/codeInsight/hint/LineTooltipRenderer.java b/platform/platform-impl/src/com/intellij/codeInsight/hint/LineTooltipRenderer.java index 4a4223055f64..40ebcb404e98 100644 --- a/platform/platform-impl/src/com/intellij/codeInsight/hint/LineTooltipRenderer.java +++ b/platform/platform-impl/src/com/intellij/codeInsight/hint/LineTooltipRenderer.java @@ -23,6 +23,7 @@ import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.IdeActions; import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.keymap.KeymapUtil; import com.intellij.ui.*; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.GridBag; @@ -46,8 +47,6 @@ import java.awt.event.MouseEvent; import java.net.URL; import java.util.ArrayList; -import static com.intellij.openapi.keymap.KeymapUtil.getActiveKeymapShortcuts; - /** * @author cdr */ @@ -56,10 +55,11 @@ public class LineTooltipRenderer extends ComparableObject.Impl implements Toolti @NonNls @Nullable protected String myText; //is used for suppressing some events while processing links - private volatile boolean myActiveLink = false; + private volatile boolean myActiveLink; //mostly is used as a marker that we are in popup with description protected final int myCurrentWidth; + @FunctionalInterface protected interface TooltipReloader { void reload(boolean toExpand); } @@ -75,8 +75,7 @@ public class LineTooltipRenderer extends ComparableObject.Impl implements Toolti } @NotNull - protected JPanel createMainPanel(@NotNull final HintHint hintHint, - @NotNull JComponent pane) { + private JPanel createMainPanel(@NotNull final HintHint hintHint, @NotNull JComponent pane) { JPanel grid = new JPanel(new GridBagLayout()); GridBag bag = new GridBag() .anchor(GridBagConstraints.CENTER) @@ -162,19 +161,19 @@ public class LineTooltipRenderer extends ComparableObject.Impl implements Toolti }; - TooltipReloader reloader = (toExpand) -> reloadFor(hint, editor, p, editorPane, alignToRight, group, hintHint, toExpand); + TooltipReloader reloader = toExpand -> reloadFor(hint, editor, p, editorPane, alignToRight, group, hintHint, toExpand); actions.add(new AnAction() { // an action to expand description when tooltip was shown after mouse move; need to unregister from editor component { - registerCustomShortcutSet(getActiveKeymapShortcuts(IdeActions.ACTION_SHOW_ERROR_DESCRIPTION), contentComponent); + registerCustomShortcutSet(KeymapUtil.getActiveKeymapShortcuts(IdeActions.ACTION_SHOW_ERROR_DESCRIPTION), contentComponent); } @Override public void actionPerformed(final AnActionEvent e) { // The tooltip gets the focus if using a screen reader and invocation through a keyboard shortcut. - hintHint.setRequestFocus(ScreenReader.isActive() && (e.getInputEvent() instanceof KeyEvent)); - ActionsCollector.getInstance().record("tooltip.actions.show.description.shortcut", this.getClass()); + hintHint.setRequestFocus(ScreenReader.isActive() && e.getInputEvent() instanceof KeyEvent); + ActionsCollector.getInstance().record("tooltip.actions.show.description.shortcut", getClass()); reloader.reload(!expanded); } }); @@ -202,7 +201,7 @@ public class LineTooltipRenderer extends ComparableObject.Impl implements Toolti return; } - ActionsCollector.getInstance().record("tooltip.actions.show.description.morelink", this.getClass()); + ActionsCollector.getInstance().record("tooltip.actions.show.description.morelink", getClass()); reloader.reload(!expanded); } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VfsData.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VfsData.java index 97cc7726bef5..3b2f3df316f1 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VfsData.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VfsData.java @@ -287,8 +287,14 @@ public class VfsData { // non-final field accesses are synchronized on this instance, but this happens in VirtualDirectoryImpl public static class DirectoryData { private static final AtomicFieldUpdater updater = AtomicFieldUpdater.forFieldOfType(DirectoryData.class, KeyFMap.class); - @NotNull volatile KeyFMap myUserMap = KeyFMap.EMPTY_MAP; - @NotNull int[] myChildrenIds = ArrayUtil.EMPTY_INT_ARRAY; // guarded by this + @NotNull + volatile KeyFMap myUserMap = KeyFMap.EMPTY_MAP; + /** + * sorted by {@link VfsData#getNameByFileId(int)} + * @see VirtualDirectoryImpl#findIndex(int[], CharSequence, boolean) + */ + @NotNull + int[] myChildrenIds = ArrayUtil.EMPTY_INT_ARRAY; // guarded by this private Set myAdoptedNames; // guarded by this @NotNull @@ -323,7 +329,7 @@ public class VfsData { } myAdoptedNames.add(name); } - void addAdoptedNames(Collection names, boolean caseSensitive) { + void addAdoptedNames(Collection names, boolean caseSensitive) { if (myAdoptedNames == null) { myAdoptedNames = new THashSet<>(0, caseSensitive ? CharSequenceHashingStrategy.CASE_SENSITIVE : CharSequenceHashingStrategy.CASE_INSENSITIVE); } diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/FileIndexBase.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/FileIndexBase.java index 998ae91e5c4d..2d2f4b2ce2fd 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/FileIndexBase.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/FileIndexBase.java @@ -40,7 +40,7 @@ public abstract class FileIndexBase implements FileIndex { !isScopeDisposed() && isInContent(file)); }; - public FileIndexBase(@NotNull DirectoryIndex directoryIndex, @NotNull FileTypeRegistry fileTypeManager) { + FileIndexBase(@NotNull DirectoryIndex directoryIndex, @NotNull FileTypeRegistry fileTypeManager) { myDirectoryIndex = directoryIndex; myFileTypeRegistry = fileTypeManager; } diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootIndex.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootIndex.java index 6fd2b5562303..0f9eef6f2b90 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootIndex.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootIndex.java @@ -37,7 +37,7 @@ import org.jetbrains.jps.model.fileTypes.FileNameMatcherFactory; import java.util.*; public class RootIndex { - public static final Comparator BY_OWNER_MODULE = (o1, o2) -> { + static final Comparator BY_OWNER_MODULE = (o1, o2) -> { String name1 = o1.getOwnerModule().getName(); String name2 = o2.getOwnerModule().getName(); return name1.compareTo(name2); @@ -54,8 +54,7 @@ public class RootIndex { private final PackageDirectoryCache myPackageDirectoryCache; private OrderEntryGraph myOrderEntryGraph; - // made public for Upsource - public RootIndex(@NotNull Project project) { + RootIndex(@NotNull Project project) { myProject = project; ApplicationManager.getApplication().assertReadAccessAllowed(); @@ -312,7 +311,7 @@ public class RootIndex { private MultiMap myLibClassRootEntries; private MultiMap myLibSourceRootEntries; - public OrderEntryGraph(Project project, RootInfo rootInfo) { + OrderEntryGraph(Project project, RootInfo rootInfo) { myProject = project; myRootInfo = rootInfo; myAllRoots = myRootInfo.getAllRoots(); @@ -431,7 +430,6 @@ public class RootIndex { if (roots == null) { return Collections.emptyList(); } - List result = new ArrayList<>(); Stack stack = new Stack<>(); for (VirtualFile root : roots) { Collection nodes = myRoots.get(root); @@ -441,6 +439,7 @@ public class RootIndex { } Set seen = new HashSet<>(); + List result = new ArrayList<>(); while (!stack.isEmpty()) { Node node = stack.pop(); if (seen.contains(node)) { @@ -475,7 +474,7 @@ public class RootIndex { return result; } - public Set getDependentUnloadedModules(@NotNull Module module) { + Set getDependentUnloadedModules(@NotNull Module module) { return myDependentUnloadedModulesCache.get(module); } @@ -483,9 +482,9 @@ public class RootIndex { * @return names of unloaded modules which directly or transitively via exported dependencies depend on the specified module */ private Set collectDependentUnloadedModules(@NotNull Module module) { - ArrayDeque stack = new ArrayDeque<>(); Node start = myGraph.myNodes.get(module); if (start == null) return Collections.emptySet(); + Deque stack = new ArrayDeque<>(); stack.push(start); Set seen = new HashSet<>(); Set result = null; @@ -574,7 +573,7 @@ public class RootIndex { } @Nullable - protected static String getPackageNameForSubdir(@Nullable String parentPackageName, @NotNull String subdirName) { + private static String getPackageNameForSubdir(@Nullable String parentPackageName, @NotNull String subdirName) { if (parentPackageName == null) return null; return parentPackageName.isEmpty() ? subdirName : parentPackageName + "." + subdirName; } @@ -899,7 +898,7 @@ public class RootIndex { } @NotNull - public Set getDependentUnloadedModules(@NotNull Module module) { + Set getDependentUnloadedModules(@NotNull Module module) { return getOrderEntryGraph().getDependentUnloadedModules(module); } @@ -910,7 +909,7 @@ public class RootIndex { abstract static class SynchronizedSLRUCache extends SLRUMap { protected final Object myLock = new Object(); - protected SynchronizedSLRUCache(final int protectedQueueSize, final int probationalQueueSize) { + SynchronizedSLRUCache(final int protectedQueueSize, final int probationalQueueSize) { super(protectedQueueSize, probationalQueueSize); } diff --git a/platform/util/src/com/intellij/util/indexing/containers/SortedIdSet.java b/platform/util/src/com/intellij/util/indexing/containers/SortedIdSet.java index d495f4bd3315..4287111821e7 100644 --- a/platform/util/src/com/intellij/util/indexing/containers/SortedIdSet.java +++ b/platform/util/src/com/intellij/util/indexing/containers/SortedIdSet.java @@ -37,15 +37,17 @@ public class SortedIdSet implements Cloneable, RandomAccessIntContainer { return mySize == 0; } + @Override public int size() { return mySize; } + @Override public boolean add(int value) { assert value > 0; int pos; - if (mySetLength == 0 || (mySetLength > 0 && Math.abs(mySet[mySetLength -1]) < value)) { + if (mySetLength == 0 || mySetLength > 0 && Math.abs(mySet[mySetLength - 1]) < value) { pos = -mySetLength-1; // most of the time during bulk indexing we add near the end } else { @@ -74,6 +76,7 @@ public class SortedIdSet implements Cloneable, RandomAccessIntContainer { return true; } + @Override public boolean remove(int value) { assert value > 0; int pos = binarySearch(mySet, 0, mySetLength, value); @@ -136,12 +139,12 @@ public class SortedIdSet implements Cloneable, RandomAccessIntContainer { } } - private static int binarySearch(int[] set, int off, int length, int key) { - int low = off; - int high = length - 1; + private static int binarySearch(final int[] set, int startOffset, int endOffset, int key) { + int low = startOffset; + int high = endOffset - 1; while (low <= high) { - int mid = (low + high) >>> 1; + int mid = low + high >>> 1; int midVal = Math.abs(set[mid]); if (midVal < key) @@ -161,6 +164,7 @@ public class SortedIdSet implements Cloneable, RandomAccessIntContainer { } } + @Override public boolean contains(int value) { if(value <= 0) return false; int pos = binarySearch(mySet, 0, mySetLength, value); @@ -179,6 +183,7 @@ public class SortedIdSet implements Cloneable, RandomAccessIntContainer { } } + @Override public void compact() { if(2 * mySize < mySetLength && mySetLength > 5) { int positivePosition = -1; @@ -201,6 +206,7 @@ public class SortedIdSet implements Cloneable, RandomAccessIntContainer { } } + @Override public RandomAccessIntContainer ensureContainerCapacity(int count) { int newSize = mySetLength + count; if (newSize < mySet.length) return this;