Java 类com.intellij.psi.scope.processor.FilterScopeProcessor 实例源码

项目:intellij-ce-playground    文件:PsiSwitchLabelStatementImpl.java   
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) {
  if (lastParent == null) return true;

  final PsiSwitchStatement switchStatement = getEnclosingSwitchStatement();
  if (switchStatement != null) {
    final PsiExpression expression = switchStatement.getExpression();
    if (expression != null && expression.getType() instanceof PsiClassType) {
      final PsiClass aClass = ((PsiClassType)expression.getType()).resolve();
      if(aClass != null) aClass.processDeclarations(new FilterScopeProcessor(ElementClassFilter.ENUM_CONST, processor), state, this, place);
    }
  }
  return true;
}
项目:intellij-ce-playground    文件:MembersGetter.java   
public void processMembers(final Consumer<LookupElement> results, @Nullable final PsiClass where,
                           final boolean acceptMethods, final boolean searchInheritors) {
  if (where == null || isPrimitiveClass(where)) return;

  final boolean searchFactoryMethods = searchInheritors &&
                                 !CommonClassNames.JAVA_LANG_OBJECT.equals(where.getQualifiedName()) &&
                                 !isPrimitiveClass(where);

  final Project project = myPlace.getProject();
  final GlobalSearchScope scope = myPlace.getResolveScope();

  final PsiClassType baseType = JavaPsiFacade.getElementFactory(project).createType(where);
  Consumer<PsiType> consumer = new Consumer<PsiType>() {
    @Override
    public void consume(PsiType psiType) {
      PsiClass psiClass = PsiUtil.resolveClassInType(psiType);
      if (psiClass == null) {
        return;
      }
      psiClass = CompletionUtil.getOriginalOrSelf(psiClass);
      if (mayProcessMembers(psiClass)) {
        final FilterScopeProcessor<PsiElement> declProcessor = new FilterScopeProcessor<PsiElement>(TrueFilter.INSTANCE);
        psiClass.processDeclarations(declProcessor, ResolveState.initial(), null, myPlace);
        doProcessMembers(acceptMethods, results, psiType == baseType, declProcessor.getResults());

        String name = psiClass.getName();
        if (name != null && searchFactoryMethods) {
          Collection<PsiMember> factoryMethods = JavaStaticMemberTypeIndex.getInstance().getStaticMembers(name, project, scope);
          doProcessMembers(acceptMethods, results, false, factoryMethods);
        }
      }
    }
  };
  consumer.consume(baseType);
  if (searchInheritors && !CommonClassNames.JAVA_LANG_OBJECT.equals(where.getQualifiedName())) {
    CodeInsightUtil.processSubTypes(baseType, myPlace, true, PrefixMatcher.ALWAYS_TRUE, consumer);
  }
}
项目:tools-idea    文件:PsiClassImplUtil.java   
@NotNull
private static MembersMap buildAllMaps(@NotNull PsiClass psiClass) {
  final List<Pair<PsiMember, PsiSubstitutor>> classes = new ArrayList<Pair<PsiMember, PsiSubstitutor>>();
  final List<Pair<PsiMember, PsiSubstitutor>> fields = new ArrayList<Pair<PsiMember, PsiSubstitutor>>();
  final List<Pair<PsiMember, PsiSubstitutor>> methods = new ArrayList<Pair<PsiMember, PsiSubstitutor>>();

  FilterScopeProcessor<MethodCandidateInfo> processor = new FilterScopeProcessor<MethodCandidateInfo>(
    new OrFilter(ElementClassFilter.METHOD, ElementClassFilter.FIELD, ElementClassFilter.CLASS)) {
    @Override
    protected void add(PsiElement element, PsiSubstitutor substitutor) {
      if (element instanceof PsiMethod) {
        methods.add(Pair.create((PsiMember)element, substitutor));
      }
      else if (element instanceof PsiField) {
        fields.add(Pair.create((PsiMember)element, substitutor));
      }
      else if (element instanceof PsiClass) {
        classes.add(Pair.create((PsiMember)element, substitutor));
      }
    }
  };
  processDeclarationsInClassNotCached(psiClass, processor, ResolveState.initial(), null, null, psiClass, false,
                                      PsiUtil.getLanguageLevel(psiClass));

  MembersMap result = new MembersMap(MemberType.class);
  result.put(MemberType.CLASS, generateMapByList(classes));
  result.put(MemberType.METHOD, generateMapByList(methods));
  result.put(MemberType.FIELD, generateMapByList(fields));
  return result;
}
项目:tools-idea    文件:PsiSwitchLabelStatementImpl.java   
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) {
  if (lastParent == null) return true;

  final PsiSwitchStatement switchStatement = getEnclosingSwitchStatement();
  if (switchStatement != null) {
    final PsiExpression expression = switchStatement.getExpression();
    if (expression != null && expression.getType() instanceof PsiClassType) {
      final PsiClass aClass = ((PsiClassType)expression.getType()).resolve();
      if(aClass != null) aClass.processDeclarations(new FilterScopeProcessor(ElementClassFilter.ENUM_CONST, processor), state, this, place);
    }
  }
  return true;
}
项目:tools-idea    文件:MembersGetter.java   
public void processMembers(final Consumer<LookupElement> results, @Nullable final PsiClass where,
                           final boolean acceptMethods, final boolean searchInheritors) {
  if (where == null || CommonClassNames.JAVA_LANG_STRING.equals(where.getQualifiedName())) return;

  final boolean searchFactoryMethods = searchInheritors &&
                                 !CommonClassNames.JAVA_LANG_OBJECT.equals(where.getQualifiedName()) &&
                                 !CommonClassNames.JAVA_LANG_STRING.equals(where.getQualifiedName());

  final Project project = myPlace.getProject();
  final GlobalSearchScope scope = myPlace.getResolveScope();

  final PsiClassType baseType = JavaPsiFacade.getElementFactory(project).createType(where);
  Consumer<PsiType> consumer = new Consumer<PsiType>() {
    @Override
    public void consume(PsiType psiType) {
      PsiClass psiClass = PsiUtil.resolveClassInType(psiType);
      if (psiClass == null) {
        return;
      }
      psiClass = CompletionUtil.getOriginalOrSelf(psiClass);
      if (mayProcessMembers(psiClass)) {
        final FilterScopeProcessor<PsiElement> declProcessor = new FilterScopeProcessor<PsiElement>(TrueFilter.INSTANCE);
        psiClass.processDeclarations(declProcessor, ResolveState.initial(), null, myPlace);
        doProcessMembers(acceptMethods, results, psiType != baseType, declProcessor.getResults());

        String name = psiClass.getName();
        if (name != null && searchFactoryMethods) {
          Collection<PsiMember> factoryMethods = JavaStaticMemberTypeIndex.getInstance().getStaticMembers(name, project, scope);
          doProcessMembers(acceptMethods, results, psiType != baseType, factoryMethods);
        }
      }
    }
  };
  consumer.consume(baseType);
  if (searchInheritors && !CommonClassNames.JAVA_LANG_OBJECT.equals(where.getQualifiedName())) {
    CodeInsightUtil.processSubTypes(baseType, myPlace, true, PrefixMatcher.ALWAYS_TRUE, consumer);
  }
}
项目:consulo-java    文件:PsiSwitchLabelStatementImpl.java   
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) {
  if (lastParent == null) return true;

  final PsiSwitchStatement switchStatement = getEnclosingSwitchStatement();
  if (switchStatement != null) {
    final PsiExpression expression = switchStatement.getExpression();
    if (expression != null && expression.getType() instanceof PsiClassType) {
      final PsiClass aClass = ((PsiClassType)expression.getType()).resolve();
      if(aClass != null) aClass.processDeclarations(new FilterScopeProcessor(ElementClassFilter.ENUM_CONST, processor), state, this, place);
    }
  }
  return true;
}
项目:consulo-java    文件:PsiImplUtil.java   
@NotNull
public static Object[] getReferenceVariantsByFilter(@NotNull PsiJavaCodeReferenceElement reference, @NotNull ElementFilter filter)
{
    FilterScopeProcessor processor = new FilterScopeProcessor(filter);
    PsiScopesUtil.resolveAndWalk(processor, reference, null, true);
    return processor.getResults().toArray();
}
项目:intellij-ce-playground    文件:PsiClassImplUtil.java   
@Nullable
@Override
protected Map<String, List<Pair<PsiMember, PsiSubstitutor>>> create(final MemberType key) {
  final Map<String, List<Pair<PsiMember, PsiSubstitutor>>> map = new THashMap<String, List<Pair<PsiMember, PsiSubstitutor>>>();

  final List<Pair<PsiMember, PsiSubstitutor>> allMembers = new ArrayList<Pair<PsiMember, PsiSubstitutor>>();
  map.put(ALL, allMembers);

  ElementClassFilter filter = key == MemberType.CLASS ? ElementClassFilter.CLASS :
                              key == MemberType.METHOD ? ElementClassFilter.METHOD :
                              ElementClassFilter.FIELD;
  final ElementClassHint classHint = new ElementClassHint() {
    @Override
    public boolean shouldProcess(DeclarationKind kind) {
      return key == MemberType.CLASS && kind == DeclarationKind.CLASS ||
             key == MemberType.FIELD && (kind == DeclarationKind.FIELD || kind == DeclarationKind.ENUM_CONST) ||
             key == MemberType.METHOD && kind == DeclarationKind.METHOD;
    }
  };
  FilterScopeProcessor<MethodCandidateInfo> processor = new FilterScopeProcessor<MethodCandidateInfo>(filter) {
    @Override
    protected void add(@NotNull PsiElement element, @NotNull PsiSubstitutor substitutor) {
      if (key == MemberType.CLASS && element instanceof PsiClass ||
          key == MemberType.METHOD && element instanceof PsiMethod ||
          key == MemberType.FIELD && element instanceof PsiField) {
        Pair<PsiMember, PsiSubstitutor> info = Pair.create((PsiMember)element, substitutor);
        allMembers.add(info);
        String currentName = ((PsiMember)element).getName();
        List<Pair<PsiMember, PsiSubstitutor>> listByName = map.get(currentName);
        if (listByName == null) {
          listByName = new ArrayList<Pair<PsiMember, PsiSubstitutor>>(1);
          map.put(currentName, listByName);
        }
        listByName.add(info);
      }
    }

    @Override
    public <K> K getHint(@NotNull Key<K> hintKey) {
      //noinspection unchecked
      return ElementClassHint.KEY == hintKey ? (K)classHint : super.getHint(hintKey);
    }
  };

  processDeclarationsInClassNotCached(myPsiClass, processor, ResolveState.initial(), null, null, myPsiClass, false,
                                      PsiUtil.getLanguageLevel(myPsiClass), myResolveScope);
  return map;
}
项目:intellij-ce-playground    文件:PsiImportStaticReferenceElementImpl.java   
@Override
public void processVariants(@NotNull PsiScopeProcessor processor) {
  FilterScopeProcessor proc = new FilterScopeProcessor(new ClassFilter(PsiModifierListOwner.class), processor);
  PsiScopesUtil.resolveAndWalk(proc, this, null, true);
}
项目:intellij-ce-playground    文件:PsiMethodReferenceExpressionImpl.java   
@Override
public void processVariants(@NotNull final PsiScopeProcessor processor) {
  final FilterScopeProcessor proc = new FilterScopeProcessor(ElementClassFilter.METHOD, processor);
  PsiScopesUtil.resolveAndWalk(proc, this, null, true);
}
项目:intellij-ce-playground    文件:PsiDocMethodOrFieldRef.java   
public static PsiVariable[] getAllVariables(PsiElement scope, PsiElement place) {
  final SmartList<PsiVariable> result = new SmartList<PsiVariable>();
  scope.processDeclarations(new FilterScopeProcessor<PsiVariable>(ElementClassFilter.VARIABLE, result), ResolveState.initial(), null, place);
  return result.toArray(new PsiVariable[result.size()]);
}
项目:intellij-ce-playground    文件:PsiDocMethodOrFieldRef.java   
public static PsiMethod[] getAllMethods(PsiElement scope, PsiElement place) {
  final SmartList<PsiMethod> result = new SmartList<PsiMethod>();
  scope.processDeclarations(new FilterScopeProcessor<PsiMethod>(ElementClassFilter.METHOD, result), ResolveState.initial(), null, place);
  return result.toArray(new PsiMethod[result.size()]);
}
项目:intellij-ce-playground    文件:PsiImplUtil.java   
@NotNull
public static Object[] getReferenceVariantsByFilter(@NotNull PsiJavaCodeReferenceElement reference, @NotNull ElementFilter filter) {
  FilterScopeProcessor processor = new FilterScopeProcessor(filter);
  PsiScopesUtil.resolveAndWalk(processor, reference, null, true);
  return processor.getResults().toArray();
}
项目:tools-idea    文件:PsiImportStaticReferenceElementImpl.java   
@Override
public void processVariants(@NotNull PsiScopeProcessor processor) {
  FilterScopeProcessor proc = new FilterScopeProcessor(new ClassFilter(PsiModifierListOwner.class), processor);
  PsiScopesUtil.resolveAndWalk(proc, this, null, true);
}
项目:tools-idea    文件:PsiMethodReferenceExpressionImpl.java   
@Override
public void processVariants(@NotNull final PsiScopeProcessor processor) {
  final FilterScopeProcessor proc = new FilterScopeProcessor(ElementClassFilter.METHOD, processor);
  PsiScopesUtil.resolveAndWalk(proc, this, null, true);
}
项目:tools-idea    文件:PsiDocMethodOrFieldRef.java   
public static PsiVariable[] getAllVariables(PsiElement scope, PsiElement place) {
  final SmartList<PsiVariable> result = new SmartList<PsiVariable>();
  scope.processDeclarations(new FilterScopeProcessor<PsiVariable>(ElementClassFilter.VARIABLE, result), ResolveState.initial(), null, place);
  return result.toArray(new PsiVariable[result.size()]);
}
项目:tools-idea    文件:PsiDocMethodOrFieldRef.java   
public static PsiMethod[] getAllMethods(PsiElement scope, PsiElement place) {
  final SmartList<PsiMethod> result = new SmartList<PsiMethod>();
  scope.processDeclarations(new FilterScopeProcessor<PsiMethod>(ElementClassFilter.METHOD, result), ResolveState.initial(), null, place);
  return result.toArray(new PsiMethod[result.size()]);
}
项目:tools-idea    文件:PsiImplUtil.java   
@NotNull
public static Object[] getReferenceVariantsByFilter(@NotNull PsiJavaCodeReferenceElement reference, @NotNull ElementFilter filter) {
  FilterScopeProcessor processor = new FilterScopeProcessor(filter);
  PsiScopesUtil.resolveAndWalk(processor, reference, null, true);
  return processor.getResults().toArray();
}
项目:consulo-java    文件:PsiClassImplUtil.java   
@Nullable
@Override
protected Map<String, PsiMember[]> create(final MemberType key)
{
    final Map<String, List<PsiMember>> map = ContainerUtil.newTroveMap();

    final List<PsiMember> allMembers = ContainerUtil.newArrayList();
    map.put(ALL, allMembers);

    ElementClassFilter filter = key == MemberType.CLASS ? ElementClassFilter.CLASS : key == MemberType.METHOD ? ElementClassFilter.METHOD : ElementClassFilter.FIELD;
    final ElementClassHint classHint = new ElementClassHint()
    {
        @Override
        public boolean shouldProcess(DeclarationKind kind)
        {
            return key == MemberType.CLASS && kind == DeclarationKind.CLASS || key == MemberType.FIELD && (kind == DeclarationKind.FIELD || kind == DeclarationKind.ENUM_CONST) || key ==
                    MemberType.METHOD && kind == DeclarationKind.METHOD;
        }
    };
    FilterScopeProcessor<MethodCandidateInfo> processor = new FilterScopeProcessor<MethodCandidateInfo>(filter)
    {
        @Override
        protected void add(@NotNull PsiElement element, @NotNull PsiSubstitutor substitutor)
        {
            if(key == MemberType.CLASS && element instanceof PsiClass || key == MemberType.METHOD && element instanceof PsiMethod || key == MemberType.FIELD && element instanceof PsiField)
            {
                allMembers.add((PsiMember) element);
                String currentName = ((PsiMember) element).getName();
                List<PsiMember> listByName = map.get(currentName);
                if(listByName == null)
                {
                    listByName = ContainerUtil.newSmartList();
                    map.put(currentName, listByName);
                }
                listByName.add((PsiMember) element);
            }
        }

        @Override
        public <K> K getHint(@NotNull Key<K> hintKey)
        {
            //noinspection unchecked
            return ElementClassHint.KEY == hintKey ? (K) classHint : super.getHint(hintKey);
        }
    };

    processDeclarationsInClassNotCached(myPsiClass, processor, ResolveState.initial(), null, null, myPsiClass, false, PsiUtil.getLanguageLevel(myPsiClass), myResolveScope);
    Map<String, PsiMember[]> result = ContainerUtil.newTroveMap();
    for(String name : map.keySet())
    {
        result.put(name, map.get(name).toArray(PsiMember.EMPTY_ARRAY));
    }
    return result;
}
项目:consulo-java    文件:PsiImportStaticReferenceElementImpl.java   
@Override
public void processVariants(PsiScopeProcessor processor) {
  FilterScopeProcessor proc = new FilterScopeProcessor(new ClassFilter(PsiModifierListOwner.class), processor);
  PsiScopesUtil.resolveAndWalk(proc, this, null, true);
}
项目:consulo-java    文件:PsiMethodReferenceExpressionImpl.java   
@Override
public void processVariants(@NotNull final PsiScopeProcessor processor)
{
    final FilterScopeProcessor proc = new FilterScopeProcessor(ElementClassFilter.METHOD, processor);
    PsiScopesUtil.resolveAndWalk(proc, this, null, true);
}
项目:consulo-java    文件:PsiDocMethodOrFieldRef.java   
public static PsiVariable[] getAllVariables(PsiElement scope, PsiElement place) {
  final SmartList<PsiVariable> result = new SmartList<PsiVariable>();
  scope.processDeclarations(new FilterScopeProcessor<PsiVariable>(ElementClassFilter.VARIABLE, result), ResolveState.initial(), null, place);
  return result.toArray(new PsiVariable[result.size()]);
}
项目:consulo-java    文件:PsiDocMethodOrFieldRef.java   
public static PsiMethod[] getAllMethods(PsiElement scope, PsiElement place) {
  final SmartList<PsiMethod> result = new SmartList<PsiMethod>();
  scope.processDeclarations(new FilterScopeProcessor<PsiMethod>(ElementClassFilter.METHOD, result), ResolveState.initial(), null, place);
  return result.toArray(new PsiMethod[result.size()]);
}
项目:consulo-java    文件:MembersGetter.java   
public void processMembers(final Consumer<LookupElement> results, @Nullable final PsiClass where, final boolean acceptMethods, final boolean searchInheritors)
{
    if(where == null || isPrimitiveClass(where))
    {
        return;
    }

    final boolean searchFactoryMethods = searchInheritors && !CommonClassNames.JAVA_LANG_OBJECT.equals(where.getQualifiedName()) && !isPrimitiveClass(where);

    final Project project = myPlace.getProject();
    final GlobalSearchScope scope = myPlace.getResolveScope();

    final PsiClassType baseType = JavaPsiFacade.getElementFactory(project).createType(where);
    Consumer<PsiType> consumer = psiType ->
    {
        PsiClass psiClass = PsiUtil.resolveClassInType(psiType);
        if(psiClass == null)
        {
            return;
        }
        psiClass = CompletionUtil.getOriginalOrSelf(psiClass);
        if(mayProcessMembers(psiClass))
        {
            final FilterScopeProcessor<PsiElement> declProcessor = new FilterScopeProcessor<>(TrueFilter.INSTANCE);
            psiClass.processDeclarations(declProcessor, ResolveState.initial(), null, myPlace);
            doProcessMembers(acceptMethods, results, psiType == baseType, declProcessor.getResults());

            String name = psiClass.getName();
            if(name != null && searchFactoryMethods)
            {
                Collection<PsiMember> factoryMethods = JavaStaticMemberTypeIndex.getInstance().getStaticMembers(name, project, scope);
                doProcessMembers(acceptMethods, results, false, factoryMethods);
            }
        }
    };
    consumer.consume(baseType);
    if(searchInheritors && !CommonClassNames.JAVA_LANG_OBJECT.equals(where.getQualifiedName()))
    {
        CodeInsightUtil.processSubTypes(baseType, myPlace, true, PrefixMatcher.ALWAYS_TRUE, consumer);
    }
}