예제 #1
0
  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);
  }
예제 #2
0
  public void createGUI() {
    this.setLayout(new BorderLayout());

    // Had to set min size / preferred size in InputPanel.form to get slider to allow left shift of
    // divider
    Splitter splitPane = new Splitter();
    inputPanel = getEditorPanel();
    splitPane.setFirstComponent(inputPanel.getComponent());
    splitPane.setSecondComponent(createParseTreeAndProfileTabbedPanel());

    this.add(splitPane, BorderLayout.CENTER);
  }
예제 #3
0
 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();
     }
   }
 }
예제 #4
0
  /** Notify the preview tool window contents that the grammar file has changed */
  public void grammarFileSaved(VirtualFile grammarFile) {
    String grammarFileName = grammarFile.getPath();
    LOG.info("grammarFileSaved " + grammarFileName + " " + project.getName());
    ANTLRv4PluginController controller = ANTLRv4PluginController.getInstance(project);
    PreviewState previewState = controller.getPreviewState(grammarFile);

    ensureStartRuleExists(grammarFile);
    inputPanel.grammarFileSaved(grammarFile);

    // if the saved grammar is not a pure lexer and there is a start rule, reparse
    // means that switching grammars must refresh preview
    if (previewState.g != null && previewState.startRuleName != null) {
      updateParseTreeFromDoc(previewState.grammarFile);
    } else {
      setParseTree(Collections.<String>emptyList(), null); // blank tree
    }

    profilerPanel.grammarFileSaved(previewState, grammarFile);
  }
예제 #5
0
  /** Load grammars and set editor component. */
  public void switchToGrammar(VirtualFile oldFile, VirtualFile grammarFile) {
    String grammarFileName = grammarFile.getPath();
    LOG.info("switchToGrammar " + grammarFileName + " " + project.getName());
    ANTLRv4PluginController controller = ANTLRv4PluginController.getInstance(project);
    PreviewState previewState = controller.getPreviewState(grammarFile);

    inputPanel.switchToGrammar(grammarFile);

    if (previewState.startRuleName != null) {
      updateParseTreeFromDoc(grammarFile);
    } else {
      setParseTree(Collections.<String>emptyList(), null); // blank tree
    }

    profilerPanel.switchToGrammar(previewState, grammarFile);

    if (previewState.g == null && previewState.lg != null) {
      setEnabled(false);
    } else {
      setEnabled(true);
    }
  }