use of com.intellij.util.FilteredQuery in project intellij-community by JetBrains.
the class CodeInsightUtil method processSubTypes.
public static void processSubTypes(PsiType psiType, final PsiElement context, boolean getRawSubtypes, @NotNull final PrefixMatcher matcher, Consumer<PsiType> consumer) {
int arrayDim = psiType.getArrayDimensions();
psiType = psiType.getDeepComponentType();
if (!(psiType instanceof PsiClassType))
return;
PsiClassType baseType = JavaCompletionUtil.originalize((PsiClassType) psiType);
PsiClassType.ClassResolveResult baseResult = baseType.resolveGenerics();
PsiClass baseClass = baseResult.getElement();
PsiSubstitutor baseSubstitutor = baseResult.getSubstitutor();
if (baseClass == null)
return;
GlobalSearchScope scope = context.getResolveScope();
Processor<PsiClass> inheritorsProcessor = createInheritorsProcessor(context, baseType, arrayDim, getRawSubtypes, consumer, baseClass, baseSubstitutor);
addContextTypeArguments(context, baseType, inheritorsProcessor);
if (baseClass.hasModifierProperty(PsiModifier.FINAL))
return;
if (matcher.getPrefix().length() > 2) {
JBTreeTraverser<PsiClass> traverser = new JBTreeTraverser<>(c -> Arrays.asList(c.getInnerClasses()));
AllClassesGetter.processJavaClasses(matcher, context.getProject(), scope, psiClass -> {
Iterable<PsiClass> inheritors = traverser.withRoot(psiClass).filter(c -> c.isInheritor(baseClass, true));
return ContainerUtil.process(inheritors, inheritorsProcessor);
});
} else {
Query<PsiClass> baseQuery = ClassInheritorsSearch.search(baseClass, scope, true, true, false);
Query<PsiClass> query = new FilteredQuery<>(baseQuery, psiClass -> !(psiClass instanceof PsiTypeParameter) && ContainerUtil.exists(JavaCompletionUtil.getAllLookupStrings(psiClass), matcher::prefixMatches));
query.forEach(inheritorsProcessor);
}
}
use of com.intellij.util.FilteredQuery in project intellij-community by JetBrains.
the class ResourceFileUtil method findResourceFileInScope.
@Nullable
public static VirtualFile findResourceFileInScope(final String resourceName, final Project project, final GlobalSearchScope scope) {
int index = resourceName.lastIndexOf('/');
String packageName = index >= 0 ? resourceName.substring(0, index).replace('/', '.') : "";
final String fileName = index >= 0 ? resourceName.substring(index + 1) : resourceName;
final VirtualFile dir = new FilteredQuery<>(DirectoryIndex.getInstance(project).getDirectoriesByPackageName(packageName, false), file -> {
final VirtualFile child = file.findChild(fileName);
return child != null && scope.contains(child);
}).findFirst();
return dir != null ? dir.findChild(fileName) : null;
}
Aggregations