Search in sources :

Example 1 with IntentionManagerImpl

use of com.intellij.codeInsight.intention.impl.config.IntentionManagerImpl in project intellij-community by JetBrains.

the class IntentionDump method main.

@Override
public void main(String[] args) {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    try {
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document document = builder.newDocument();
        Element intentions = document.createElement("Intentions");
        document.appendChild(intentions);
        while (((IntentionManagerImpl) IntentionManager.getInstance()).hasActiveRequests()) {
            TimeoutUtil.sleep(100);
        }
        for (IntentionActionMetaData actionMetaData : IntentionManagerSettings.getInstance().getMetaData()) {
            Element intention = document.createElement("Intention");
            intention.setAttribute("categories", StringUtil.join(actionMetaData.myCategory, ","));
            intention.setAttribute("name", actionMetaData.getFamily());
            Element description = document.createElement("description");
            CDATASection descriptionSection = document.createCDATASection(escapeCDATA(actionMetaData.getDescription().getText()));
            description.appendChild(descriptionSection);
            intention.appendChild(description);
            TextDescriptor[] beforeDescriptors = actionMetaData.getExampleUsagesBefore();
            if (beforeDescriptors.length > 0) {
                Element before = document.createElement("before");
                CDATASection beforeSection = document.createCDATASection(escapeCDATA(beforeDescriptors[0].getText()));
                before.appendChild(beforeSection);
                intention.appendChild(before);
            }
            TextDescriptor[] afterDescriptors = actionMetaData.getExampleUsagesAfter();
            if (afterDescriptors.length > 0) {
                Element after = document.createElement("after");
                CDATASection afterSection = document.createCDATASection(escapeCDATA(afterDescriptors[0].getText()));
                after.appendChild(afterSection);
                intention.appendChild(after);
            }
            intentions.appendChild(intention);
        }
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        DOMSource source = new DOMSource(document);
        final String path = args.length == 2 ? args[1] : PathManager.getHomePath() + File.separator + "AllIntentions.xml";
        StreamResult console = new StreamResult(new File(path));
        transformer.transform(source, console);
        System.exit(0);
    } catch (ParserConfigurationException | IOException | TransformerException e) {
        // noinspection CallToPrintStackTrace
        e.printStackTrace();
        System.exit(1);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) Element(org.w3c.dom.Element) TextDescriptor(com.intellij.codeInsight.intention.impl.config.TextDescriptor) IOException(java.io.IOException) Document(org.w3c.dom.Document) IntentionManagerImpl(com.intellij.codeInsight.intention.impl.config.IntentionManagerImpl) CDATASection(org.w3c.dom.CDATASection) DocumentBuilder(javax.xml.parsers.DocumentBuilder) IntentionActionMetaData(com.intellij.codeInsight.intention.impl.config.IntentionActionMetaData) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File) TransformerException(javax.xml.transform.TransformerException)

Aggregations

IntentionActionMetaData (com.intellij.codeInsight.intention.impl.config.IntentionActionMetaData)1 IntentionManagerImpl (com.intellij.codeInsight.intention.impl.config.IntentionManagerImpl)1 TextDescriptor (com.intellij.codeInsight.intention.impl.config.TextDescriptor)1 File (java.io.File)1 IOException (java.io.IOException)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 Transformer (javax.xml.transform.Transformer)1 TransformerException (javax.xml.transform.TransformerException)1 DOMSource (javax.xml.transform.dom.DOMSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1 CDATASection (org.w3c.dom.CDATASection)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1