public void closeGrammar(VirtualFile grammarFile) {
    String grammarFileName = grammarFile.getPath();
    LOG.info("closeGrammar " + grammarFileName + " " + project.getName());

    inputPanel.resetStartRuleLabel();
    inputPanel.clearErrorConsole();
    clearParseTree(); // wipe tree

    ANTLRv4PluginController controller = ANTLRv4PluginController.getInstance(project);
    PreviewState previewState = controller.getPreviewState(grammarFile);
    inputPanel.releaseEditor(previewState);
  }
 public void ensureStartRuleExists(VirtualFile grammarFile) {
   PreviewState previewState =
       ANTLRv4PluginController.getInstance(project).getPreviewState(grammarFile);
   // if start rule no longer exists, reset display/state.
   if (previewState.g != ParsingUtils.BAD_PARSER_GRAMMAR && previewState.startRuleName != null) {
     Rule rule = previewState.g.getRule(previewState.startRuleName);
     if (rule == null) {
       previewState.startRuleName = null;
       inputPanel.resetStartRuleLabel();
     }
   }
 }