Пример #1
0
  @Override
  protected void evaluateAndShowHint() {
    myEvaluator.evaluate(
        myExpression,
        new XEvaluationCallbackBase() {
          @Override
          public void evaluated(@NotNull final XValue result) {
            result.computePresentation(
                new XValueNodePresentationConfigurator.ConfigurableXValueNodeImpl() {
                  private XFullValueEvaluator myFullValueEvaluator;
                  private boolean myShown = false;

                  @Override
                  public void applyPresentation(
                      @Nullable Icon icon,
                      @NotNull XValuePresentation valuePresenter,
                      boolean hasChildren) {
                    if (isHintHidden()) {
                      return;
                    }

                    SimpleColoredText text = new SimpleColoredText();
                    text.append(
                        StringUtil.trimMiddle(myValueName, 200),
                        XDebuggerUIConstants.VALUE_NAME_ATTRIBUTES);
                    XValueNodeImpl.buildText(valuePresenter, text);

                    if (!hasChildren) {
                      SimpleColoredComponent component = HintUtil.createInformationComponent();
                      text.appendToComponent(component);
                      if (myFullValueEvaluator != null) {
                        component.append(
                            myFullValueEvaluator.getLinkText(),
                            XDebuggerTreeNodeHyperlink.TEXT_ATTRIBUTES,
                            new Consumer<MouseEvent>() {
                              @Override
                              public void consume(MouseEvent event) {
                                DebuggerUIUtil.showValuePopup(
                                    myFullValueEvaluator, event, getProject(), getEditor());
                              }
                            });
                        LinkMouseListenerBase.installSingleTagOn(component);
                      }
                      showHint(component);
                    } else if (getType() == ValueHintType.MOUSE_CLICK_HINT) {
                      if (!myShown) {
                        showTree(result);
                      }
                    } else {
                      if (getType() == ValueHintType.MOUSE_OVER_HINT) {
                        text.insert(
                            0,
                            "("
                                + KeymapUtil.getFirstKeyboardShortcutText("ShowErrorDescription")
                                + ") ",
                            SimpleTextAttributes.GRAYED_ATTRIBUTES);
                      }

                      JComponent component =
                          createExpandableHintComponent(
                              text,
                              new Runnable() {
                                @Override
                                public void run() {
                                  showTree(result);
                                }
                              });
                      showHint(component);
                    }
                    myShown = true;
                  }

                  @Override
                  public void setFullValueEvaluator(
                      @NotNull XFullValueEvaluator fullValueEvaluator) {
                    myFullValueEvaluator = fullValueEvaluator;
                  }

                  @Override
                  public boolean isObsolete() {
                    return isHintHidden();
                  }
                },
                XValuePlace.TOOLTIP);
          }

          @Override
          public void errorOccurred(@NotNull final String errorMessage) {
            ApplicationManager.getApplication()
                .invokeLater(
                    new Runnable() {
                      @Override
                      public void run() {
                        int start = 0, end = 0;
                        if (getCurrentRange() != null) {
                          start = getCurrentRange().getStartOffset();
                          end = getCurrentRange().getEndOffset();
                        }
                        HintManager.getInstance()
                            .showErrorHint(
                                getEditor(),
                                errorMessage,
                                start,
                                end,
                                HintManager.ABOVE,
                                HintManager.HIDE_BY_ESCAPE | HintManager.HIDE_BY_TEXT_CHANGE,
                                0);
                      }
                    });
            LOG.debug("Cannot evaluate '" + myExpression + "':" + errorMessage);
          }
        },
        myExpressionPosition);
  }
Пример #2
0
  protected void evaluateAndShowHint() {
    myEvaluator.evaluate(
        myExpression,
        new XEvaluationCallbackBase() {
          public void evaluated(@NotNull final XValue result) {
            result.computePresentation(
                new XValueNode() {
                  @Override
                  public void setPresentation(
                      @Nullable Icon icon,
                      @NonNls @Nullable String type,
                      @NonNls @NotNull String value,
                      boolean hasChildren) {
                    setPresentation(icon, type, XDebuggerUIConstants.EQ_TEXT, value, hasChildren);
                  }

                  @Override
                  public void setPresentation(
                      @Nullable Icon icon,
                      @NonNls @Nullable String type,
                      @NonNls @NotNull String separator,
                      @NonNls @NotNull String value,
                      boolean hasChildren) {
                    setPresentation(icon, type, separator, value, null, hasChildren);
                  }

                  @Override
                  public void setPresentation(
                      @Nullable Icon icon,
                      @NonNls @Nullable String type,
                      @NonNls @NotNull String value,
                      @Nullable NotNullFunction<String, String> valuePresenter,
                      boolean hasChildren) {
                    setPresentation(
                        icon,
                        type,
                        XDebuggerUIConstants.EQ_TEXT,
                        value,
                        valuePresenter,
                        hasChildren);
                  }

                  @Override
                  public void setGroupingPresentation(
                      @Nullable Icon icon,
                      @NonNls @Nullable String value,
                      @Nullable XValuePresenter valuePresenter,
                      boolean expand) {
                    setPresentation(icon, value, valuePresenter, true);
                  }

                  @Override
                  public void setPresentation(
                      @Nullable Icon icon,
                      @NonNls @Nullable String value,
                      @Nullable XValuePresenter valuePresenter,
                      boolean hasChildren) {
                    doSetPresentation(
                        icon,
                        null,
                        XDebuggerUIConstants.EQ_TEXT,
                        value,
                        valuePresenter,
                        hasChildren);
                  }

                  @Override
                  public void setPresentation(
                      @Nullable Icon icon,
                      @NonNls @Nullable final String type,
                      @NonNls @NotNull final String separator,
                      @NonNls @NotNull final String value,
                      @Nullable final NotNullFunction<String, String> valuePresenter,
                      final boolean hasChildren) {
                    doSetPresentation(
                        icon,
                        type,
                        separator,
                        value,
                        valuePresenter == null ? null : new XValuePresenterAdapter(valuePresenter),
                        hasChildren);
                  }

                  private void doSetPresentation(
                      @Nullable Icon icon,
                      @NonNls @Nullable final String type,
                      @NonNls @NotNull final String separator,
                      @NonNls @Nullable final String value,
                      @Nullable final XValuePresenter valuePresenter,
                      final boolean hasChildren) {
                    DebuggerUIUtil.invokeOnEventDispatch(
                        new Runnable() {
                          public void run() {
                            doShowHint(
                                result,
                                separator,
                                value,
                                type,
                                valuePresenter == null
                                    ? XValueNodeImpl.DEFAULT_VALUE_PRESENTER
                                    : valuePresenter,
                                hasChildren);
                          }
                        });
                  }

                  public void setPresentation(
                      @NonNls final String name,
                      @Nullable final Icon icon,
                      @NonNls @Nullable final String type,
                      @NonNls @NotNull final String value,
                      final boolean hasChildren) {
                    setPresentation(icon, type, value, hasChildren);
                  }

                  public void setPresentation(
                      @NonNls final String name,
                      @Nullable final Icon icon,
                      @NonNls @Nullable final String type,
                      @NonNls @NotNull final String separator,
                      @NonNls @NotNull final String value,
                      final boolean hasChildren) {
                    setPresentation(icon, type, separator, value, hasChildren);
                  }

                  public void setFullValueEvaluator(
                      @NotNull XFullValueEvaluator fullValueEvaluator) {
                    // todo[nik] implement?
                  }

                  public boolean isObsolete() {
                    // todo[nik]
                    return false;
                  }
                },
                XValuePlace.TOOLTIP);
          }

          public void errorOccurred(@NotNull final String errorMessage) {
            LOG.debug("Cannot evaluate '" + myExpression + "':" + errorMessage);
          }
        },
        myExpressionPosition);
  }