@SuppressWarnings("deprecation")
  private void doELTooltipTest(String prefix, String value, String compare) {
    String documentContent = caTest.getDocument().get();
    int start = (documentContent == null ? -1 : documentContent.indexOf(prefix));
    assertFalse("Required node '" + prefix + "' not found in document", (start == -1));
    int offsetToTest = start + prefix.length();

    ITextHover hover = getTextHover(caTest.getViewer(), offsetToTest - 1);
    assertNotNull("Hover not found for value: '" + value + "'", hover);

    String hoverText = null;
    if (hover instanceof ITextHoverExtension2) {
      Object hoverInfo2 =
          ((ITextHoverExtension2) hover)
              .getHoverInfo2(
                  caTest.getViewer(), hover.getHoverRegion(caTest.getViewer(), offsetToTest));
      hoverText = String.valueOf(hoverInfo2);
    } else {
      hoverText =
          ((ITextHover) hover)
              .getHoverInfo(
                  caTest.getViewer(), hover.getHoverRegion(caTest.getViewer(), offsetToTest));
    }
    String hoverTextValue = HTML2TextUtil.html2Text(hoverText);
    String compareValue = HTML2TextUtil.html2Text(compare);
    // System.out.println("Hover Text: [" + hoverTextValue + "]\nExpected Value: [" + compareValue +
    // "]\nEqual: " + compareValue.equalsIgnoreCase(hoverTextValue) + "\n");
    assertTrue(
        "Hover exists but its value is not expected:\nHover Text: ["
            + hoverTextValue
            + "]\nExpected Value: ["
            + compareValue
            + "]",
        compareValue.equalsIgnoreCase(hoverTextValue));
  }
 public String getInformation(ITextViewer textViewer, IRegion subject) {
   if (fImplementation != null) {
     String s = fImplementation.getHoverInfo(textViewer, subject);
     if (s != null && s.trim().length() > 0) return s;
   }
   return null;
 }
예제 #3
0
  @Override
  public Object getHoverInfo2(ITextViewer textViewer, IRegion region) {
    // Overridden from ITextHoverExtension2. We try and return the richest help available; this
    // means trying to call getHoverInfo2() on any contributors, and falling back on getHoverInfo().
    lastReturnedHover = null;

    // Return any annotation info - i.e. errors and warnings.
    String annotationHover = super.getHoverInfo(textViewer, region);

    if (annotationHover != null) {
      return escapeHtmlEntities(annotationHover);
    }

    // Check through the contributed hover providers.
    for (ITextHover hoverContributer : hoverContributors) {
      if (hoverContributer instanceof ITextHoverExtension2) {
        Object hoverInfo =
            ((ITextHoverExtension2) hoverContributer).getHoverInfo2(textViewer, region);

        if (hoverInfo != null) {
          lastReturnedHover = hoverContributer;

          return hoverInfo;
        }
      } else {
        String hoverText = hoverContributer.getHoverInfo(textViewer, region);

        if (hoverText != null) {
          lastReturnedHover = hoverContributer;

          return hoverText;
        }
      }
    }

    // Check for a dartdoc contribution.
    return getDartDocHover(region);
  }
예제 #4
0
    /**
     * Tries to make a text hover focusable (or "sticky").
     *
     * @param sourceViewer the source viewer to display the hover over
     * @param textHover the hover to make focusable
     * @return <code>true</code> if successful, <code>false</code> otherwise
     */
    @SuppressWarnings("deprecation")
    private boolean makeTextHoverFocusable(ISourceViewer sourceViewer, ITextHover textHover) {
      Point hoverEventLocation = ((ITextViewerExtension2) sourceViewer).getHoverEventLocation();
      int offset =
          computeOffsetAtLocation(sourceViewer, hoverEventLocation.x, hoverEventLocation.y);
      if (offset == -1) return false;

      try {
        IRegion hoverRegion = textHover.getHoverRegion(sourceViewer, offset);
        if (hoverRegion == null) return false;

        String hoverInfo = textHover.getHoverInfo(sourceViewer, hoverRegion);

        IInformationControlCreator controlCreator = null;
        if (textHover instanceof IInformationProviderExtension2)
          controlCreator =
              ((IInformationProviderExtension2) textHover).getInformationPresenterControlCreator();

        IInformationProvider informationProvider =
            new InformationProvider(hoverRegion, hoverInfo, controlCreator);

        fInformationPresenter.setOffset(offset);
        fInformationPresenter.setAnchor(AbstractInformationControlManager.ANCHOR_BOTTOM);
        fInformationPresenter.setMargins(
            6, 6); // default values from AbstractInformationControlManager
        String contentType =
            TextUtilities.getContentType(
                sourceViewer.getDocument(), AutoconfPartitionScanner.AUTOCONF_MACRO, offset, true);
        fInformationPresenter.setInformationProvider(informationProvider, contentType);
        fInformationPresenter.showInformation();

        return true;

      } catch (BadLocationException e) {
        return false;
      }
    }
예제 #5
0
  @SuppressWarnings("deprecation")
  @Override
  public String getHoverInfo(ITextViewer textViewer, IRegion region) {
    // Return any annotation info - i.e. errors and warnings.
    String annotationHover = super.getHoverInfo(textViewer, region);

    if (annotationHover != null) {
      return escapeHtmlEntities(annotationHover);
    }

    // Check through the contributed hover providers.
    for (ITextHover hoverContributer : hoverContributors) {
      String hoverText = hoverContributer.getHoverInfo(textViewer, region);

      if (hoverText != null) {
        lastReturnedHover = hoverContributer;

        return hoverText;
      }
    }

    // Check for a dartdoc contribution.
    return getDartDocHover(region);
  }