@Override public void writeState( @NotNull FileEditorState state, @NotNull Project project, @NotNull Element targetElement) { if (!(state instanceof MPSEditorStateWrapper)) return; MPSEditorStateWrapper wrapper = (MPSEditorStateWrapper) state; EditorState editorState = wrapper.getEditorState(); targetElement.setAttribute(CLASS, editorState.getClass().getName()); editorState.save(targetElement); }
@Override @NotNull public FileEditorState readState( @NotNull Element sourceElement, @NotNull Project project, @NotNull VirtualFile file) { String className = sourceElement.getAttributeValue(CLASS); if (className == null) return FileEditorState.INSTANCE; try { Class cls = Class.forName(className); EditorState instance = (EditorState) cls.newInstance(); instance.load(sourceElement); MPSEditorStateWrapper result = new MPSEditorStateWrapper(); result.setEditorState(instance); return result; } catch (ClassNotFoundException e) { // do nothing - class is not there anymore } catch (Throwable t) { LOG.error(null, t); } return FileEditorState.INSTANCE; }