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