Search in sources :

Example 56 with LookupElement

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

the class LookupUi method addListeners.

private void addListeners() {
    myList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (myLookup.isLookupDisposed())
                return;
            myHintAlarm.cancelAllRequests();
            final LookupElement item = myLookup.getCurrentItem();
            if (item != null) {
                updateHint(item);
            }
        }
    });
    final Alarm alarm = new Alarm(myLookup);
    myScrollPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {

        @Override
        public void adjustmentValueChanged(AdjustmentEvent e) {
            if (myLookup.myUpdating || myLookup.isLookupDisposed())
                return;
            alarm.addRequest(() -> myLookup.refreshUi(false, false), 300, myModalityState);
        }
    });
}
Also used : Alarm(com.intellij.util.Alarm) ListSelectionEvent(javax.swing.event.ListSelectionEvent) LookupElement(com.intellij.codeInsight.lookup.LookupElement) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 57 with LookupElement

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

the class EncodingReference method getVariants.

@Override
@NotNull
public Object[] getVariants() {
    Charset[] charsets = CharsetToolkit.getAvailableCharsets();
    List<LookupElement> suggestions = new ArrayList<>(charsets.length);
    for (Charset charset : charsets) {
        suggestions.add(LookupElementBuilder.create(charset.name()).withCaseSensitivity(false));
    }
    return suggestions.toArray(new LookupElement[suggestions.size()]);
}
Also used : ArrayList(java.util.ArrayList) Charset(java.nio.charset.Charset) LookupElement(com.intellij.codeInsight.lookup.LookupElement) NotNull(org.jetbrains.annotations.NotNull)

Example 58 with LookupElement

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

the class ComponentTypeOfMacro method calculateLookupItems.

@Override
public LookupElement[] calculateLookupItems(@NotNull Expression[] params, ExpressionContext context) {
    if (params.length != 1)
        return null;
    LookupElement[] lookupItems = params[0].calculateLookupItems(context);
    if (lookupItems == null)
        return null;
    List<LookupElement> result = ContainerUtil.newArrayList();
    for (LookupElement element : lookupItems) {
        PsiTypeLookupItem lookupItem = element.as(PsiTypeLookupItem.CLASS_CONDITION_KEY);
        if (lookupItem != null) {
            PsiType psiType = lookupItem.getType();
            if (psiType instanceof PsiArrayType) {
                result.add(PsiTypeLookupItem.createLookupItem(((PsiArrayType) psiType).getComponentType(), null));
            }
        }
    }
    return lookupItems;
}
Also used : PsiTypeLookupItem(com.intellij.codeInsight.lookup.PsiTypeLookupItem) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PsiArrayType(com.intellij.psi.PsiArrayType) PsiType(com.intellij.psi.PsiType)

Example 59 with LookupElement

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

the class ComponentTypeOfMacro method calculateResult.

@Override
public Result calculateResult(@NotNull Expression[] params, final ExpressionContext context) {
    if (params.length != 1)
        return null;
    final Result result = params[0].calculateResult(context);
    if (result == null)
        return null;
    if (result instanceof PsiTypeResult) {
        PsiType type = ((PsiTypeResult) result).getType();
        if (type instanceof PsiArrayType) {
            return new PsiTypeResult(((PsiArrayType) type).getComponentType(), context.getProject());
        }
    }
    PsiExpression expr = MacroUtil.resultToPsiExpression(result, context);
    PsiType type = expr == null ? MacroUtil.resultToPsiType(result, context) : expr.getType();
    if (type instanceof PsiArrayType) {
        return new PsiTypeResult(((PsiArrayType) type).getComponentType(), context.getProject());
    }
    LookupElement[] elements = params[0].calculateLookupItems(context);
    if (elements != null) {
        for (LookupElement element : elements) {
            PsiTypeLookupItem typeLookupItem = element.as(PsiTypeLookupItem.CLASS_CONDITION_KEY);
            if (typeLookupItem != null) {
                PsiType psiType = typeLookupItem.getType();
                if (psiType instanceof PsiArrayType) {
                    return new PsiTypeResult(((PsiArrayType) psiType).getComponentType(), context.getProject());
                }
            }
        }
    }
    return new PsiElementResult(null);
}
Also used : PsiTypeLookupItem(com.intellij.codeInsight.lookup.PsiTypeLookupItem) PsiExpression(com.intellij.psi.PsiExpression) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PsiArrayType(com.intellij.psi.PsiArrayType) PsiType(com.intellij.psi.PsiType)

Example 60 with LookupElement

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

the class SubtypesMacro method calculateLookupItems.

@Override
public LookupElement[] calculateLookupItems(@NotNull Expression[] params, ExpressionContext context) {
    if (params.length == 0)
        return LookupElement.EMPTY_ARRAY;
    Result paramResult = params[0].calculateQuickResult(context);
    if (paramResult instanceof PsiTypeResult) {
        final PsiType type = ((PsiTypeResult) paramResult).getType();
        final PsiFile file = PsiDocumentManager.getInstance(context.getProject()).getPsiFile(context.getEditor().getDocument());
        final PsiElement element = file.findElementAt(context.getStartOffset());
        final Set<LookupElement> set = new LinkedHashSet<>();
        JavaTemplateUtil.addTypeLookupItem(set, type);
        CodeInsightUtil.processSubTypes(type, element, false, PrefixMatcher.ALWAYS_TRUE, psiType -> JavaTemplateUtil.addTypeLookupItem(set, psiType));
        return set.toArray(new LookupElement[set.size()]);
    }
    return LookupElement.EMPTY_ARRAY;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PsiFile(com.intellij.psi.PsiFile) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PsiElement(com.intellij.psi.PsiElement) PsiType(com.intellij.psi.PsiType)

Aggregations

LookupElement (com.intellij.codeInsight.lookup.LookupElement)183 PsiElement (com.intellij.psi.PsiElement)33 NotNull (org.jetbrains.annotations.NotNull)32 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)20 Nullable (org.jetbrains.annotations.Nullable)17 ArrayList (java.util.ArrayList)14 Project (com.intellij.openapi.project.Project)12 LookupElementPresentation (com.intellij.codeInsight.lookup.LookupElementPresentation)10 Document (com.intellij.openapi.editor.Document)10 PsiFile (com.intellij.psi.PsiFile)10 Editor (com.intellij.openapi.editor.Editor)9 THashSet (gnu.trove.THashSet)8 LinkedHashSet (java.util.LinkedHashSet)8 PrioritizedLookupElement (com.intellij.codeInsight.completion.PrioritizedLookupElement)7 XmlTag (com.intellij.psi.xml.XmlTag)7 Consumer (com.intellij.util.Consumer)7 HashSet (java.util.HashSet)7 InsertionContext (com.intellij.codeInsight.completion.InsertionContext)6 PsiTypeLookupItem (com.intellij.codeInsight.lookup.PsiTypeLookupItem)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6