Search in sources :

Example 1 with LookupImpl

use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.

the class XmlCompletionTest method selectItem.

private void selectItem(LookupElement element, char ch) {
    final LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(myFixture.getEditor());
    lookup.setCurrentItem(element);
    lookup.finishLookup(ch);
}
Also used : LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl)

Example 2 with LookupImpl

use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.

the class XmlSmartEnterTest method performCompletionAction.

private void performCompletionAction() {
    new CodeCompletionHandlerBase(CompletionType.BASIC).invokeCompletion(getProject(), getEditor());
    final LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(getEditor());
    myItems = lookup == null ? null : lookup.getItems().toArray(LookupElement.EMPTY_ARRAY);
}
Also used : LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl)

Example 3 with LookupImpl

use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.

the class PyLiveTemplatesExpandingTest method doMultiFileTest.

private void doMultiFileTest() {
    myFixture.copyDirectoryToProject(getTestName(false), "");
    myFixture.configureByFile("a.py");
    final Editor editor = myFixture.getEditor();
    final Project project = myFixture.getProject();
    new ListTemplatesAction().actionPerformedImpl(project, editor);
    final LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(editor);
    assertNotNull(lookup);
    lookup.finishLookup(Lookup.NORMAL_SELECT_CHAR);
    myFixture.checkResultByFile(getTestName(false) + "/a_after.py");
}
Also used : Project(com.intellij.openapi.project.Project) LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) Editor(com.intellij.openapi.editor.Editor) ListTemplatesAction(com.intellij.codeInsight.template.impl.actions.ListTemplatesAction)

Example 4 with LookupImpl

use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.

the class GrFinalListener method perform.

public void perform(final boolean generateFinal, final String modifier, final GrVariable variable) {
    final Document document = myEditor.getDocument();
    LOG.assertTrue(variable != null);
    final GrModifierList modifierList = variable.getModifierList();
    LOG.assertTrue(modifierList != null);
    final int textOffset = modifierList.getTextOffset();
    final Runnable runnable = () -> {
        if (generateFinal) {
            final GrTypeElement typeElement = variable.getTypeElementGroovy();
            final int typeOffset = typeElement != null ? typeElement.getTextOffset() : textOffset;
            document.insertString(typeOffset, modifier + " ");
        } else {
            final int idx = modifierList.getText().indexOf(modifier);
            document.deleteString(textOffset + idx, textOffset + idx + modifier.length() + 1);
        }
    };
    final LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(myEditor);
    if (lookup != null) {
        lookup.performGuardedChange(runnable);
    } else {
        runnable.run();
    }
    PsiDocumentManager.getInstance(variable.getProject()).commitDocument(document);
}
Also used : GrModifierList(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList) GrTypeElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement) LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) Document(com.intellij.openapi.editor.Document)

Example 5 with LookupImpl

use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.

the class VisibilityListener method perform.

/**
   * to be performed in write action
   */
public void perform(final PsiVariable variable) {
    ApplicationManager.getApplication().assertWriteAccessAllowed();
    final Document document = myEditor.getDocument();
    LOG.assertTrue(variable != null);
    final PsiModifierList modifierList = variable.getModifierList();
    LOG.assertTrue(modifierList != null);
    int textOffset = modifierList.getTextOffset();
    final String modifierListText = modifierList.getText();
    int length = PsiModifier.PUBLIC.length();
    int idx = modifierListText.indexOf(PsiModifier.PUBLIC);
    if (idx == -1) {
        idx = modifierListText.indexOf(PsiModifier.PROTECTED);
        length = PsiModifier.PROTECTED.length();
    }
    if (idx == -1) {
        idx = modifierListText.indexOf(PsiModifier.PRIVATE);
        length = PsiModifier.PRIVATE.length();
    }
    String visibility = getVisibility();
    if (visibility == PsiModifier.PACKAGE_LOCAL) {
        visibility = "";
    }
    final boolean wasPackageLocal = idx == -1;
    final boolean isPackageLocal = visibility.isEmpty();
    final int startOffset = textOffset + (wasPackageLocal ? 0 : idx);
    final int endOffset;
    if (wasPackageLocal) {
        endOffset = startOffset;
    } else {
        endOffset = textOffset + length + (isPackageLocal ? 1 : 0);
    }
    final String finalVisibility = visibility + (wasPackageLocal ? " " : "");
    Runnable runnable = () -> document.replaceString(startOffset, endOffset, finalVisibility);
    final LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(myEditor);
    if (lookup != null) {
        lookup.performGuardedChange(runnable);
    } else {
        runnable.run();
    }
}
Also used : LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) Document(com.intellij.openapi.editor.Document) PsiModifierList(com.intellij.psi.PsiModifierList)

Aggregations

LookupImpl (com.intellij.codeInsight.lookup.impl.LookupImpl)39 ListTemplatesAction (com.intellij.codeInsight.template.impl.actions.ListTemplatesAction)5 Document (com.intellij.openapi.editor.Document)5 Editor (com.intellij.openapi.editor.Editor)5 Project (com.intellij.openapi.project.Project)5 LookupElement (com.intellij.codeInsight.lookup.LookupElement)4 PlainPrefixMatcher (com.intellij.codeInsight.completion.PlainPrefixMatcher)2 LookupEx (com.intellij.codeInsight.lookup.LookupEx)2 TemplateState (com.intellij.codeInsight.template.impl.TemplateState)2 CodeInsightSettings (com.intellij.codeInsight.CodeInsightSettings)1 CamelHumpMatcher (com.intellij.codeInsight.completion.impl.CamelHumpMatcher)1 CompletionSorterImpl (com.intellij.codeInsight.completion.impl.CompletionSorterImpl)1 Lookup (com.intellij.codeInsight.lookup.Lookup)1 LookupManager (com.intellij.codeInsight.lookup.LookupManager)1 LiveTemplateLookupElement (com.intellij.codeInsight.template.impl.LiveTemplateLookupElement)1 CommandAdapter (com.intellij.openapi.command.CommandAdapter)1 CommandEvent (com.intellij.openapi.command.CommandEvent)1 SelectionModel (com.intellij.openapi.editor.SelectionModel)1 DocCommandGroupId (com.intellij.openapi.editor.actionSystem.DocCommandGroupId)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1