Search in sources :

Example 41 with PsiNamedElement

use of com.intellij.psi.PsiNamedElement in project intellij-swagger by zalando.

the class OperationSecurityCompletion method getSecurityDefinitions.

private List<ArrayField> getSecurityDefinitions() {
    final PsiFile containingFile = completionHelper.getPsiFile().getContainingFile();
    final List<? extends PsiNamedElement> securityDefinitions = new PathFinder().findChildrenByPathFrom("$.securityDefinitions", containingFile);
    return securityDefinitions.stream().map(PsiNamedElement::getName).map(ArrayField::new).collect(Collectors.toList());
}
Also used : PsiNamedElement(com.intellij.psi.PsiNamedElement) PsiFile(com.intellij.psi.PsiFile) PathFinder(org.zalando.intellij.swagger.traversal.path.PathFinder)

Example 42 with PsiNamedElement

use of com.intellij.psi.PsiNamedElement in project intellij-swagger by zalando.

the class PathFinder method isInsidePath.

private boolean isInsidePath(final PsiElement psiElement, PathExpression pathExpression) {
    if (psiElement == null) {
        return false;
    }
    final PsiNamedElement nextNamedParent = getNextNamedParent(psiElement);
    final String unescapedTargetKeyName = unescapedName(pathExpression.last());
    if (pathExpression.isAnyKey()) {
        return isInsidePath(getNextNamedParent(nextNamedParent.getParent()), pathExpression.beforeLast());
    }
    if (pathExpression.isAnyKeys()) {
        return isInsidePath(goUpToElementWithParentName(psiElement, pathExpression.secondLast()), pathExpression.beforeLast());
    }
    if (unescapedTargetKeyName.equals(ROOT_PATH)) {
        return nextNamedParent instanceof PsiFile;
    }
    return unescapedTargetKeyName.equals(nextNamedParent.getName()) && (pathExpression.hasOnePath() || isInsidePath(nextNamedParent.getParent(), pathExpression.beforeLast()));
}
Also used : PsiNamedElement(com.intellij.psi.PsiNamedElement) PsiFile(com.intellij.psi.PsiFile)

Example 43 with PsiNamedElement

use of com.intellij.psi.PsiNamedElement in project android by JetBrains.

the class ResourceDirectoryNode method collectChildren.

public void collectChildren() {
    for (AbstractTreeNode child : myBaseNode.getChildren()) {
        Object value = child.getValue();
        if (value instanceof PsiNamedElement) {
            String name = ((PsiNamedElement) value).getName();
            if (!myChildMap.containsKey(name)) {
                myChildMap.put(name, child);
                myChildren.add(child);
            }
        } else {
            myChildren.add(child);
        }
    }
}
Also used : PsiNamedElement(com.intellij.psi.PsiNamedElement) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode)

Example 44 with PsiNamedElement

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

the class JavaTestFinder method findClassesForTest.

@NotNull
public Collection<PsiElement> findClassesForTest(@NotNull PsiElement element) {
    PsiClass klass = findSourceElement(element);
    if (klass == null)
        return Collections.emptySet();
    GlobalSearchScope scope = getSearchScope(element, true);
    PsiShortNamesCache cache = PsiShortNamesCache.getInstance(element.getProject());
    List<Pair<? extends PsiNamedElement, Integer>> classesWithWeights = new ArrayList<>();
    for (Pair<String, Integer> eachNameWithWeight : TestFinderHelper.collectPossibleClassNamesWithWeights(klass.getName())) {
        for (PsiClass eachClass : cache.getClassesByName(eachNameWithWeight.first, scope)) {
            if (isTestSubjectClass(eachClass)) {
                classesWithWeights.add(Pair.create(eachClass, eachNameWithWeight.second));
            }
        }
    }
    return TestFinderHelper.getSortedElements(classesWithWeights, false);
}
Also used : PsiShortNamesCache(com.intellij.psi.search.PsiShortNamesCache) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiNamedElement(com.intellij.psi.PsiNamedElement) PsiClass(com.intellij.psi.PsiClass) ArrayList(java.util.ArrayList) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 45 with PsiNamedElement

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

the class CachesBasedRefSearcher method processQuery.

@Override
public void processQuery(@NotNull ReferencesSearch.SearchParameters p, @NotNull Processor<PsiReference> consumer) {
    final PsiElement refElement = p.getElementToSearch();
    boolean caseSensitive = refElement.getLanguage().isCaseSensitive();
    String text = null;
    if (refElement instanceof PsiFileSystemItem && !(refElement instanceof SyntheticFileSystemItem)) {
        final VirtualFile vFile = ((PsiFileSystemItem) refElement).getVirtualFile();
        if (vFile != null) {
            text = vFile.getNameWithoutExtension();
        }
        // We must not look for file references with the file language's case-sensitivity, 
        // since case-sensitivity of the references themselves depends either on file system 
        // or on the rules of the language of reference
        caseSensitive = false;
    } else if (refElement instanceof PsiNamedElement) {
        text = ((PsiNamedElement) refElement).getName();
        if (refElement instanceof PsiMetaOwner) {
            final PsiMetaData metaData = ((PsiMetaOwner) refElement).getMetaData();
            if (metaData != null)
                text = metaData.getName();
        }
    }
    if (text == null && refElement instanceof PsiMetaOwner) {
        final PsiMetaData metaData = ((PsiMetaOwner) refElement).getMetaData();
        if (metaData != null)
            text = metaData.getName();
    }
    if (StringUtil.isNotEmpty(text)) {
        final SearchScope searchScope = p.getEffectiveSearchScope();
        p.getOptimizer().searchWord(text, searchScope, caseSensitive, refElement);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SyntheticFileSystemItem(com.intellij.psi.impl.SyntheticFileSystemItem) PsiMetaData(com.intellij.psi.meta.PsiMetaData) PsiNamedElement(com.intellij.psi.PsiNamedElement) SearchScope(com.intellij.psi.search.SearchScope) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) PsiMetaOwner(com.intellij.psi.meta.PsiMetaOwner) PsiElement(com.intellij.psi.PsiElement)

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