/** Restores the code folding state information from the given memento. */ public void restoreCodeFolding(org.eclipse.ui.IMemento memento) { if (memento == null) { return; } org.eclipse.ui.IMemento[] annotationMementos = memento.getChildren(ANNOTATION); if (annotationMementos == null) { return; } java.util.Map<org.eclipse.jface.text.source.projection.ProjectionAnnotation, Boolean> collapsedStates = new java.util.LinkedHashMap< org.eclipse.jface.text.source.projection.ProjectionAnnotation, Boolean>(); for (org.eclipse.ui.IMemento annotationMemento : annotationMementos) { org.eclipse.jface.text.source.projection.ProjectionAnnotation annotation = new org.eclipse.jface.text.source.projection.ProjectionAnnotation(); collapsedStates.put(annotation, annotationMemento.getBoolean(IS_COLLAPSED)); int offset = annotationMemento.getInteger(OFFSET); int length = annotationMemento.getInteger(LENGTH); org.eclipse.jface.text.Position position = new org.eclipse.jface.text.Position(offset, length); projectionAnnotationModel.addAnnotation(annotation, position); } // postset collapse state to prevent wrong displaying folding code. for (org.eclipse.jface.text.source.projection.ProjectionAnnotation annotation : collapsedStates.keySet()) { Boolean isCollapsed = collapsedStates.get(annotation); if (isCollapsed != null && isCollapsed.booleanValue()) { projectionAnnotationModel.collapse(annotation); } } }