Ejemplo n.º 1
0
 private static HighlighterMessage createHighlighterMessage(
     SNode node,
     String message,
     MessageStatus status,
     IErrorReporter errorReporter,
     BaseEditorChecker checker) {
   if (errorReporter == null) {
     errorReporter =
         new SimpleErrorReporter(node, message, null, null, status, new NodeMessageTarget());
   }
   HighlighterMessage error =
       new HighlighterMessage(
           node,
           status,
           errorReporter.getErrorTarget(),
           getMessageColor(status),
           message,
           checker);
   error.setErrorReporter(errorReporter);
   for (QuickFixProvider quickFixProvider : errorReporter.getIntentionProviders()) {
     quickFixProvider.setIsError(error.getStatus() == MessageStatus.ERROR);
     error.addIntentionProvider(quickFixProvider);
   }
   return error;
 }
  private boolean applyInstantIntention(
      final EditorContext editorContext,
      final SNode quickFixNode,
      QuickFixProvider intentionProvider) {
    final QuickFix_Runtime intention = intentionProvider.getQuickFix();
    if (intention != null) {
      if (!myOnceExecutedQuickFixes.contains(intention)) {
        myOnceExecutedQuickFixes.add(intention);
        ApplicationManager.getApplication()
            .invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    EditorCell selectedCell = editorContext.getSelectedCell();
                    if (selectedCell == null) return;
                    int caretX = selectedCell.getCaretX();
                    int caretY = selectedCell.getBaseline();

                    Project p =
                        editorContext.getOperationContext() != null
                            ? editorContext.getOperationContext().getProject()
                            : null;
                    if (p == null) {
                      return;
                    }

                    p.getModelAccess()
                        .executeUndoTransparentCommand(
                            new Runnable() {
                              @Override
                              public void run() {
                                intention.execute(quickFixNode);
                              }
                            });

                    editorContext.flushEvents();
                    if (editorContext.getSelectionManager().getSelection() == null) {
                      EditorCell rootCell = editorContext.getEditorComponent().getRootCell();
                      EditorCell leaf = rootCell.findLeaf(caretX, caretY);
                      if (leaf != null) {
                        editorContext.getEditorComponent().changeSelection(leaf);
                        leaf.setCaretX(caretX);
                      }
                    }
                  }
                },
                ModalityState.NON_MODAL);
      }
      return true;
    }
    return false;
  }