Skip to content

Commit

Permalink
remove static field
Browse files Browse the repository at this point in the history
Signed-off-by: Shi Chen <[email protected]>
  • Loading branch information
CsCherrYY committed Mar 17, 2021
1 parent bfea5ca commit 704e50b
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public class FormatterManager {

private final static String FORMATTER_OPTION_PREFIX = JavaCore.PLUGIN_ID + ".formatter"; //$NON-NLS-1$

private static int version = 13; // Keep consistent with default formatter profile version

/**
* A SAX event handler to parse the xml format for profiles.
*/
Expand Down Expand Up @@ -95,7 +93,12 @@ public void startElement(String uri, String localName, String qName, Attributes
fKind = CODE_FORMATTER_PROFILE_KIND;
}
fSettings = new HashMap<>(200);
fVersion = Integer.parseInt(attributes.getValue(XML_ATTRIBUTE_VERSION));
try {
fVersion = Integer.parseInt(attributes.getValue(XML_ATTRIBUTE_VERSION));
} catch (NumberFormatException e) {
fVersion = ProfileVersionerCore.getCurrentVersion();
}

}
}
else if (qName.equals(XML_NODE_ROOT)) {
Expand Down Expand Up @@ -171,8 +174,11 @@ public static Map<String, String> readSettingsFromStream(InputSource inputSource
} catch (Exception e) {
throw new CoreException(new Status(IStatus.WARNING, IConstants.PLUGIN_ID, e.getMessage(), e));
}
FormatterManager.version = handler.getVersion();
return handler.getSettings();
int version = handler.getVersion();
if (version == ProfileVersionerCore.getCurrentVersion()) {
return handler.getSettings();
}
return ProfileVersionerCore.updateAndComplete(handler.getSettings(), version);
}

public static void configureFormatter(Preferences preferences) {
Expand All @@ -188,7 +194,6 @@ public static void configureFormatter(Preferences preferences) {
}
}
if (options != null && !options.isEmpty()) {
options = ProfileVersionerCore.updateAndComplete(options, FormatterManager.version);
setFormattingOptions(preferences, options);
} else {
Map<String, String> defaultOptions = DefaultCodeFormatterOptions.getEclipseDefaultSettings().getMap();
Expand Down

0 comments on commit 704e50b

Please sign in to comment.