mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
reduce usages of WriteExternalException
This commit is contained in:
@@ -45,12 +45,7 @@ final class OptionsManagerImpl extends OptionsManager implements PersistentState
|
||||
@Override
|
||||
public Element getState() {
|
||||
Element element = new Element("state");
|
||||
try {
|
||||
options.writeExternal(element);
|
||||
}
|
||||
catch (WriteExternalException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
options.writeExternal(element);
|
||||
return element;
|
||||
}
|
||||
|
||||
|
||||
@@ -105,13 +105,7 @@ public class DebuggerSettings implements Cloneable, PersistentStateComponent<Ele
|
||||
@Override
|
||||
public Element getState() {
|
||||
Element state = XmlSerializer.serialize(this, new SkipDefaultsSerializationFilter());
|
||||
try {
|
||||
DebuggerUtilsEx.writeFilters(state, "filter", mySteppingFilters);
|
||||
}
|
||||
catch (WriteExternalException e) {
|
||||
LOG.error(e);
|
||||
return null;
|
||||
}
|
||||
DebuggerUtilsEx.writeFilters(state, "filter", mySteppingFilters);
|
||||
|
||||
for (ContentState eachState : myContentStates.values()) {
|
||||
final Element content = new Element("content");
|
||||
|
||||
@@ -129,8 +129,7 @@ public class NodeRendererSettings implements PersistentStateComponent<Element> {
|
||||
myCustomRenderers.writeExternal(custom);
|
||||
}
|
||||
}
|
||||
catch (WriteExternalException e) {
|
||||
// ignore
|
||||
catch (WriteExternalException ignore) {
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
@@ -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.roots.libraries;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
@@ -27,7 +13,6 @@ import com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.roots.ModuleRootManagerTestCase;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
@@ -309,14 +294,9 @@ public class LibraryTest extends ModuleRootManagerTestCase {
|
||||
}
|
||||
|
||||
private static Element serialize(Library library) {
|
||||
try {
|
||||
Element element = new Element("root");
|
||||
library.writeExternal(element);
|
||||
return element;
|
||||
}
|
||||
catch (WriteExternalException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
Element element = new Element("root");
|
||||
library.writeExternal(element);
|
||||
return element;
|
||||
}
|
||||
|
||||
public void testAddRemoveJarDirectory() {
|
||||
|
||||
@@ -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.codeInspection;
|
||||
|
||||
import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
@@ -23,7 +9,6 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.DefaultJDOMExternalizer;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.FileViewProvider;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -341,7 +326,6 @@ public abstract class InspectionProfileEntry implements BatchSuppressableTool {
|
||||
* and bean-style getters/setters (like {@code int getToolOption(), void setToolOption(int)}) to store your options.
|
||||
*
|
||||
* @param node to store settings to.
|
||||
* @throws WriteExternalException if no data should be saved for this component.
|
||||
*/
|
||||
public void writeSettings(@NotNull Element node) {
|
||||
if (useNewSerializer()) {
|
||||
|
||||
@@ -156,7 +156,7 @@ public class ScopeToolState {
|
||||
throw e;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new WriteExternalException("Can't write settings for tool #" + entry.getShortName(), e);
|
||||
throw new RuntimeException("Can't write settings for tool #" + entry.getShortName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 com.intellij.psi.codeStyle;
|
||||
|
||||
import com.intellij.configurationStore.UnknownElementCollector;
|
||||
@@ -865,9 +866,6 @@ public class CodeStyleSettings extends LegacyCodeStyleSettings
|
||||
|
||||
myUnknownElementWriter.write(element, getCustomSettingsValues(), CustomCodeStyleSettings::getTagName, settings -> {
|
||||
CustomCodeStyleSettings parentCustomSettings = parentSettings.getCustomSettings(settings.getClass());
|
||||
if (parentCustomSettings == null) {
|
||||
throw new WriteExternalException("Custom settings are null for " + settings.getClass());
|
||||
}
|
||||
settings.writeExternal(element, parentCustomSettings);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,24 +1,9 @@
|
||||
/*
|
||||
* 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.util.config;
|
||||
|
||||
import com.intellij.openapi.util.Factory;
|
||||
import com.intellij.openapi.util.JDOMExternalizable;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
@@ -78,15 +63,10 @@ public interface Externalizer<T> {
|
||||
|
||||
@Override
|
||||
public void writeValue(Element dataElement, T value) {
|
||||
try {
|
||||
value.writeExternal(dataElement);
|
||||
}
|
||||
catch (WriteExternalException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
value.writeExternal(dataElement);
|
||||
}
|
||||
|
||||
public static <T extends JDOMExternalizable> FactoryBased<T> create(Factory<T> factory) {
|
||||
static <T extends JDOMExternalizable> FactoryBased<T> create(Factory<T> factory) {
|
||||
return new FactoryBased<>(factory);
|
||||
}
|
||||
}
|
||||
|
||||
+6
-11
@@ -232,17 +232,12 @@ public class CustomActionsSchema implements PersistentStateComponent<Element> {
|
||||
@Override
|
||||
public Element getState() {
|
||||
Element element = new Element("state");
|
||||
try {
|
||||
//noinspection deprecation
|
||||
DefaultJDOMExternalizer.writeExternal(this, element);
|
||||
for (ActionUrl group : myActions) {
|
||||
Element groupElement = new Element(GROUP);
|
||||
group.writeExternal(groupElement);
|
||||
element.addContent(groupElement);
|
||||
}
|
||||
}
|
||||
catch (WriteExternalException e) {
|
||||
throw new RuntimeException(e);
|
||||
//noinspection deprecation
|
||||
DefaultJDOMExternalizer.writeExternal(this, element);
|
||||
for (ActionUrl group : myActions) {
|
||||
Element groupElement = new Element(GROUP);
|
||||
group.writeExternal(groupElement);
|
||||
element.addContent(groupElement);
|
||||
}
|
||||
writeIcons(element);
|
||||
return element;
|
||||
|
||||
@@ -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.util;
|
||||
|
||||
/**
|
||||
@@ -31,8 +17,4 @@ public class WriteExternalException extends RuntimeException {
|
||||
public WriteExternalException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public WriteExternalException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -17,7 +17,6 @@ package com.siyeh.ig.ui;
|
||||
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.JDOMExternalizable;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.containers.OrderedSet;
|
||||
@@ -78,10 +77,11 @@ public class ExternalizableStringSet extends OrderedSet<String>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeExternal(Element element) throws WriteExternalException {
|
||||
public void writeExternal(Element element) {
|
||||
if (hasDefaultValues()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (String value : this) {
|
||||
if (value != null) {
|
||||
final Element item = new Element(ITEM);
|
||||
@@ -95,12 +95,12 @@ public class ExternalizableStringSet extends OrderedSet<String>
|
||||
* Write this ExternalizableStringSet to the specified element, with the specified name, if it has non-default values.
|
||||
* @param element the element to write to.
|
||||
* @param name the name of the option.
|
||||
* @throws WriteExternalException
|
||||
*/
|
||||
public void writeSettings(Element element, String name) throws WriteExternalException {
|
||||
public void writeSettings(Element element, String name) {
|
||||
if (hasDefaultValues()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Element optionElement = new Element("option").setAttribute("name", name);
|
||||
final Element valueElement = new Element("value");
|
||||
writeExternal(valueElement);
|
||||
|
||||
@@ -163,36 +163,30 @@ public class AntConfigurationImpl extends AntConfigurationBase implements Persis
|
||||
|
||||
@Override
|
||||
public Element getState() {
|
||||
try {
|
||||
final Element state = new Element("state");
|
||||
getProperties().writeExternal(state);
|
||||
ApplicationManager.getApplication().runReadAction(() -> {
|
||||
for (final AntBuildFileBase buildFile : myBuildFiles) {
|
||||
final Element element = new Element(BUILD_FILE);
|
||||
//noinspection ConstantConditions
|
||||
element.setAttribute(URL, buildFile.getVirtualFile().getUrl());
|
||||
buildFile.writeProperties(element);
|
||||
saveEvents(element, buildFile);
|
||||
state.addContent(element);
|
||||
}
|
||||
final Element state = new Element("state");
|
||||
getProperties().writeExternal(state);
|
||||
ApplicationManager.getApplication().runReadAction(() -> {
|
||||
for (final AntBuildFileBase buildFile : myBuildFiles) {
|
||||
final Element element = new Element(BUILD_FILE);
|
||||
//noinspection ConstantConditions
|
||||
element.setAttribute(URL, buildFile.getVirtualFile().getUrl());
|
||||
buildFile.writeProperties(element);
|
||||
saveEvents(element, buildFile);
|
||||
state.addContent(element);
|
||||
}
|
||||
|
||||
final List<VirtualFile> files = new ArrayList<>(myAntFileToContextFileMap.keySet());
|
||||
// sort in order to minimize changes
|
||||
Collections.sort(files, Comparator.comparing(VirtualFile::getUrl));
|
||||
for (VirtualFile file : files) {
|
||||
final Element element = new Element(CONTEXT_MAPPING);
|
||||
final VirtualFile contextFile = myAntFileToContextFileMap.get(file);
|
||||
element.setAttribute(URL, file.getUrl());
|
||||
element.setAttribute(CONTEXT, contextFile.getUrl());
|
||||
state.addContent(element);
|
||||
}
|
||||
});
|
||||
return state;
|
||||
}
|
||||
catch (WriteExternalException e) {
|
||||
LOG.error(e);
|
||||
return null;
|
||||
}
|
||||
final List<VirtualFile> files = new ArrayList<>(myAntFileToContextFileMap.keySet());
|
||||
// sort in order to minimize changes
|
||||
Collections.sort(files, Comparator.comparing(VirtualFile::getUrl));
|
||||
for (VirtualFile file : files) {
|
||||
final Element element = new Element(CONTEXT_MAPPING);
|
||||
final VirtualFile contextFile = myAntFileToContextFileMap.get(file);
|
||||
element.setAttribute(URL, file.getUrl());
|
||||
element.setAttribute(CONTEXT, contextFile.getUrl());
|
||||
state.addContent(element);
|
||||
}
|
||||
});
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -35,15 +35,9 @@ public class AntWorkspaceConfiguration implements PersistentStateComponent<Eleme
|
||||
}
|
||||
|
||||
public Element getState() {
|
||||
try {
|
||||
final Element e = new Element("state");
|
||||
writeExternal(e);
|
||||
return e;
|
||||
}
|
||||
catch (WriteExternalException e1) {
|
||||
LOG.error(e1);
|
||||
return null;
|
||||
}
|
||||
final Element e = new Element("state");
|
||||
writeExternal(e);
|
||||
return e;
|
||||
}
|
||||
|
||||
public void loadState(@NotNull Element state) {
|
||||
|
||||
Reference in New Issue
Block a user