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);
}
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());
}
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;
}
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);
}
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);
}
Aggregations