prepare to fix IDEA-189650 IDE closes empty files when restarting

This commit is contained in:
Vladimir Krivosheev
2018-04-20 16:10:50 +02:00
parent 787d5b00e5
commit f0733bb677
12 changed files with 44 additions and 121 deletions
@@ -30,6 +30,7 @@ import com.intellij.testFramework.LightVirtualFile;
import com.intellij.util.IncorrectOperationException;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.concurrency.Promise;
import org.jetbrains.concurrency.Promises;
@@ -270,7 +271,7 @@ final class TestEditorManagerImpl extends FileEditorManagerEx implements Disposa
@Override
@NotNull
public FileEditorState readState(@NotNull Element sourceElement, @NotNull Project project, @NotNull VirtualFile file) {
public FileEditorState readState(@Nullable Element sourceElement, @NotNull Project project, @NotNull VirtualFile file) {
throw new IncorrectOperationException();
}
@@ -23,6 +23,7 @@ import com.intellij.psi.PsiDocumentManager;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class PsiAwareTextEditorProvider extends TextEditorProvider {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.fileEditor.impl.text.PsiAwareTextEditorProvider");
@@ -37,11 +38,11 @@ public class PsiAwareTextEditorProvider extends TextEditorProvider {
@Override
@NotNull
public FileEditorState readState(@NotNull final Element element, @NotNull final Project project, @NotNull final VirtualFile file) {
public FileEditorState readState(@Nullable Element element, @NotNull final Project project, @NotNull final VirtualFile file) {
final TextEditorState state = (TextEditorState)super.readState(element, project, file);
// Foldings
Element child = element.getChild(FOLDING_ELEMENT);
Element child = element == null ? null : element.getChild(FOLDING_ELEMENT);
if (child != null) {
Document document = FileDocumentManager.getInstance().getCachedDocument(file);
if (document == null) {
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.fileEditor;
import com.intellij.openapi.extensions.ExtensionPointName;
@@ -24,6 +10,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Should be registered via {@link #EP_FILE_EDITOR_PROVIDER}.
@@ -71,7 +58,7 @@ public interface FileEditorProvider {
* Use {@link FileEditorState#INSTANCE} as default implementation
*/
@NotNull
default FileEditorState readState(@NotNull Element sourceElement, @NotNull Project project, @NotNull VirtualFile file) {
default FileEditorState readState(@Nullable Element sourceElement, @NotNull Project project, @NotNull VirtualFile file) {
return FileEditorState.INSTANCE;
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.fileEditor.impl;
import com.intellij.ide.ui.UISettings;
@@ -31,7 +17,6 @@ import com.intellij.openapi.project.DumbAwareRunnable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupManager;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
@@ -216,7 +201,7 @@ public final class EditorHistoryManager implements PersistentStateComponent<Elem
/**
* @return array of valid files that are in the history, oldest first. May contain duplicates.
*/
public synchronized VirtualFile[] getFiles(){
public synchronized VirtualFile[] getFiles() {
final List<VirtualFile> result = new ArrayList<>(myEntriesList.size());
for (HistoryEntry entry : myEntriesList) {
VirtualFile file = entry.getFile();
@@ -306,8 +291,7 @@ public final class EditorHistoryManager implements PersistentStateComponent<Elem
try {
addEntry(HistoryEntry.createHeavy(myProject, e));
}
catch (InvalidDataException | ProcessCanceledException e1) {
// OK here
catch (ProcessCanceledException ignored) {
}
catch (Exception anyException) {
LOG.error(anyException);
@@ -195,17 +195,14 @@ final class HistoryEntry {
if (provider == null) {
continue;
}
if (Boolean.valueOf(providerElement.getAttributeValue(SELECTED_ATTR_VALUE))) {
if (Boolean.parseBoolean(providerElement.getAttributeValue(SELECTED_ATTR_VALUE))) {
selectedProvider = provider;
}
Element stateElement = providerElement.getChild(STATE_ELEMENT);
if (stateElement == null) {
throw new InvalidDataException();
}
if (file != null) {
FileEditorState state = provider.readState(stateElement, project, file);
Element stateElement = providerElement.getChild(STATE_ELEMENT);
// due to backward compatibility null cannot be passed, so, use empty element
FileEditorState state = provider.readState(stateElement == null ? JDOMUtil.internElement(new Element("")) : stateElement, project, file);
providerStates.add(Pair.create(provider, state));
}
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.fileEditor.impl.http;
import com.intellij.openapi.fileEditor.FileEditor;
@@ -26,6 +12,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.impl.http.HttpVirtualFile;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author nik
@@ -44,7 +31,7 @@ class HttpFileEditorProvider implements FileEditorProvider, DumbAware {
@Override
@NotNull
public FileEditorState readState(@NotNull final Element sourceElement, @NotNull final Project project, @NotNull final VirtualFile file) {
public FileEditorState readState(@Nullable Element sourceElement, @NotNull Project project, @NotNull VirtualFile file) {
return new TextEditorState();
}
@@ -71,8 +71,11 @@ public class TextEditorProvider implements FileEditorProvider, DumbAware {
@Override
@NotNull
public FileEditorState readState(@NotNull Element element, @NotNull Project project, @NotNull VirtualFile file) {
public FileEditorState readState(@Nullable Element element, @NotNull Project project, @NotNull VirtualFile file) {
TextEditorState state = new TextEditorState();
if (element == null) {
return state;
}
try {
List<Element> caretElements = element.getChildren(CARET_ELEMENT);
@@ -681,7 +681,7 @@ public class Mock {
@Override
@NotNull
public FileEditorState readState(@NotNull Element sourceElement, @NotNull Project project, @NotNull VirtualFile file) {
public FileEditorState readState(@Nullable Element sourceElement, @NotNull Project project, @NotNull VirtualFile file) {
throw new UnsupportedOperationException();
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.lang.properties.editor;
import com.intellij.lang.properties.PropertiesImplUtil;
@@ -34,6 +20,7 @@ import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class ResourceBundleEditorProvider extends FileTypeFactory implements FileEditorProvider, DumbAware {
private static final ResourceBundleFileType RESOURCE_BUNDLE_FILE_TYPE = new ResourceBundleFileType();
@@ -73,7 +60,7 @@ public class ResourceBundleEditorProvider extends FileTypeFactory implements Fil
@Override
@NotNull
public FileEditorState readState(@NotNull Element element, @NotNull Project project, @NotNull VirtualFile file) {
public FileEditorState readState(@Nullable Element element, @NotNull Project project, @NotNull VirtualFile file) {
return new ResourceBundleEditor.ResourceBundleEditorState(null);
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.designer;
import com.intellij.openapi.editor.Document;
@@ -22,6 +8,7 @@ import com.intellij.openapi.fileEditor.FileEditorStateLevel;
import com.intellij.openapi.vfs.VirtualFile;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author Alexander Lobas
@@ -70,16 +57,15 @@ public class DesignerEditorState implements FileEditorState {
* @see com.intellij.openapi.fileEditor.FileEditorProvider#readState(org.jdom.Element, com.intellij.openapi.project.Project, com.intellij.openapi.vfs.VirtualFile)
*/
@NotNull
public static FileEditorState readState(@NotNull Element sourceElement, @NotNull VirtualFile file, double defaultZoom) {
public static FileEditorState readState(@Nullable Element sourceElement, @NotNull VirtualFile file, double defaultZoom) {
double zoom = defaultZoom;
try {
zoom = Double.parseDouble(sourceElement.getAttributeValue(DESIGNER_ZOOM));
if (sourceElement != null) {
try {
zoom = Double.parseDouble(sourceElement.getAttributeValue(DESIGNER_ZOOM));
}
catch (Throwable ignored) {
}
}
catch (Throwable e) {
// ignore
}
return new DesignerEditorState(file, zoom);
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.uiDesigner.editor;
import com.intellij.openapi.diagnostic.Logger;
@@ -29,6 +15,7 @@ import com.intellij.testFramework.LightVirtualFile;
import com.intellij.util.ArrayUtil;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public final class UIFormEditorProvider implements FileEditorProvider, DumbAware {
private static final Logger LOG = Logger.getInstance("#com.intellij.uiDesigner.editor.UIFormEditorProvider");
@@ -49,7 +36,7 @@ public final class UIFormEditorProvider implements FileEditorProvider, DumbAware
@Override
@NotNull
public FileEditorState readState(@NotNull final Element element, @NotNull final Project project, @NotNull final VirtualFile file){
public FileEditorState readState(@Nullable Element element, @NotNull final Project project, @NotNull final VirtualFile file){
//TODO[anton,vova] implement
return new MyEditorState(-1, ArrayUtil.EMPTY_STRING_ARRAY);
}
@@ -1,3 +1,4 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.ipnb.editor;
import com.intellij.openapi.fileEditor.FileEditor;
@@ -6,10 +7,12 @@ import com.intellij.openapi.fileEditor.FileEditorProvider;
import com.intellij.openapi.fileEditor.FileEditorState;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.ipnb.IpnbFileType;
/**
@@ -32,10 +35,10 @@ public class IpnbEditorProvider implements FileEditorProvider, DumbAware {
@NotNull
@Override
public FileEditorState readState(@NotNull Element sourceElement, @NotNull Project project, @NotNull VirtualFile file) {
public FileEditorState readState(@Nullable Element sourceElement, @NotNull Project project, @NotNull VirtualFile file) {
final IpnbEditorState state = new IpnbEditorState(-1, 0);
final Element child = sourceElement.getChild(SELECTED_CELL);
state.setSelectedIndex(child == null ? 0 : Integer.parseInt(child.getAttributeValue(ID)));
final Element child = sourceElement == null ? null : sourceElement.getChild(SELECTED_CELL);
state.setSelectedIndex(child == null ? 0 : StringUtil.parseInt(child.getAttributeValue(ID), 0));
return state;
}