public static Query<PsiClass> search(final PsiClass aClass, SearchScope scope, boolean includeAnonymous, final boolean checkInheritance) { final Query<PsiClass> raw = INSTANCE.createUniqueResultsQuery(new SearchParameters(aClass, scope, includeAnonymous, checkInheritance)); if (!includeAnonymous) { return new FilteredQuery<PsiClass>(raw, new Condition<PsiClass>() { @Override public boolean value(final PsiClass psiClass) { return !(psiClass instanceof PsiAnonymousClass); } }); } return raw; }
@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<VirtualFile>( DirectoryIndex.getInstance(project).getDirectoriesByPackageName(packageName, false), new Condition<VirtualFile>() { @Override public boolean value(final VirtualFile file) { final VirtualFile child = file.findChild(fileName); return child != null && scope.contains(child); } }).findFirst(); return dir != null ? dir.findChild(fileName) : null; }
@NotNull private static Query<PsiMember> createQuery(@NotNull PsiClass target, @NotNull PsiClass annClass) { PsiImmediateClassType type = new PsiImmediateClassType(target, PsiSubstitutor.EMPTY); return new FilteredQuery<>(AnnotatedMembersSearch.search(annClass), psiMember -> ReadAction.compute(() -> { if(psiMember instanceof PsiMethod && !psiMember.hasModifierProperty(PsiModifier.STATIC)) { PsiParameterList parameterList = ((PsiMethod) psiMember).getParameterList(); PsiParameter[] parameters = parameterList.getParameters(); if(parameters.length == 1 && parameters[0].getType().equals(type)) { return true; } } return false; })); }
private static PsiDirectory[] getPackageDirectories(Project project, String rootPackage, final GlobalSearchScope scope) { final PsiManager manager = PsiManager.getInstance(project); Query<VirtualFile> query = DirectoryIndex.getInstance(scope.getProject()).getDirectoriesByPackageName(rootPackage, true); query = new FilteredQuery<>(query, scope::contains); List<PsiDirectory> directories = ContainerUtil.mapNotNull(query.findAll(), manager::findDirectory); return directories.toArray(new PsiDirectory[directories.size()]); }
@Override public Query<VirtualFile> getDirsByPackageName(@NotNull String packageName, boolean includeLibrarySources) { return new FilteredQuery<VirtualFile>(myDirectoryIndex.getDirectoriesByPackageName(packageName, includeLibrarySources), myDirCondition); }
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); } }