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);
}
}
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();
}
}
}
Aggregations