Simplify AbstractDOMConverter.

* Set.of() instead of static block to initialize set
* Enable save actions to automate cleanup of the codebase.

Change-Id: Ib8365b4c3c989065346167a9415aa6c1d88f782b
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
diff --git a/bundles/org.eclipse.releng.build.tools.convert/.settings/org.eclipse.jdt.ui.prefs b/bundles/org.eclipse.releng.build.tools.convert/.settings/org.eclipse.jdt.ui.prefs
index 55edce7..4f8d0e0 100644
--- a/bundles/org.eclipse.releng.build.tools.convert/.settings/org.eclipse.jdt.ui.prefs
+++ b/bundles/org.eclipse.releng.build.tools.convert/.settings/org.eclipse.jdt.ui.prefs
@@ -52,6 +52,7 @@
 cleanup_profile=_Eclipse Releng
 cleanup_settings_version=2
 eclipse.preferences.version=1
+editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
 formatter_profile=org.eclipse.jdt.ui.default.eclipse_profile
 formatter_settings_version=19
 org.eclipse.jdt.ui.exception.name=e
@@ -64,3 +65,71 @@
 org.eclipse.jdt.ui.overrideannotation=true
 org.eclipse.jdt.ui.staticondemandthreshold=99
 org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return the ${bare_field_name}\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} the ${bare_field_name} to set\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/**\n * \n */</template><template autoinsert\="true" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * @author ${user}\n *\n * ${tags}\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n * \n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Javadoc)\n * ${see_to_overridden}\n */</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * ${tags}\n * ${see_to_target}\n */</template><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template><template autoinsert\="true" context\="modulecomment_context" deleted\="false" description\="Comment for modules" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.modulecomment" name\="modulecomment">/**\n * @author ${user}\n *\n * ${tags}\n */</template><template autoinsert\="true" context\="recordbody_context" deleted\="false" description\="Code in new record type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.recordbody" name\="recordbody">\n</template></templates>
+sp_cleanup.add_default_serial_version_id=true
+sp_cleanup.add_generated_serial_version_id=false
+sp_cleanup.add_missing_annotations=true
+sp_cleanup.add_missing_deprecated_annotations=true
+sp_cleanup.add_missing_methods=false
+sp_cleanup.add_missing_nls_tags=false
+sp_cleanup.add_missing_override_annotations=true
+sp_cleanup.add_missing_override_annotations_interface_methods=true
+sp_cleanup.add_serial_version_id=false
+sp_cleanup.always_use_blocks=true
+sp_cleanup.always_use_parentheses_in_expressions=false
+sp_cleanup.always_use_this_for_non_static_field_access=false
+sp_cleanup.always_use_this_for_non_static_method_access=false
+sp_cleanup.convert_functional_interfaces=true
+sp_cleanup.convert_to_enhanced_for_loop=true
+sp_cleanup.correct_indentation=false
+sp_cleanup.format_source_code=true
+sp_cleanup.format_source_code_changes_only=true
+sp_cleanup.insert_inferred_type_arguments=false
+sp_cleanup.lazy_logical_operator=false
+sp_cleanup.make_local_variable_final=true
+sp_cleanup.make_parameters_final=false
+sp_cleanup.make_private_fields_final=true
+sp_cleanup.make_type_abstract_if_missing_method=false
+sp_cleanup.make_variable_declarations_final=false
+sp_cleanup.never_use_blocks=false
+sp_cleanup.never_use_parentheses_in_expressions=true
+sp_cleanup.number_suffix=false
+sp_cleanup.on_save_use_additional_actions=true
+sp_cleanup.organize_imports=true
+sp_cleanup.push_down_negation=false
+sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
+sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
+sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
+sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
+sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
+sp_cleanup.remove_private_constructors=true
+sp_cleanup.remove_redundant_modifiers=true
+sp_cleanup.remove_redundant_semicolons=true
+sp_cleanup.remove_redundant_type_arguments=true
+sp_cleanup.remove_trailing_whitespaces=true
+sp_cleanup.remove_trailing_whitespaces_all=true
+sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
+sp_cleanup.remove_unnecessary_array_creation=true
+sp_cleanup.remove_unnecessary_casts=true
+sp_cleanup.remove_unnecessary_nls_tags=true
+sp_cleanup.remove_unused_imports=false
+sp_cleanup.remove_unused_local_variables=false
+sp_cleanup.remove_unused_private_fields=true
+sp_cleanup.remove_unused_private_members=false
+sp_cleanup.remove_unused_private_methods=true
+sp_cleanup.remove_unused_private_types=true
+sp_cleanup.simplify_lambda_expression_and_method_ref=true
+sp_cleanup.sort_members=false
+sp_cleanup.sort_members_all=false
+sp_cleanup.use_anonymous_class_creation=false
+sp_cleanup.use_autoboxing=false
+sp_cleanup.use_blocks=false
+sp_cleanup.use_blocks_only_for_return_and_throw=false
+sp_cleanup.use_directly_map_method=true
+sp_cleanup.use_lambda=true
+sp_cleanup.use_parentheses_in_expressions=false
+sp_cleanup.use_this_for_non_static_field_access=false
+sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
+sp_cleanup.use_this_for_non_static_method_access=false
+sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
+sp_cleanup.use_unboxing=false
+sp_cleanup.use_var=false
diff --git a/bundles/org.eclipse.releng.build.tools.convert/src/org/eclipse/releng/build/tools/convert/dom/AbstractDOMConverter.java b/bundles/org.eclipse.releng.build.tools.convert/src/org/eclipse/releng/build/tools/convert/dom/AbstractDOMConverter.java
index b64f9a7..06621e3 100644
--- a/bundles/org.eclipse.releng.build.tools.convert/src/org/eclipse/releng/build/tools/convert/dom/AbstractDOMConverter.java
+++ b/bundles/org.eclipse.releng.build.tools.convert/src/org/eclipse/releng/build/tools/convert/dom/AbstractDOMConverter.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2006, 2018 IBM Corporation and others. 
+ * Copyright (c) 2006, 2020 IBM Corporation and others. 
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -17,24 +17,17 @@
 import java.io.Writer;
 import java.text.ChoiceFormat;
 import java.text.MessageFormat;
-import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 
 import org.eclipse.releng.build.tools.convert.ant.Converter;
 import org.eclipse.releng.build.tools.convert.ant.Messages;
 
 public abstract class AbstractDOMConverter implements IDOMConverter {
 
-    public static final HashSet<String> FILTERED_WARNINGS_IDS;
-
     public static final String  FORBIDDEN_REFERENCE   = "ForbiddenReference";  //$NON-NLS-1$
     public static final String  DISCOURAGED_REFERENCE = "DiscouragedReference"; //$NON-NLS-1$
-
-    static {
-        FILTERED_WARNINGS_IDS = new HashSet<>();
-        FILTERED_WARNINGS_IDS.add(FORBIDDEN_REFERENCE);
-        FILTERED_WARNINGS_IDS.add(DISCOURAGED_REFERENCE);
-    }
+    public static final Set<String> FILTERED_WARNINGS_IDS = Set.of(FORBIDDEN_REFERENCE, FORBIDDEN_REFERENCE);
 
     protected Messages          messages;
 
@@ -85,15 +78,15 @@
                 writer.write(messages.getString("header")); //$NON-NLS-1$
             } else {
                 final String pattern = messages.getString("dom_header"); //$NON-NLS-1$
-                writer.write(MessageFormat.format(pattern,
-                        new Object[] { pluginName, extractXmlFileName(options.get(Converter.INPUT_SOURCE)) }));
+                writer.write(MessageFormat.format(pattern, pluginName, extractXmlFileName(options.get(Converter.INPUT_SOURCE))));
             }
             final ProblemSummaryNode problemSummaryNode = summaryNode;
             writeTopAnchor(writer);
             String pattern = messages.getString("problem.summary"); //$NON-NLS-1$
-            writer.write(MessageFormat.format(pattern, new Object[] { Integer.toString(problemSummaryNode.numberOfProblems),
-                    Integer.toString(problemSummaryNode.numberOfErrors), Integer.toString(problemSummaryNode.numberOfWarnings), 
-                    Integer.toString(problemSummaryNode.numberOfInfos)}));
+            writer.write(MessageFormat.format(pattern, Integer.toString(problemSummaryNode.numberOfProblems),
+					Integer.toString(problemSummaryNode.numberOfErrors),
+					Integer.toString(problemSummaryNode.numberOfWarnings),
+					Integer.toString(problemSummaryNode.numberOfInfos)));
 
             writeAnchorsReferences(writer);
             final ProblemsNode[] problemsNodes = documentNode.getProblems();
@@ -102,8 +95,7 @@
             writeErrorAnchor(writer);
             writeAnchorsReferencesErrors(writer);
             // dump errors
-            for (int i = 0, max = problemsNodes.length; i < max; i++) {
-                final ProblemsNode problemsNode = problemsNodes[i];
+            for (final ProblemsNode problemsNode : problemsNodes) {
                 final ProblemNode[] problemNodes = problemsNode.getErrors();
                 final int length = problemNodes.length;
                 if (length == 0) {
@@ -129,14 +121,12 @@
                         pattern = messages.getString("errors.entry.even"); //$NON-NLS-1$
                     }
                     problemNode.setSources();
-                    writer.write(MessageFormat.format(
-                            pattern,
-                            new Object[] { sourceFileName, Integer.toString(globalErrorNumber), Integer.toString(j + 1),
-                                    problemNode.id, Integer.toString(problemNode.line), convertToHTML(problemNode.message),
-                                    convertToHTML(problemNode.sourceCodeBefore), convertToHTML(problemNode.sourceCode),
-                                    convertToHTML(problemNode.sourceCodeAfter),
-                                    getUnderLine(problemNode.sourceCodeBefore, problemNode.sourceCodeAfter),
-                                    Integer.toString(problemNode.charStart), Integer.toString(problemNode.charEnd), }));
+                    writer.write(MessageFormat.format(pattern, sourceFileName, Integer.toString(globalErrorNumber),
+							Integer.toString(j + 1), problemNode.id, Integer.toString(problemNode.line),
+							convertToHTML(problemNode.message), convertToHTML(problemNode.sourceCodeBefore),
+							convertToHTML(problemNode.sourceCode), convertToHTML(problemNode.sourceCodeAfter),
+							getUnderLine(problemNode.sourceCodeBefore, problemNode.sourceCodeAfter),
+							Integer.toString(problemNode.charStart), Integer.toString(problemNode.charEnd)));
                     globalErrorNumber++;
                 }
                 writer.write(messages.getString("errors.footer")); //$NON-NLS-1$
@@ -145,8 +135,7 @@
             writeOtherWarningsAnchor(writer);
             writeAnchorsReferencesOtherWarnings(writer);
             // dump other warnings
-            for (int i = 0, max = problemsNodes.length; i < max; i++) {
-                final ProblemsNode problemsNode = problemsNodes[i];
+            for (final ProblemsNode problemsNode : problemsNodes) {
                 final ProblemNode[] problemNodes = problemsNode.getOtherWarnings();
                 final int length = problemNodes.length;
                 if (length == 0) {
@@ -172,14 +161,12 @@
                         pattern = messages.getString("warnings.entry.even"); //$NON-NLS-1$
                     }
                     problemNode.setSources();
-                    writer.write(MessageFormat.format(
-                            pattern,
-                            new Object[] { sourceFileName, Integer.toString(globalErrorNumber), Integer.toString(j + 1),
-                                    problemNode.id, Integer.toString(problemNode.line), convertToHTML(problemNode.message),
-                                    convertToHTML(problemNode.sourceCodeBefore), convertToHTML(problemNode.sourceCode),
-                                    convertToHTML(problemNode.sourceCodeAfter),
-                                    getUnderLine(problemNode.sourceCodeBefore, problemNode.sourceCodeAfter),
-                                    Integer.toString(problemNode.charStart), Integer.toString(problemNode.charEnd), }));
+                    writer.write(MessageFormat.format(pattern, sourceFileName, Integer.toString(globalErrorNumber),
+							Integer.toString(j + 1), problemNode.id, Integer.toString(problemNode.line),
+							convertToHTML(problemNode.message), convertToHTML(problemNode.sourceCodeBefore),
+							convertToHTML(problemNode.sourceCode), convertToHTML(problemNode.sourceCodeAfter),
+							getUnderLine(problemNode.sourceCodeBefore, problemNode.sourceCodeAfter),
+							Integer.toString(problemNode.charStart), Integer.toString(problemNode.charEnd)));
                     globalErrorNumber++;
                 }
                 writer.write(messages.getString("other_warnings.footer")); //$NON-NLS-1$
@@ -188,8 +175,7 @@
             // dump infos
             writeInfosAnchor(writer);
             writeAnchorsReferencesInfos(writer);
-            for (int i = 0, max = problemsNodes.length; i < max; i++) {
-                final ProblemsNode problemsNode = problemsNodes[i];
+            for (final ProblemsNode problemsNode : problemsNodes) {
                 final ProblemNode[] problemNodes = problemsNode.getInfos();
                 final int length = problemNodes.length;
                 if (length == 0) {
@@ -215,14 +201,12 @@
                         pattern = messages.getString("infos.entry.even"); //$NON-NLS-1$
                     }
                     problemNode.setSources();
-                    writer.write(MessageFormat.format(
-                            pattern,
-                            new Object[] { sourceFileName, Integer.toString(globalErrorNumber), Integer.toString(j + 1),
-                                    problemNode.id, Integer.toString(problemNode.line), convertToHTML(problemNode.message),
-                                    convertToHTML(problemNode.sourceCodeBefore), convertToHTML(problemNode.sourceCode),
-                                    convertToHTML(problemNode.sourceCodeAfter),
-                                    getUnderLine(problemNode.sourceCodeBefore, problemNode.sourceCodeAfter),
-                                    Integer.toString(problemNode.charStart), Integer.toString(problemNode.charEnd), }));
+                    writer.write(MessageFormat.format(pattern, sourceFileName, Integer.toString(globalErrorNumber),
+							Integer.toString(j + 1), problemNode.id, Integer.toString(problemNode.line),
+							convertToHTML(problemNode.message), convertToHTML(problemNode.sourceCodeBefore),
+							convertToHTML(problemNode.sourceCode), convertToHTML(problemNode.sourceCodeAfter),
+							getUnderLine(problemNode.sourceCodeBefore, problemNode.sourceCodeAfter),
+							Integer.toString(problemNode.charStart), Integer.toString(problemNode.charEnd)));
                     globalErrorNumber++;
                 }
                 writer.write(messages.getString("infos.footer")); //$NON-NLS-1$
@@ -231,8 +215,7 @@
             // dump forbidden accesses warnings
             writeForbiddenRulesWarningsAnchor(writer);
             writeAnchorsReferencesForbiddenRulesWarnings(writer);
-            for (int i = 0, max = problemsNodes.length; i < max; i++) {
-                final ProblemsNode problemsNode = problemsNodes[i];
+            for (final ProblemsNode problemsNode : problemsNodes) {
                 final ProblemNode[] problemNodes = problemsNode.getForbiddenWarnings();
                 final int length = problemNodes.length;
                 if (length == 0) {
@@ -258,14 +241,12 @@
                         pattern = messages.getString("warnings.entry.even"); //$NON-NLS-1$
                     }
                     problemNode.setSources();
-                    writer.write(MessageFormat.format(
-                            pattern,
-                            new Object[] { sourceFileName, Integer.toString(globalErrorNumber), Integer.toString(j + 1),
-                                    problemNode.id, Integer.toString(problemNode.line), convertToHTML(problemNode.message),
-                                    convertToHTML(problemNode.sourceCodeBefore), convertToHTML(problemNode.sourceCode),
-                                    convertToHTML(problemNode.sourceCodeAfter),
-                                    getUnderLine(problemNode.sourceCodeBefore, problemNode.sourceCodeAfter),
-                                    Integer.toString(problemNode.charStart), Integer.toString(problemNode.charEnd), }));
+                    writer.write(MessageFormat.format(pattern, sourceFileName, Integer.toString(globalErrorNumber),
+							Integer.toString(j + 1), problemNode.id, Integer.toString(problemNode.line),
+							convertToHTML(problemNode.message), convertToHTML(problemNode.sourceCodeBefore),
+							convertToHTML(problemNode.sourceCode), convertToHTML(problemNode.sourceCodeAfter),
+							getUnderLine(problemNode.sourceCodeBefore, problemNode.sourceCodeAfter),
+							Integer.toString(problemNode.charStart), Integer.toString(problemNode.charEnd)));
                     globalErrorNumber++;
                 }
                 writer.write(messages.getString("forbidden_warnings.footer")); //$NON-NLS-1$
@@ -274,8 +255,7 @@
             // dump discouraged accesses warnings
             writeDiscouragedRulesWarningsAnchor(writer);
             writeAnchorsReferencesDiscouragedRulesWarnings(writer);
-            for (int i = 0, max = problemsNodes.length; i < max; i++) {
-                final ProblemsNode problemsNode = problemsNodes[i];
+            for (final ProblemsNode problemsNode : problemsNodes) {
                 final ProblemNode[] problemNodes = problemsNode.getDiscouragedWarnings();
                 final int length = problemNodes.length;
                 if (length == 0) {
@@ -301,14 +281,12 @@
                         pattern = messages.getString("warnings.entry.even"); //$NON-NLS-1$
                     }
                     problemNode.setSources();
-                    writer.write(MessageFormat.format(
-                            pattern,
-                            new Object[] { sourceFileName, Integer.toString(globalErrorNumber), Integer.toString(j + 1),
-                                    problemNode.id, Integer.toString(problemNode.line), convertToHTML(problemNode.message),
-                                    convertToHTML(problemNode.sourceCodeBefore), convertToHTML(problemNode.sourceCode),
-                                    convertToHTML(problemNode.sourceCodeAfter),
-                                    getUnderLine(problemNode.sourceCodeBefore, problemNode.sourceCodeAfter),
-                                    Integer.toString(problemNode.charStart), Integer.toString(problemNode.charEnd), }));
+                    writer.write(MessageFormat.format(pattern, sourceFileName, Integer.toString(globalErrorNumber),
+							Integer.toString(j + 1), problemNode.id, Integer.toString(problemNode.line),
+							convertToHTML(problemNode.message), convertToHTML(problemNode.sourceCodeBefore),
+							convertToHTML(problemNode.sourceCode), convertToHTML(problemNode.sourceCodeAfter),
+							getUnderLine(problemNode.sourceCodeBefore, problemNode.sourceCodeAfter),
+							Integer.toString(problemNode.charStart), Integer.toString(problemNode.charEnd)));
                     globalErrorNumber++;
                 }
                 writer.write(messages.getString("discouraged_warnings.footer")); //$NON-NLS-1$