Element () { final Element state = new Element("state"); getProperties().writeExternal(state); ReadAction.run(() -> { 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; synchronized (myAntFileToContextFileMap) { files = new ArrayList<>(myAntFileToContextFileMap.keySet()); } // sort in order to minimize changes files.sort(Comparator.comparing(VirtualFile::getUrl)); for (VirtualFile file : files) { final Element element = new Element(CONTEXT_MAPPING); element.setAttribute(URL, file.getUrl()); final VirtualFile contextFile = myAntFileToContextFileMap.get(file); if (contextFile != null) { element.setAttribute(CONTEXT, contextFile.getUrl()); } state.addContent(element); } }); return state; }