public void testDimenUnitsCompletion1() throws Exception {
    final VirtualFile file = copyFileToProject(getTestName(true) + ".xml");
    myFixture.configureFromExistingVirtualFile(file);
    myFixture.complete(CompletionType.BASIC);

    final List<String> lookupElementStrings = myFixture.getLookupElementStrings();
    assertNotNull(lookupElementStrings);
    UsefulTestCase.assertSameElements(
        lookupElementStrings, "3dp", "3px", "3sp", "3pt", "3mm", "3in");

    final PsiElement originalElement =
        myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset());
    assertNotNull(originalElement);

    final LookupEx lookup = myFixture.getLookup();
    LookupElement dpElement = null;
    LookupElement pxElement = null;

    for (LookupElement element : lookup.getItems()) {
      if (element.getLookupString().endsWith("dp")) {
        dpElement = element;
      } else if (element.getLookupString().endsWith("px")) {
        pxElement = element;
      }
    }
    assertNotNull(dpElement);
    assertNotNull(pxElement);
    DocumentationProvider provider;
    PsiElement docTargetElement;

    lookup.setCurrentItem(dpElement);
    docTargetElement =
        DocumentationManager.getInstance(getProject())
            .findTargetElement(myFixture.getEditor(), myFixture.getFile(), originalElement);
    assertNotNull(docTargetElement);
    provider = DocumentationManager.getProviderFromElement(docTargetElement);
    assertEquals(
        "<html><body><b>Density-independent Pixels</b> - an abstract unit that is based on the physical "
            + "density of the screen.</body></html>",
        provider.generateDoc(docTargetElement, originalElement));

    lookup.setCurrentItem(pxElement);
    docTargetElement =
        DocumentationManager.getInstance(getProject())
            .findTargetElement(myFixture.getEditor(), myFixture.getFile(), originalElement);
    assertNotNull(docTargetElement);
    provider = DocumentationManager.getProviderFromElement(docTargetElement);
    assertEquals(
        "<html><body><b>Pixels</b> - corresponds to actual pixels on the screen. Not recommended.</body></html>",
        provider.generateDoc(docTargetElement, originalElement));
  }
    DocumentationTestContext(String... fileNames) throws Exception {
      configureByFiles(null, fileNames);
      psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(myEditor.getDocument());
      originalElement = psiFile.findElementAt(myEditor.getCaretModel().getOffset());
      element =
          DocumentationManager.getInstance(myProject)
              .findTargetElement(myEditor, myFile, originalElement);

      if (element == null) {
        element = originalElement;
      }

      documentationProvider = DocumentationManager.getProviderFromElement(element);
    }
Example #3
0
 @NotNull
 private static DocInfo generateInfo(PsiElement element, PsiElement atPointer) {
   final DocumentationProvider documentationProvider =
       DocumentationManager.getProviderFromElement(element, atPointer);
   String result = doGenerateInfo(element, atPointer, documentationProvider);
   return result == null ? DocInfo.EMPTY : new DocInfo(result, documentationProvider, element);
 }
  @Nullable
  private static String generateInfo(PsiElement element, PsiElement atPointer) {
    final DocumentationProvider documentationProvider =
        DocumentationManager.getProviderFromElement(element, atPointer);

    String info = documentationProvider.getQuickNavigateInfo(element, atPointer);
    if (info != null) {
      return info;
    }

    if (element instanceof PsiFile) {
      final VirtualFile virtualFile = ((PsiFile) element).getVirtualFile();
      if (virtualFile != null) {
        return virtualFile.getPresentableUrl();
      }
    }

    info = getQuickNavigateInfo(element);
    if (info != null) {
      return info;
    }

    if (element instanceof NavigationItem) {
      final ItemPresentation presentation = ((NavigationItem) element).getPresentation();
      if (presentation != null) {
        return presentation.getPresentableText();
      }
    }

    return null;
  }
Example #5
0
 @Override
 public void showDocInfo(@NotNull DocumentationManager docManager) {
   docManager.showJavaDocInfo(myTargetElement, myElementAtPointer, true, null);
   docManager.setAllowContentUpdateFromContext(false);
 }