Search in sources :

Example 11 with PsiNamedElement

use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.

the class PyRenameArgumentQuickFix method applyFix.

@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    final PsiElement element = descriptor.getPsiElement();
    if (!(element instanceof PsiNamedElement))
        return;
    final VirtualFile virtualFile = element.getContainingFile().getVirtualFile();
    if (virtualFile != null) {
        final Editor editor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, virtualFile), true);
        final TemplateBuilderImpl builder = new TemplateBuilderImpl(element);
        final String name = ((PsiNamedElement) element).getName();
        assert name != null;
        assert editor != null;
        builder.replaceElement(element, TextRange.create(0, name.length()), name);
        builder.run(editor, false);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TemplateBuilderImpl(com.intellij.codeInsight.template.TemplateBuilderImpl) PsiNamedElement(com.intellij.psi.PsiNamedElement) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Editor(com.intellij.openapi.editor.Editor) PsiElement(com.intellij.psi.PsiElement)

Example 12 with PsiNamedElement

use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.

the class DictionarySuggestionProvider method getSuggestedNames.

@Override
public SuggestedNameInfo getSuggestedNames(PsiElement element, PsiElement nameSuggestionContext, Set<String> result) {
    assert result != null;
    if (!active || nameSuggestionContext == null) {
        return null;
    }
    String text = nameSuggestionContext.getText();
    if (nameSuggestionContext instanceof PsiNamedElement) {
        //noinspection ConstantConditions
        text = ((PsiNamedElement) element).getName();
    }
    if (text == null) {
        return null;
    }
    Project project = element.getProject();
    SpellCheckerManager manager = SpellCheckerManager.getInstance(project);
    manager.getSuggestions(text).stream().filter(newName -> RenameUtil.isValidName(project, element, newName)).forEach(result::add);
    return SuggestedNameInfo.NULL_INFO;
}
Also used : SuggestedNameInfo(com.intellij.psi.codeStyle.SuggestedNameInfo) RenameUtil(com.intellij.refactoring.rename.RenameUtil) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) Set(java.util.Set) PsiNamedElement(com.intellij.psi.PsiNamedElement) SpellCheckerManager(com.intellij.spellchecker.SpellCheckerManager) PreferrableNameSuggestionProvider(com.intellij.refactoring.rename.PreferrableNameSuggestionProvider) Project(com.intellij.openapi.project.Project) PsiNamedElement(com.intellij.psi.PsiNamedElement) SpellCheckerManager(com.intellij.spellchecker.SpellCheckerManager)

Example 13 with PsiNamedElement

use of com.intellij.psi.PsiNamedElement 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 14 with PsiNamedElement

use of com.intellij.psi.PsiNamedElement in project intellij-elixir by KronicDeth.

the class Module method aliasedName.

@Nullable
private String aliasedName(@NotNull QualifiedAlias element) {
    String aliasedName = null;
    PsiElement[] children = element.getChildren();
    int operatorIndex = org.elixir_lang.psi.operation.Normalized.operatorIndex(children);
    PsiElement unqualified = org.elixir_lang.psi.operation.infix.Normalized.rightOperand(children, operatorIndex);
    assert children.length == 3;
    if (unqualified instanceof PsiNamedElement) {
        PsiNamedElement namedElement = (PsiNamedElement) unqualified;
        aliasedName = namedElement.getName();
    }
    return aliasedName;
}
Also used : PsiNamedElement(com.intellij.psi.PsiNamedElement) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with PsiNamedElement

use of com.intellij.psi.PsiNamedElement in project intellij-elixir by KronicDeth.

the class UnaliasedName method down.

/*
     * Private Static Methods
     */
@Nullable
private static String down(@NotNull PsiElement element) {
    String unaliasedName = null;
    if (element instanceof QualifiableAlias) {
        PsiNamedElement namedElement = (PsiNamedElement) element;
        unaliasedName = namedElement.getName();
    }
    return unaliasedName;
}
Also used : PsiNamedElement(com.intellij.psi.PsiNamedElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PsiNamedElement (com.intellij.psi.PsiNamedElement)65 PsiElement (com.intellij.psi.PsiElement)29 NotNull (org.jetbrains.annotations.NotNull)16 ArrayList (java.util.ArrayList)14 PsiFile (com.intellij.psi.PsiFile)8 LookupElement (com.intellij.codeInsight.lookup.LookupElement)7 Pair (com.intellij.openapi.util.Pair)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Project (com.intellij.openapi.project.Project)4 UsageInfo (com.intellij.usageView.UsageInfo)4 Nullable (org.jetbrains.annotations.Nullable)4 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)3 PsiReference (com.intellij.psi.PsiReference)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 PyClass (com.jetbrains.python.psi.PyClass)3 PyFunction (com.jetbrains.python.psi.PyFunction)3 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)2 LoadedSymbol (com.google.idea.blaze.base.lang.buildfile.psi.LoadedSymbol)2 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)2 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)2