void (final PropertiesFile file) { final List<IProperty> properties = new ArrayList<>(file.getProperties()); properties.sort(Comparator.comparing(IProperty::getKey, String.CASE_INSENSITIVE_ORDER)); final PropertiesList propertiesList = PsiTreeUtil.findChildOfType(file.getContainingFile(), PropertiesList.class); if (propertiesList == null) return; final char delimiter = PropertiesCodeStyleSettings.getInstance(file.getProject()).getDelimiter(); final StringBuilder rawText = new StringBuilder(propertiesList.getDocCommentText()); for (int i = 0; i < properties.size(); i++) { IProperty property = properties.get(i); final String value = property.getValue(); final String commentAboveProperty = property.getDocCommentText(); if (commentAboveProperty != null) { rawText.append(commentAboveProperty); } final String key = property.getKey(); final String propertyText; if (key != null) { propertyText = PropertiesElementFactory.getPropertyText(key, value != null ? value : "", delimiter, null, PropertyKeyValueFormat.FILE); rawText.append(propertyText); if (i != properties.size() - 1) { rawText.append("\n"); } } } final PropertiesFile fakeFile = PropertiesElementFactory.createPropertiesFile(file.getProject(), rawText.toString()); final PropertiesList fakePropertiesList = PsiTreeUtil.findChildOfType(fakeFile.getContainingFile(), PropertiesList.class); LOG.assertTrue(fakePropertiesList != null); propertiesList.replace(fakePropertiesList); }