diff --git a/plugins/properties/properties-psi-api/src/com/intellij/lang/properties/psi/PropertiesElementFactory.java b/plugins/properties/properties-psi-api/src/com/intellij/lang/properties/psi/PropertiesElementFactory.java index ebafb102010d..a3959081a7a7 100644 --- a/plugins/properties/properties-psi-api/src/com/intellij/lang/properties/psi/PropertiesElementFactory.java +++ b/plugins/properties/properties-psi-api/src/com/intellij/lang/properties/psi/PropertiesElementFactory.java @@ -44,7 +44,7 @@ public class PropertiesElementFactory { @NotNull public static IProperty createProperty(@NotNull Project project, @NonNls @NotNull String name, @NonNls @NotNull String value) { - String text = getPropertyText(name, value, null, project); + String text = getPropertyText(name, value, null, project, true); final PropertiesFile dummyFile = createPropertiesFile(project, text); return dummyFile.getProperties().get(0); } @@ -53,11 +53,12 @@ public class PropertiesElementFactory { public static String getPropertyText(@NonNls @NotNull String name, @NonNls @NotNull String value, @NonNls @Nullable Character delimiter, - @Nullable Project project) { + @Nullable Project project, + boolean escape) { if (delimiter == null) { delimiter = project == null ? PropertiesCodeStyleSettings.DEFAULT_KEY_VALUE_DELIMITER : PropertiesCodeStyleSettings.getInstance(project).KEY_VALUE_DELIMITER; } - return escape(name) + String.valueOf(delimiter) + escapeValue(value); + return (escape ? escape(name) : name) + String.valueOf(delimiter) + (escape ? escapeValue(value) : value); } @NotNull @@ -88,34 +89,13 @@ public class PropertiesElementFactory { @NotNull private static String escape(@NotNull String name) { - if (StringUtil.startsWithChar(name, '#')) { - name = escapeChar(name, '#'); - } - if (StringUtil.startsWithChar(name, '!')) { - name = escapeChar(name, '!'); - } - name = escapeChar(name, '='); - name = escapeChar(name, ':'); - name = escapeChar(name, ' '); - name = escapeChar(name, '\t'); - return name; - } - - @NotNull - private static String escapeChar(@NotNull String name, char c) { - int offset = 0; - while (true) { - int i = name.indexOf(c, offset); - if (i == -1) return name; - if (i == 0 || name.charAt(i - 1) != '\\') { - name = name.substring(0, i) + '\\' + name.substring(i); - } - offset = i + 2; + if (StringUtil.startsWithChar(name, '#') || StringUtil.startsWithChar(name, '!')) { + name = "\\" + name; } + return StringUtil.escapeChars(name, '=', ':', ' ', '\t'); } public static String escapeValue(String value) { return PropertiesResourceBundleUtil.fromValueEditorToPropertyValue(value); } - } diff --git a/plugins/properties/properties-psi-impl/src/com/intellij/codeInspection/unsorted/AlphaUnsortedPropertiesFileInspection.java b/plugins/properties/properties-psi-impl/src/com/intellij/codeInspection/unsorted/AlphaUnsortedPropertiesFileInspection.java index d115c9cc88a0..d8a2898c876a 100644 --- a/plugins/properties/properties-psi-impl/src/com/intellij/codeInspection/unsorted/AlphaUnsortedPropertiesFileInspection.java +++ b/plugins/properties/properties-psi-impl/src/com/intellij/codeInspection/unsorted/AlphaUnsortedPropertiesFileInspection.java @@ -132,8 +132,10 @@ public class AlphaUnsortedPropertiesFileInspection extends LocalInspectionTool { final StringBuilder rawText = new StringBuilder(); for (int i = 0; i < properties.size(); i++) { IProperty property = properties.get(i); - final String value = property.getUnescapedValue(); - rawText.append(PropertiesElementFactory.getPropertyText(property.getKey(), value != null ? value : "", delimiter, null)); + final String value = property.getValue(); + final String propertyText = + PropertiesElementFactory.getPropertyText(property.getKey(), value != null ? value : "", delimiter, null, false); + rawText.append(propertyText); if (i != properties.size() - 1) { rawText.append("\n"); }