mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 02:59:33 +07:00
cleanup: get rid of LinkedList; hide implementation details
GitOrigin-RevId: 0fce09c1eb5e86c5adda97fb23eec77d78f77da4
This commit is contained in:
committed by
intellij-monorepo-bot
parent
196335d01e
commit
10afd2fead
@@ -15086,7 +15086,7 @@ c:com.intellij.openapi.fileEditor.impl.IdeDocumentHistoryImpl
|
|||||||
- getChangedFiles():java.util.List
|
- getChangedFiles():java.util.List
|
||||||
- p:getFileEditorManager():com.intellij.openapi.fileEditor.ex.FileEditorManagerEx
|
- p:getFileEditorManager():com.intellij.openapi.fileEditor.ex.FileEditorManagerEx
|
||||||
- p:getSelectedEditor():com.intellij.openapi.fileEditor.ex.FileEditorWithProvider
|
- p:getSelectedEditor():com.intellij.openapi.fileEditor.ex.FileEditorWithProvider
|
||||||
- getState():com.intellij.openapi.fileEditor.impl.IdeDocumentHistoryImpl$RecentlyChangedFilesState
|
- getState():java.lang.Object
|
||||||
- gotoPlaceInfo(com.intellij.openapi.fileEditor.impl.IdeDocumentHistoryImpl$PlaceInfo):V
|
- gotoPlaceInfo(com.intellij.openapi.fileEditor.impl.IdeDocumentHistoryImpl$PlaceInfo):V
|
||||||
- gotoPlaceInfo(com.intellij.openapi.fileEditor.impl.IdeDocumentHistoryImpl$PlaceInfo,Z):V
|
- gotoPlaceInfo(com.intellij.openapi.fileEditor.impl.IdeDocumentHistoryImpl$PlaceInfo,Z):V
|
||||||
- f:includeCurrentCommandAsNavigation():V
|
- f:includeCurrentCommandAsNavigation():V
|
||||||
@@ -15096,7 +15096,7 @@ c:com.intellij.openapi.fileEditor.impl.IdeDocumentHistoryImpl
|
|||||||
- isNavigateNextChangeAvailable():Z
|
- isNavigateNextChangeAvailable():Z
|
||||||
- f:isNavigatePreviousChangeAvailable():Z
|
- f:isNavigatePreviousChangeAvailable():Z
|
||||||
- isSame(com.intellij.openapi.fileEditor.impl.IdeDocumentHistoryImpl$PlaceInfo,com.intellij.openapi.fileEditor.impl.IdeDocumentHistoryImpl$PlaceInfo):Z
|
- isSame(com.intellij.openapi.fileEditor.impl.IdeDocumentHistoryImpl$PlaceInfo,com.intellij.openapi.fileEditor.impl.IdeDocumentHistoryImpl$PlaceInfo):Z
|
||||||
- loadState(com.intellij.openapi.fileEditor.impl.IdeDocumentHistoryImpl$RecentlyChangedFilesState):V
|
- loadState(java.lang.Object):V
|
||||||
- navigateNextChange():V
|
- navigateNextChange():V
|
||||||
- f:navigatePreviousChange():V
|
- f:navigatePreviousChange():V
|
||||||
- f:onSelectionChanged():V
|
- f:onSelectionChanged():V
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ com/intellij/openapi/editor/markup/AnalyzerStatus
|
|||||||
com/intellij/openapi/extensions/impl/ExtensionPointImpl
|
com/intellij/openapi/extensions/impl/ExtensionPointImpl
|
||||||
com/intellij/openapi/fileEditor/impl/EditorCompositeListener
|
com/intellij/openapi/fileEditor/impl/EditorCompositeListener
|
||||||
com/intellij/openapi/fileEditor/impl/FileEditorOpenOptions
|
com/intellij/openapi/fileEditor/impl/FileEditorOpenOptions
|
||||||
com/intellij/openapi/fileEditor/impl/IdeDocumentHistoryImpl$RecentlyChangedFilesState
|
|
||||||
com/intellij/openapi/fileEditor/impl/text/TextEditorComponent
|
com/intellij/openapi/fileEditor/impl/text/TextEditorComponent
|
||||||
com/intellij/openapi/keymap/impl/ActionProcessor
|
com/intellij/openapi/keymap/impl/ActionProcessor
|
||||||
com/intellij/openapi/keymap/impl/ui/KeymapScheme
|
com/intellij/openapi/keymap/impl/ui/KeymapScheme
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ import java.util.function.Predicate;
|
|||||||
|
|
||||||
@State(name = "IdeDocumentHistory", storages = @Storage(StoragePathMacros.PRODUCT_WORKSPACE_FILE), reportStatistic = false)
|
@State(name = "IdeDocumentHistory", storages = @Storage(StoragePathMacros.PRODUCT_WORKSPACE_FILE), reportStatistic = false)
|
||||||
public class IdeDocumentHistoryImpl extends IdeDocumentHistory
|
public class IdeDocumentHistoryImpl extends IdeDocumentHistory
|
||||||
implements Disposable, PersistentStateComponent<IdeDocumentHistoryImpl.RecentlyChangedFilesState> {
|
implements Disposable, PersistentStateComponent<Object> {
|
||||||
private static final Logger LOG = Logger.getInstance(IdeDocumentHistoryImpl.class);
|
private static final Logger LOG = Logger.getInstance(IdeDocumentHistoryImpl.class);
|
||||||
|
|
||||||
private static final int BACK_QUEUE_LIMIT = Registry.intValue("editor.navigation.history.stack.size");
|
private static final int BACK_QUEUE_LIMIT = Registry.intValue("editor.navigation.history.stack.size");
|
||||||
@@ -75,8 +75,8 @@ public class IdeDocumentHistoryImpl extends IdeDocumentHistory
|
|||||||
|
|
||||||
private FileDocumentManager myFileDocumentManager;
|
private FileDocumentManager myFileDocumentManager;
|
||||||
|
|
||||||
private final LinkedList<PlaceInfo> backPlaces = new LinkedList<>(); // LinkedList of PlaceInfo's
|
private final Deque<PlaceInfo> backPlaces = new ArrayDeque<>();
|
||||||
private final LinkedList<PlaceInfo> forwardPlaces = new LinkedList<>(); // LinkedList of PlaceInfo's
|
private final Deque<PlaceInfo> forwardPlaces = new ArrayDeque<>();
|
||||||
private boolean myBackInProgress;
|
private boolean myBackInProgress;
|
||||||
private boolean forwardInProgress;
|
private boolean forwardInProgress;
|
||||||
private Object myCurrentCommandGroupId;
|
private Object myCurrentCommandGroupId;
|
||||||
@@ -84,7 +84,7 @@ public class IdeDocumentHistoryImpl extends IdeDocumentHistory
|
|||||||
private boolean registeredBackPlaceInLastGroup;
|
private boolean registeredBackPlaceInLastGroup;
|
||||||
|
|
||||||
// change's navigation
|
// change's navigation
|
||||||
private final LinkedList<PlaceInfo> changePlaces = new LinkedList<>(); // LinkedList of PlaceInfo's
|
private final Deque<PlaceInfo> changePlaces = new ArrayDeque<>();
|
||||||
private int currentIndex;
|
private int currentIndex;
|
||||||
|
|
||||||
private PlaceInfo commandStartPlace;
|
private PlaceInfo commandStartPlace;
|
||||||
@@ -231,29 +231,16 @@ public class IdeDocumentHistoryImpl extends IdeDocumentHistory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static final class RecentlyChangedFilesState {
|
private record RecentlyChangedFilesState(
|
||||||
@XCollection(style = XCollection.Style.v2)
|
@XCollection(style = XCollection.Style.v2)
|
||||||
public final List<String> changedPaths = new ArrayList<>();
|
List<String> changedPaths) {
|
||||||
|
RecentlyChangedFilesState() {
|
||||||
@Override
|
this(new ArrayList<>());
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (o == null || getClass() != o.getClass()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return changedPaths.equals(((RecentlyChangedFilesState)o).changedPaths);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return changedPaths.hashCode();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RecentlyChangedFilesState getState() {
|
public Object getState() {
|
||||||
synchronized (state) {
|
synchronized (state) {
|
||||||
RecentlyChangedFilesState stateSnapshot = new RecentlyChangedFilesState();
|
RecentlyChangedFilesState stateSnapshot = new RecentlyChangedFilesState();
|
||||||
stateSnapshot.changedPaths.addAll(state.changedPaths);
|
stateSnapshot.changedPaths.addAll(state.changedPaths);
|
||||||
@@ -262,10 +249,10 @@ public class IdeDocumentHistoryImpl extends IdeDocumentHistory
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadState(@NotNull RecentlyChangedFilesState state) {
|
public void loadState(@NotNull Object state) {
|
||||||
synchronized (this.state) {
|
synchronized (this.state) {
|
||||||
this.state.changedPaths.clear();
|
this.state.changedPaths.clear();
|
||||||
this.state.changedPaths.addAll(state.changedPaths);
|
this.state.changedPaths.addAll(((RecentlyChangedFilesState)state).changedPaths);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,7 +288,7 @@ public class IdeDocumentHistoryImpl extends IdeDocumentHistory
|
|||||||
return createPlaceInfo(selectedEditorWithProvider.getFileEditor(), selectedEditorWithProvider.getProvider());
|
return createPlaceInfo(selectedEditorWithProvider.getFileEditor(), selectedEditorWithProvider.getProvider());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static @Nullable PlaceInfo getPlaceInfoFromFocus(Project project) {
|
private @Nullable PlaceInfo getPlaceInfoFromFocus(Project project) {
|
||||||
FileEditor fileEditor = new FocusBasedCurrentEditorProvider().getCurrentEditor(project);
|
FileEditor fileEditor = new FocusBasedCurrentEditorProvider().getCurrentEditor(project);
|
||||||
if (fileEditor instanceof TextEditor && fileEditor.isValid()) {
|
if (fileEditor instanceof TextEditor && fileEditor.isValid()) {
|
||||||
VirtualFile file = fileEditor.getFile();
|
VirtualFile file = fileEditor.getFile();
|
||||||
@@ -500,6 +487,7 @@ public class IdeDocumentHistoryImpl extends IdeDocumentHistory
|
|||||||
removeInvalidFilesFromStacks();
|
removeInvalidFilesFromStacks();
|
||||||
if (currentIndex == 0) return;
|
if (currentIndex == 0) return;
|
||||||
PlaceInfo currentPlace = getCurrentPlaceInfo();
|
PlaceInfo currentPlace = getCurrentPlaceInfo();
|
||||||
|
List<PlaceInfo> changePlaces = getChangePlaces();
|
||||||
for (int i = currentIndex - 1; i >= 0; i--) {
|
for (int i = currentIndex - 1; i >= 0; i--) {
|
||||||
PlaceInfo info = changePlaces.get(i);
|
PlaceInfo info = changePlaces.get(i);
|
||||||
if (currentPlace == null || !isSame(currentPlace, info)) {
|
if (currentPlace == null || !isSame(currentPlace, info)) {
|
||||||
@@ -510,14 +498,30 @@ public class IdeDocumentHistoryImpl extends IdeDocumentHistory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void navigateNextChange() {
|
||||||
|
removeInvalidFilesFromStacks();
|
||||||
|
if (currentIndex >= changePlaces.size()) return;
|
||||||
|
PlaceInfo currentPlace = getCurrentPlaceInfo();
|
||||||
|
List<PlaceInfo> changePlaces = getChangePlaces();
|
||||||
|
for (int i = currentIndex; i < changePlaces.size(); i++) {
|
||||||
|
PlaceInfo info = changePlaces.get(i);
|
||||||
|
if (currentPlace == null || !isSame(currentPlace, info)) {
|
||||||
|
executeCommand(() -> gotoPlaceInfo(info), "", null);
|
||||||
|
currentIndex = i + 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<PlaceInfo> getBackPlaces() {
|
public @NotNull List<PlaceInfo> getBackPlaces() {
|
||||||
return Collections.unmodifiableList(backPlaces);
|
return List.copyOf(backPlaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PlaceInfo> getChangePlaces() {
|
public List<PlaceInfo> getChangePlaces() {
|
||||||
return Collections.unmodifiableList(changePlaces);
|
return List.copyOf(changePlaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -551,27 +555,12 @@ public class IdeDocumentHistoryImpl extends IdeDocumentHistory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void navigateNextChange() {
|
|
||||||
removeInvalidFilesFromStacks();
|
|
||||||
if (currentIndex >= changePlaces.size()) return;
|
|
||||||
PlaceInfo currentPlace = getCurrentPlaceInfo();
|
|
||||||
for (int i = currentIndex; i < changePlaces.size(); i++) {
|
|
||||||
PlaceInfo info = changePlaces.get(i);
|
|
||||||
if (currentPlace == null || !isSame(currentPlace, info)) {
|
|
||||||
executeCommand(() -> gotoPlaceInfo(info), "", null);
|
|
||||||
currentIndex = i + 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNavigateNextChangeAvailable() {
|
public boolean isNavigateNextChangeAvailable() {
|
||||||
return currentIndex < changePlaces.size();
|
return currentIndex < changePlaces.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean removeInvalidFilesFrom(@NotNull List<PlaceInfo> backPlaces) {
|
private boolean removeInvalidFilesFrom(@NotNull Deque<PlaceInfo> backPlaces) {
|
||||||
return backPlaces
|
return backPlaces
|
||||||
.removeIf(info -> (info.myFile instanceof OptionallyIncluded &&
|
.removeIf(info -> (info.myFile instanceof OptionallyIncluded &&
|
||||||
!((OptionallyIncluded)info.myFile).isIncludedInDocumentHistory(project)) ||
|
!((OptionallyIncluded)info.myFile).isIncludedInDocumentHistory(project)) ||
|
||||||
@@ -647,19 +636,18 @@ public class IdeDocumentHistoryImpl extends IdeDocumentHistory
|
|||||||
getCaretPosition(fileEditor), System.currentTimeMillis());
|
getCaretPosition(fileEditor), System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static @Nullable RangeMarker getCaretPosition(@NotNull FileEditor fileEditor) {
|
private @Nullable RangeMarker getCaretPosition(@NotNull FileEditor fileEditor) {
|
||||||
if (!(fileEditor instanceof TextEditor)) {
|
if (!(fileEditor instanceof TextEditor)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Editor editor = ((TextEditor)fileEditor).getEditor();
|
Editor editor = ((TextEditor)fileEditor).getEditor();
|
||||||
int offset = editor.getCaretModel().getOffset();
|
int offset = editor.getCaretModel().getOffset();
|
||||||
|
|
||||||
return editor.getDocument().createRangeMarker(offset, offset);
|
return editor.getDocument().createRangeMarker(offset, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void putLastOrMerge(@NotNull PlaceInfo next, int limit, boolean isChanged, Object groupId) {
|
private void putLastOrMerge(@NotNull PlaceInfo next, int limit, boolean isChanged, Object groupId) {
|
||||||
LinkedList<PlaceInfo> list = isChanged ? changePlaces : backPlaces;
|
Deque<PlaceInfo> list = isChanged ? changePlaces : backPlaces;
|
||||||
MessageBus messageBus = project.getMessageBus();
|
MessageBus messageBus = project.getMessageBus();
|
||||||
RecentPlacesListener listener = messageBus.syncPublisher(RecentPlacesListener.TOPIC);
|
RecentPlacesListener listener = messageBus.syncPublisher(RecentPlacesListener.TOPIC);
|
||||||
if (!list.isEmpty()) {
|
if (!list.isEmpty()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user