Java 类com.intellij.util.FilteredQuery 实例源码

项目:intellij-ce-playground    文件:DirectClassInheritorsSearch.java   
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;
}
项目:intellij-ce-playground    文件:ResourceFileUtil.java   
@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;
}
项目:tools-idea    文件:DirectClassInheritorsSearch.java   
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;
}
项目:tools-idea    文件:ResourceFileUtil.java   
@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;
}
项目:consulo-java    文件:GuavaLineMarkerProvider.java   
@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;
    }));
}
项目:consulo    文件:PlatformPackageUtil.java   
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()]);
}
项目:consulo-java    文件:DirectClassInheritorsSearch.java   
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;
}
项目:intellij-ce-playground    文件:ModulePackageIndexImpl.java   
@Override
public Query<VirtualFile> getDirsByPackageName(@NotNull String packageName, boolean includeLibrarySources) {
  return new FilteredQuery<VirtualFile>(myDirectoryIndex.getDirectoriesByPackageName(packageName, includeLibrarySources), myDirCondition);
}
项目:tools-idea    文件:ModulePackageIndexImpl.java   
@Override
public Query<VirtualFile> getDirsByPackageName(@NotNull String packageName, boolean includeLibrarySources) {
  return new FilteredQuery<VirtualFile>(myDirectoryIndex.getDirectoriesByPackageName(packageName, includeLibrarySources), myDirCondition);
}
项目:consulo-java    文件:CodeInsightUtil.java   
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);
    }
}