Search in sources :

Example 61 with PsiNamedElement

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

the class PyTestFinder method findClassesForTest.

@NotNull
@Override
public Collection<PsiElement> findClassesForTest(@NotNull PsiElement element) {
    final PyFunction sourceFunction = PsiTreeUtil.getParentOfType(element, PyFunction.class);
    final PyClass source = PsiTreeUtil.getParentOfType(element, PyClass.class);
    if (sourceFunction == null && source == null)
        return Collections.emptySet();
    List<Pair<? extends PsiNamedElement, Integer>> classesWithWeights = new ArrayList<>();
    final List<Pair<String, Integer>> possibleNames = new ArrayList<>();
    if (source != null)
        possibleNames.addAll(TestFinderHelper.collectPossibleClassNamesWithWeights(source.getName()));
    if (sourceFunction != null)
        possibleNames.addAll(TestFinderHelper.collectPossibleClassNamesWithWeights(sourceFunction.getName()));
    for (Pair<String, Integer> eachNameWithWeight : possibleNames) {
        for (PyClass eachClass : PyClassNameIndex.find(eachNameWithWeight.first, element.getProject(), GlobalSearchScope.projectScope(element.getProject()))) {
            if (!PyTestUtil.isPyTestClass(eachClass, null))
                classesWithWeights.add(new Pair<PsiNamedElement, Integer>(eachClass, eachNameWithWeight.second));
        }
        for (PyFunction function : PyFunctionNameIndex.find(eachNameWithWeight.first, element.getProject(), GlobalSearchScope.projectScope(element.getProject()))) {
            if (!PyTestUtil.isPyTestFunction(function))
                classesWithWeights.add(new Pair<PsiNamedElement, Integer>(function, eachNameWithWeight.second));
        }
    }
    return TestFinderHelper.getSortedElements(classesWithWeights, false);
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) PyFunction(com.jetbrains.python.psi.PyFunction) PsiNamedElement(com.intellij.psi.PsiNamedElement) ArrayList(java.util.ArrayList) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 62 with PsiNamedElement

use of com.intellij.psi.PsiNamedElement in project WebStormRequireJsPlugin by Fedott.

the class RequirejsTestCase method assertUrlReference.

protected void assertUrlReference(PsiReference reference, String expectedUrl) {
    PsiElement referenceElement = reference.resolve();
    assertTrue(referenceElement instanceof PsiNamedElement);
    assertEquals(expectedUrl, ((PsiNamedElement) referenceElement).getName());
}
Also used : PsiNamedElement(com.intellij.psi.PsiNamedElement) PsiElement(com.intellij.psi.PsiElement)

Example 63 with PsiNamedElement

use of com.intellij.psi.PsiNamedElement in project Perl5-IDEA by Camelcade.

the class PerlStructureViewElement method getAlphaSortKey.

@NotNull
@Override
public String getAlphaSortKey() {
    assert myElement instanceof PsiNamedElement;
    PerlExportDescriptor exportDescriptor = getExportDescriptor();
    if (exportDescriptor != null) {
        return exportDescriptor.getImportedName();
    }
    String name = ((PsiNamedElement) myElement).getName();
    if (name == null) {
        name = "Empty named " + myElement;
    }
    return name;
}
Also used : PerlExportDescriptor(com.perl5.lang.perl.extensions.packageprocessor.PerlExportDescriptor) PsiNamedElement(com.intellij.psi.PsiNamedElement) NotNull(org.jetbrains.annotations.NotNull)

Example 64 with PsiNamedElement

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

the class FuncallReference method resolve.

@Nullable
@Override
public PsiNamedElement resolve() {
    String functionName = myElement.getFunctionName();
    // first search in local scope (e.g. function passed in as an arg).
    PsiNamedElement element = ResolveUtil.findInScope(myElement, functionName);
    if (element != null) {
        return element;
    }
    BuildFile file = myElement.getContainingFile();
    if (functionName == null || file == null) {
        return null;
    }
    return file.findFunctionInScope(functionName);
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) PsiNamedElement(com.intellij.psi.PsiNamedElement) Nullable(javax.annotation.Nullable)

Example 65 with PsiNamedElement

use of com.intellij.psi.PsiNamedElement in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoFieldNameMacro method fieldNames.

private static Set<String> fieldNames(ExpressionContext context) {
    PsiElement psiElement = context != null ? context.getPsiElementAtStartOffset() : null;
    GoFieldDeclaration fieldDeclaration = PsiTreeUtil.getNonStrictParentOfType(psiElement, GoFieldDeclaration.class);
    if (fieldDeclaration == null) {
        return Collections.emptySet();
    }
    return ContainerUtil.map2LinkedSet(fieldDeclaration.getFieldDefinitionList(), PsiNamedElement::getName);
}
Also used : GoFieldDeclaration(com.goide.psi.GoFieldDeclaration) PsiNamedElement(com.intellij.psi.PsiNamedElement) 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