コード例 #1
0
  public void invoke(
      @NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file) {
    PsiDocumentManager.getInstance(project).commitAllDocuments();

    final LookupEx lookup = LookupManagerImpl.getActiveLookup(editor);
    if (lookup != null) {
      lookup.showElementActions();
      return;
    }

    if (HintManagerImpl.getInstanceImpl().performCurrentQuestionAction()) return;

    // intentions check isWritable before modification: if (!file.isWritable()) return;
    if (file instanceof PsiCodeFragment) return;

    TemplateState state = TemplateManagerImpl.getTemplateState(editor);
    if (state != null && !state.isFinished()) {
      return;
    }

    final DaemonCodeAnalyzerImpl codeAnalyzer =
        (DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(project);
    codeAnalyzer.autoImportReferenceAtCursor(editor, file); // let autoimport complete

    ShowIntentionsPass.IntentionsInfo intentions = new ShowIntentionsPass.IntentionsInfo();
    ShowIntentionsPass.getActionsToShow(editor, file, intentions, -1);

    if (!intentions.isEmpty()) {
      IntentionHintComponent.showIntentionHint(project, file, editor, intentions, true);
    }
  }
コード例 #2
0
  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));
  }