Search in sources :

Example 31 with LookupElement

use of com.intellij.codeInsight.lookup.LookupElement in project intellij-elixir by KronicDeth.

the class Variants method executeOnAliasedName.

/*
     * Protected Instance Methods
     */
/**
     * Decides whether {@code match} matches the criteria being searched for.  All other {@link #execute} methods
     * eventually end here.
     *
     * @param match
     * @param aliasedName
     * @param state
     * @return {@code true} to keep processing; {@code false} to stop processing.
     */
@Override
protected boolean executeOnAliasedName(@NotNull PsiNamedElement match, @NotNull final String aliasedName, @NotNull ResolveState state) {
    if (lookupElementList == null) {
        lookupElementList = new ArrayList<LookupElement>();
    }
    lookupElementList.add(LookupElementBuilder.createWithSmartPointer(aliasedName, match));
    String unaliasedName = UnaliasedName.unaliasedName(match);
    if (unaliasedName != null) {
        Project project = match.getProject();
        Collection<String> indexedNameCollection = StubIndex.getInstance().getAllKeys(AllName.KEY, project);
        List<String> unaliasedNestedNames = ContainerUtil.findAll(indexedNameCollection, new org.elixir_lang.Module.IsNestedUnder(unaliasedName));
        if (unaliasedNestedNames.size() > 0) {
            GlobalSearchScope scope = GlobalSearchScope.allScope(project);
            for (String unaliasedNestedName : unaliasedNestedNames) {
                Collection<NamedElement> unaliasedNestedNamedElementCollection = StubIndex.getElements(AllName.KEY, unaliasedNestedName, project, scope, NamedElement.class);
                if (unaliasedNestedNamedElementCollection.size() > 0) {
                    List<String> unaliasedNestedNamePartList = split(unaliasedNestedName);
                    List<String> unaliasedNamePartList = split(unaliasedName);
                    List<String> aliasedNamePartList = split(aliasedName);
                    List<String> aliasedNestedNamePartList = new ArrayList<String>();
                    aliasedNestedNamePartList.addAll(aliasedNamePartList);
                    for (int i = unaliasedNamePartList.size(); i < unaliasedNestedNamePartList.size(); i++) {
                        aliasedNestedNamePartList.add(unaliasedNestedNamePartList.get(i));
                    }
                    String aliasedNestedName = concat(aliasedNestedNamePartList);
                    for (NamedElement unaliasedNestedNamedElement : unaliasedNestedNamedElementCollection) {
                        lookupElementList.add(LookupElementBuilder.createWithSmartPointer(aliasedNestedName, unaliasedNestedNamedElement));
                    }
                }
            }
        }
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) LookupElement(com.intellij.codeInsight.lookup.LookupElement) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Module(org.elixir_lang.psi.scope.Module) PsiNamedElement(com.intellij.psi.PsiNamedElement)

Example 32 with LookupElement

use of com.intellij.codeInsight.lookup.LookupElement in project intellij-elixir by KronicDeth.

the class Variants method addToLookupElementByPsiElement.

/*
     * Private Instance Methods
     */
private void addToLookupElementByPsiElement(@NotNull Call call) {
    if (call instanceof Named) {
        Named named = (Named) call;
        PsiElement nameIdentifier = named.getNameIdentifier();
        if (nameIdentifier != null) {
            if (lookupElementByPsiElement == null || !lookupElementByPsiElement.containsKey(nameIdentifier)) {
                if (lookupElementByPsiElement == null) {
                    lookupElementByPsiElement = new THashMap<PsiElement, LookupElement>();
                }
                String name = nameIdentifier.getText();
                lookupElementByPsiElement.put(nameIdentifier, LookupElementBuilder.createWithSmartPointer(name, nameIdentifier).withRenderer(new org.elixir_lang.code_insight.lookup.element_renderer.CallDefinitionClause(name)));
            }
        }
    }
}
Also used : Named(org.elixir_lang.psi.call.Named) CallDefinitionClause(org.elixir_lang.psi.scope.CallDefinitionClause) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PsiElement(com.intellij.psi.PsiElement)

Example 33 with LookupElement

use of com.intellij.codeInsight.lookup.LookupElement in project intellij-elixir by KronicDeth.

the class CallDefinitionClause method callDefinitionClauseLookupElements.

/*
     * Private Instance Methods
     */
@NotNull
private static Iterable<LookupElement> callDefinitionClauseLookupElements(@NotNull Call scope) {
    Call[] childCalls = macroChildCalls(scope);
    List<LookupElement> lookupElementList = null;
    if (childCalls != null && childCalls.length > 0) {
        for (Call childCall : childCalls) {
            if (org.elixir_lang.structure_view.element.CallDefinitionClause.is(childCall)) {
                Pair<String, IntRange> nameArityRange = nameArityRange(childCall);
                if (nameArityRange != null) {
                    String name = nameArityRange.first;
                    if (name != null) {
                        if (lookupElementList == null) {
                            lookupElementList = new ArrayList<LookupElement>();
                        }
                        lookupElementList.add(org.elixir_lang.code_insight.lookup.element.CallDefinitionClause.createWithSmartPointer(nameArityRange.first, childCall));
                    }
                }
            }
        }
    }
    if (lookupElementList == null) {
        lookupElementList = Collections.emptyList();
    }
    return lookupElementList;
}
Also used : Call(org.elixir_lang.psi.call.Call) IntRange(org.apache.commons.lang.math.IntRange) LookupElement(com.intellij.codeInsight.lookup.LookupElement) NotNull(org.jetbrains.annotations.NotNull)

Example 34 with LookupElement

use of com.intellij.codeInsight.lookup.LookupElement in project intellij-elixir by KronicDeth.

the class Variants method executeOnVariable.

/*
     *
     * Instance Methods
     *
     */
/*
     * Protected Instance Methods
     */
/**
     * Decides whether {@code match} matches the criteria being searched for.  All other {@link #execute} methods
     * eventually end here.
     *
     * @return {@code false}, as all variables should be found.  Prefix filtering will be done later by IDEA core.
     */
@Override
protected boolean executeOnVariable(@NotNull PsiNamedElement match, @NotNull ResolveState state) {
    PsiReference reference = match.getReference();
    String name = null;
    PsiElement declaration = match;
    if (reference != null) {
        PsiElement resolved = reference.resolve();
        if (resolved != null) {
            declaration = resolved;
            if (resolved instanceof PsiNamedElement) {
                PsiNamedElement namedResolved = (PsiNamedElement) resolved;
                name = namedResolved.getName();
            }
        }
    }
    if (name == null) {
        name = match.getName();
    }
    if (name != null) {
        if (lookupElementByElement == null) {
            lookupElementByElement = new THashMap<PsiElement, LookupElement>();
        }
        if (!lookupElementByElement.containsKey(declaration)) {
            final String finalName = name;
            lookupElementByElement.put(declaration, LookupElementBuilder.createWithSmartPointer(name, declaration).withRenderer(new org.elixir_lang.code_insight.lookup.element_renderer.Variable(finalName)));
        }
    }
    return true;
}
Also used : Variable(org.elixir_lang.psi.scope.Variable) PsiNamedElement(com.intellij.psi.PsiNamedElement) PsiReference(com.intellij.psi.PsiReference) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PsiElement(com.intellij.psi.PsiElement)

Example 35 with LookupElement

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

the class RenameWrongRefFix method invoke.

@Override
public void invoke(@NotNull Project project, final Editor editor, PsiFile file) {
    PsiReferenceExpression[] refs = CreateFromUsageUtils.collectExpressions(myRefExpr, PsiMember.class, PsiFile.class);
    PsiElement element = PsiTreeUtil.getParentOfType(myRefExpr, PsiMember.class, PsiFile.class);
    LookupElement[] items = collectItems();
    ReferenceNameExpression refExpr = new ReferenceNameExpression(items, myRefExpr.getReferenceName());
    TemplateBuilderImpl builder = new TemplateBuilderImpl(element);
    for (PsiReferenceExpression expr : refs) {
        if (!expr.equals(myRefExpr)) {
            builder.replaceElement(expr.getReferenceNameElement(), OTHER_VARIABLE_NAME, INPUT_VARIABLE_NAME, false);
        } else {
            builder.replaceElement(expr.getReferenceNameElement(), INPUT_VARIABLE_NAME, refExpr, true);
        }
    }
    final float proportion = EditorUtil.calcVerticalScrollProportion(editor);
    editor.getCaretModel().moveToOffset(element.getTextRange().getStartOffset());
    /*for (int i = refs.length - 1; i >= 0; i--) {
      TextRange range = refs[i].getReferenceNameElement().getTextRange();
      document.deleteString(range.getStartOffset(), range.getEndOffset());
    }
*/
    Template template = builder.buildInlineTemplate();
    editor.getCaretModel().moveToOffset(element.getTextRange().getStartOffset());
    TemplateManager.getInstance(project).startTemplate(editor, template);
    EditorUtil.setVerticalScrollProportion(editor, proportion);
}
Also used : TemplateBuilderImpl(com.intellij.codeInsight.template.TemplateBuilderImpl) LookupElement(com.intellij.codeInsight.lookup.LookupElement) Template(com.intellij.codeInsight.template.Template)

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