use of org.antlr.intellij.plugin.parsing.RunANTLROnGrammarFile in project intellij-plugin-v4 by antlr.
the class GenerateParserAction method actionPerformed.
@Override
public void actionPerformed(final AnActionEvent e) {
Project project = e.getData(PlatformDataKeys.PROJECT);
if (project == null) {
LOG.error("actionPerformed no project for " + e);
// whoa!
return;
}
VirtualFile grammarFile = MyActionUtils.getGrammarFileFromEvent(e);
LOG.info("actionPerformed " + (grammarFile == null ? "NONE" : grammarFile));
if (grammarFile == null)
return;
String title = "ANTLR Code Generation";
boolean canBeCancelled = true;
// commit changes to PSI and file system
PsiDocumentManager psiMgr = PsiDocumentManager.getInstance(project);
FileDocumentManager docMgr = FileDocumentManager.getInstance();
Document doc = docMgr.getDocument(grammarFile);
if (doc == null)
return;
boolean unsaved = !psiMgr.isCommitted(doc) || docMgr.isDocumentUnsaved(doc);
if (unsaved) {
// save event triggers ANTLR run if autogen on
psiMgr.commitDocument(doc);
docMgr.saveDocument(doc);
}
// from action, they really mean it
boolean forceGeneration = true;
RunANTLROnGrammarFile gen = new RunANTLROnGrammarFile(grammarFile, project, title, canBeCancelled, forceGeneration);
boolean autogen = ANTLRv4GrammarPropertiesStore.getGrammarProperties(project, grammarFile).shouldAutoGenerateParser();
if (!unsaved || !autogen) {
// if everything already saved (not stale) then run ANTLR
// if had to be saved and autogen NOT on, then run ANTLR
// Otherwise, the save file event will have or will run ANTLR.
// , "Generating", canBeCancelled, e.getData(PlatformDataKeys.PROJECT));
ProgressManager.getInstance().run(gen);
// refresh from disk to see new files
Set<File> generatedFiles = new HashSet<>();
generatedFiles.add(new File(gen.getOutputDirName()));
LocalFileSystem.getInstance().refreshIoFiles(generatedFiles, true, true, null);
// pop up a notification
Notification notification = new Notification(RunANTLROnGrammarFile.groupDisplayId, "parser for " + grammarFile.getName() + " generated", "to " + gen.getOutputDirName(), NotificationType.INFORMATION);
Notifications.Bus.notify(notification, project);
}
}
use of org.antlr.intellij.plugin.parsing.RunANTLROnGrammarFile in project intellij-plugin-v4 by antlr.
the class ANTLRv4PluginController method runANTLRTool.
/**
* Make sure to run after updating grammars in previewState
*/
public void runANTLRTool(final VirtualFile grammarFile) {
String title = "ANTLR Code Generation";
boolean canBeCancelled = true;
boolean forceGeneration = false;
Task gen = new RunANTLROnGrammarFile(grammarFile, project, title, canBeCancelled, forceGeneration);
ProgressManager.getInstance().run(gen);
}
Aggregations