Source:
<code>public void write(ModuleDetails moduleDetails) throws TransformerException, ParserConfigurationException { final DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); final DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); final Document doc = dBuilder.newDocument(); final Element rootElement = doc.createElement("checkstyle-metadata"); final Element rootChild = doc.createElement("module"); rootElement.appendChild(rootChild); doc.appendChild(rootElement); Element checkModule = null; final ModuleType moduleType = moduleDetails.getModuleType(); if (moduleType == ModuleType.CHECK) { checkModule = doc.createElement("check"); } else if (moduleType == ModuleType.FILTER) { checkModule = doc.createElement("filter"); } else if (moduleType == ModuleType.FILEFILTER) { checkModule = doc.createElement("file-filter"); <START> } <END> rootChild.appendChild(checkModule); checkModule.setAttribute("name", moduleDetails.getName()); checkModule.setAttribute("fully-qualified-name", moduleDetails.getFullQualifiedName()); checkModule.setAttribute("parent", moduleDetails.getParent()); final Element desc = doc.createElement("description"); final Node cdataDesc = doc.createCDATASection(moduleDetails.getDescription()); desc.appendChild(cdataDesc); checkModule.appendChild(desc); createPropertySection(moduleDetails, checkModule, doc); if (!moduleDetails.getViolationMessageKeys().isEmpty()) { final Element messageKeys = doc.createElement("message-keys"); for (String msg : moduleDetails.getViolationMessageKeys()) { final Element messageKey = doc.createElement("message-key"); messageKey.setAttribute("key", msg); messageKeys.appendChild(messageKey); } checkModule.appendChild(messageKeys); } writeToFile(doc, moduleDetails); }</code><technical_language>instead of repeating if blocks, add field in enum doc.createElement(moduleType.getElementName());</technical_language>

Target:
public static void write(ModuleDetails moduleDetails) throws TransformerException, ParserConfigurationException { final DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); final DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); final Document doc = dBuilder.newDocument(); final Element rootElement = doc.createElement("checkstyle-metadata"); final Element rootChild = doc.createElement("module"); rootElement.appendChild(rootChild); doc.appendChild(rootElement); final Element checkModule = doc.createElement(moduleDetails.getModuleType().getLabel()); rootChild.appendChild(checkModule); checkModule.setAttribute("name", moduleDetails.getName()); checkModule.setAttribute("fully-qualified-name", moduleDetails.getFullQualifiedName()); checkModule.setAttribute("parent", moduleDetails.getParent()); final Element desc = doc.createElement("description"); final Node cdataDesc = doc.createCDATASection(moduleDetails.getDescription()); desc.appendChild(cdataDesc); checkModule.appendChild(desc); createPropertySection(moduleDetails, checkModule, doc); if (!moduleDetails.getViolationMessageKeys().isEmpty()) { final Element messageKeys = doc.createElement("message-keys"); for (String msg : moduleDetails.getViolationMessageKeys()) { final Element messageKey = doc.createElement("message-key"); messageKey.setAttribute("key", msg); messageKeys.appendChild(messageKey); } checkModule.appendChild(messageKeys); } writeToFile(doc, moduleDetails); }