Search in sources :

Example 1 with IntentionActionMetaData

use of com.intellij.codeInsight.intention.impl.config.IntentionActionMetaData 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)

Example 2 with IntentionActionMetaData

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

the class DumpIntentionsAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final VirtualFile file = FileChooser.chooseFile(FileChooserDescriptorFactory.createSingleFolderDescriptor(), e.getData(CommonDataKeys.PROJECT), null);
    if (file != null) {
        final List<IntentionActionMetaData> list = IntentionManagerSettings.getInstance().getMetaData();
        final File root = VfsUtilCore.virtualToIoFile(file);
        Element el = new Element("root");
        Map<String, Element> categoryMap = new HashMap<>();
        for (IntentionActionMetaData metaData : list) {
            try {
                Element metadataElement = new Element("intention");
                metadataElement.setAttribute("family", metaData.getFamily());
                metadataElement.setAttribute("description", metaData.getDescription().getText());
                String key = StringUtil.join(metaData.myCategory, ".");
                Element element = getCategoryElement(categoryMap, el, metaData, key, metaData.myCategory.length - 1);
                element.addContent(metadataElement);
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
        try {
            JdomKt.write(el, root.toPath().resolve("intentions.xml"));
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashMap(java.util.HashMap) Element(org.jdom.Element) IntentionActionMetaData(com.intellij.codeInsight.intention.impl.config.IntentionActionMetaData) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

IntentionActionMetaData (com.intellij.codeInsight.intention.impl.config.IntentionActionMetaData)2 File (java.io.File)2 IOException (java.io.IOException)2 IntentionManagerImpl (com.intellij.codeInsight.intention.impl.config.IntentionManagerImpl)1 TextDescriptor (com.intellij.codeInsight.intention.impl.config.TextDescriptor)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 HashMap (java.util.HashMap)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 Element (org.jdom.Element)1 CDATASection (org.w3c.dom.CDATASection)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1