Search in sources :

Example 36 with PsiNamedElement

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

the class FlexUnitTestFinder method findClassesForTest.

@NotNull
public Collection<PsiElement> findClassesForTest(@NotNull final PsiElement element) {
    final JSClass jsClass = findSourceElement(element);
    final String className = jsClass == null ? null : jsClass.getName();
    final Pair<Module, FlexUnitSupport> moduleAndSupport = FlexUnitSupport.getModuleAndSupport(element);
    final Module module = moduleAndSupport == null ? null : moduleAndSupport.first;
    final FlexUnitSupport flexUnitSupport = moduleAndSupport == null ? null : moduleAndSupport.second;
    if (className == null || module == null || flexUnitSupport == null) {
        return Collections.emptyList();
    }
    final GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesScope(module).intersectWith(GlobalSearchScopes.projectProductionScope(module.getProject()));
    final List<Pair<? extends PsiNamedElement, Integer>> classesWithWeights = new ArrayList<>();
    for (Pair<String, Integer> nameWithWeight : TestFinderHelper.collectPossibleClassNamesWithWeights(className)) {
        for (final JSQualifiedNamedElement jsElement : JSResolveUtil.findElementsByName(nameWithWeight.first, module.getProject(), scope)) {
            if (jsElement instanceof JSClass && jsElement != jsClass && !((JSClass) jsElement).isInterface() && !flexUnitSupport.isTestClass((JSClass) jsElement, true)) {
                classesWithWeights.add(Pair.create(jsElement, nameWithWeight.second));
            }
        }
    }
    return TestFinderHelper.getSortedElements(classesWithWeights, false);
}
Also used : PsiNamedElement(com.intellij.psi.PsiNamedElement) ArrayList(java.util.ArrayList) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Module(com.intellij.openapi.module.Module) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 37 with PsiNamedElement

use of com.intellij.psi.PsiNamedElement in project intellij by bazelbuild.

the class CompletionResultsProcessor method process.

@Override
public boolean process(BuildElement buildElement) {
    if (buildElement == originalElement) {
        return true;
    }
    if (buildElement instanceof LoadedSymbol) {
        LoadedSymbol loadedSymbol = (LoadedSymbol) buildElement;
        String string = loadedSymbol.getSymbolString();
        results.put(string, new LoadedSymbolReferenceLookupElement(loadedSymbol, string, quoteType));
    } else if (buildElement instanceof PsiNamedElement) {
        PsiNamedElement namedElement = (PsiNamedElement) buildElement;
        String name = namedElement.getName();
        if (!allowPrivateSymbols && name != null && name.startsWith("_")) {
            return true;
        }
        results.put(name, new NamedBuildLookupElement((PsiNamedElement) buildElement, quoteType));
    }
    return true;
}
Also used : LoadedSymbol(com.google.idea.blaze.base.lang.buildfile.psi.LoadedSymbol) PsiNamedElement(com.intellij.psi.PsiNamedElement)

Example 38 with PsiNamedElement

use of com.intellij.psi.PsiNamedElement in project intellij by bazelbuild.

the class ResolveUtil method findInScope.

/**
 * Walks up PSI tree of local file, checking PsiNamedElements
 */
@Nullable
public static PsiNamedElement findInScope(PsiElement element, String name) {
    PsiNamedElement[] resultHolder = new PsiNamedElement[1];
    Processor<BuildElement> processor = buildElement -> {
        if (buildElement == element) {
            return true;
        }
        if (buildElement instanceof PsiNamedElement && name.equals(buildElement.getName())) {
            resultHolder[0] = (PsiNamedElement) buildElement;
            return false;
        } else if (buildElement instanceof LoadedSymbol) {
            LoadedSymbol loadedSymbol = (LoadedSymbol) buildElement;
            if (name.equals(loadedSymbol.getSymbolString())) {
                PsiElement referencedElement = loadedSymbol.getVisibleElement();
                if (referencedElement instanceof PsiNamedElement) {
                    resultHolder[0] = (PsiNamedElement) referencedElement;
                    return false;
                }
            }
        }
        return true;
    };
    searchInScope(element, processor);
    return resultHolder[0];
}
Also used : TargetExpression(com.google.idea.blaze.base.lang.buildfile.psi.TargetExpression) AssignmentStatement(com.google.idea.blaze.base.lang.buildfile.psi.AssignmentStatement) FunctionStatement(com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement) Parameter(com.google.idea.blaze.base.lang.buildfile.psi.Parameter) ForStatement(com.google.idea.blaze.base.lang.buildfile.psi.ForStatement) StatementList(com.google.idea.blaze.base.lang.buildfile.psi.StatementList) Expression(com.google.idea.blaze.base.lang.buildfile.psi.Expression) BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) Processor(com.intellij.util.Processor) PsiElement(com.intellij.psi.PsiElement) PsiFile(com.intellij.psi.PsiFile) LoadedSymbol(com.google.idea.blaze.base.lang.buildfile.psi.LoadedSymbol) PsiNamedElement(com.intellij.psi.PsiNamedElement) BuildElement(com.google.idea.blaze.base.lang.buildfile.psi.BuildElement) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) Nullable(javax.annotation.Nullable) PsiNamedElement(com.intellij.psi.PsiNamedElement) LoadedSymbol(com.google.idea.blaze.base.lang.buildfile.psi.LoadedSymbol) PsiElement(com.intellij.psi.PsiElement) BuildElement(com.google.idea.blaze.base.lang.buildfile.psi.BuildElement) Nullable(javax.annotation.Nullable)

Example 39 with PsiNamedElement

use of com.intellij.psi.PsiNamedElement in project intellij by bazelbuild.

the class TargetReference method resolve.

@Nullable
@Override
public PsiElement resolve() {
    String referencedName = myElement.getName();
    if (referencedName == null) {
        return null;
    }
    PsiNamedElement target = ResolveUtil.findInScope(myElement, referencedName);
    return target != null ? target : null;
}
Also used : PsiNamedElement(com.intellij.psi.PsiNamedElement) Nullable(javax.annotation.Nullable)

Example 40 with PsiNamedElement

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

the class RootSecurityCompletion 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)

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