Search in sources :

Example 41 with Processor

use of com.intellij.util.Processor in project intellij-community by JetBrains.

the class ReferenceChainLink method getGlobalMembers.

@Nullable
List<PsiMember> getGlobalMembers(VirtualFile placeFile, Project project) {
    if (isExpensive(project))
        return null;
    List<PsiMember> candidates = new ArrayList<>();
    AtomicInteger count = new AtomicInteger();
    Processor<PsiMember> processor = member -> {
        if (!(member instanceof PsiMethod && !ApproximateResolver.canHaveArgCount((PsiMethod) member, argCount))) {
            candidates.add(member);
        }
        return count.incrementAndGet() < 42;
    };
    PsiShortNamesCache cache = PsiShortNamesCache.getInstance(project);
    GlobalSearchScope scope = ResolveScopeManager.getInstance(project).getDefaultResolveScope(placeFile);
    if (isCall) {
        if (!cache.processMethodsWithName(referenceName, processor, scope, null)) {
            markExpensive(project);
            return null;
        }
    } else {
        PsiPackage pkg = JavaPsiFacade.getInstance(project).findPackage(referenceName);
        if (pkg != null && pkg.getDirectories(scope).length > 0)
            return null;
        if (!cache.processFieldsWithName(referenceName, processor, scope, null)) {
            markExpensive(project);
            return null;
        }
    }
    if (!cache.processClassesWithName(referenceName, processor, scope, null)) {
        markExpensive(project);
        return null;
    }
    return candidates.stream().filter(candidate -> canBeAccessible(placeFile, candidate)).collect(Collectors.toList());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Key(com.intellij.openapi.util.Key) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Set(java.util.Set) ResolveScopeManager(com.intellij.psi.impl.ResolveScopeManager) ContainerUtil(com.intellij.util.containers.ContainerUtil) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Processor(com.intellij.util.Processor) Project(com.intellij.openapi.project.Project) PsiShortNamesCache(com.intellij.psi.search.PsiShortNamesCache) com.intellij.psi(com.intellij.psi) ApproximateResolver(com.intellij.psi.impl.search.ApproximateResolver) NotNull(org.jetbrains.annotations.NotNull) PsiShortNamesCache(com.intellij.psi.search.PsiShortNamesCache) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ArrayList(java.util.ArrayList) Nullable(org.jetbrains.annotations.Nullable)

Example 42 with Processor

use of com.intellij.util.Processor in project intellij-community by JetBrains.

the class JavaCompilingVisitor method buildDescendants.

private static List<PsiClass> buildDescendants(String className, boolean includeSelf, OptimizingSearchHelper searchHelper, CompileContext context) {
    if (!searchHelper.doOptimizing())
        return Collections.emptyList();
    final SearchScope scope = context.getOptions().getScope();
    if (!(scope instanceof GlobalSearchScope))
        return Collections.emptyList();
    final PsiShortNamesCache cache = PsiShortNamesCache.getInstance(context.getProject());
    final PsiClass[] classes = cache.getClassesByName(className, (GlobalSearchScope) scope);
    final List<PsiClass> results = new ArrayList<>();
    final Processor<PsiClass> processor = aClass -> {
        results.add(aClass);
        return true;
    };
    for (PsiClass aClass : classes) {
        ClassInheritorsSearch.search(aClass, scope, true).forEach(processor);
    }
    if (includeSelf) {
        Collections.addAll(results, classes);
    }
    return results;
}
Also used : MalformedPatternException(com.intellij.structuralsearch.MalformedPatternException) CommentMatchingStrategy(com.intellij.structuralsearch.impl.matcher.strategies.CommentMatchingStrategy) ExprMatchingStrategy(com.intellij.structuralsearch.impl.matcher.strategies.ExprMatchingStrategy) JavaDocMatchingStrategy(com.intellij.structuralsearch.impl.matcher.strategies.JavaDocMatchingStrategy) NonNls(org.jetbrains.annotations.NonNls) SearchScope(com.intellij.psi.search.SearchScope) com.intellij.structuralsearch.impl.matcher.handlers(com.intellij.structuralsearch.impl.matcher.handlers) com.intellij.structuralsearch.impl.matcher.filters(com.intellij.structuralsearch.impl.matcher.filters) ArrayList(java.util.ArrayList) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) RegExpPredicate(com.intellij.structuralsearch.impl.matcher.predicates.RegExpPredicate) Matcher(java.util.regex.Matcher) JavaCompiledPattern(com.intellij.structuralsearch.impl.matcher.JavaCompiledPattern) PsiShortNamesCache(com.intellij.psi.search.PsiShortNamesCache) DocValuesIterator(com.intellij.structuralsearch.impl.matcher.iterators.DocValuesIterator) NodeIterator(com.intellij.dupLocator.iterators.NodeIterator) MatchingStrategy(com.intellij.structuralsearch.impl.matcher.strategies.MatchingStrategy) SSRBundle(com.intellij.structuralsearch.SSRBundle) CompiledPattern(com.intellij.structuralsearch.impl.matcher.CompiledPattern) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiDocTag(com.intellij.psi.javadoc.PsiDocTag) Nullable(org.jetbrains.annotations.Nullable) PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) List(java.util.List) Processor(com.intellij.util.Processor) com.intellij.psi(com.intellij.psi) ClassInheritorsSearch(com.intellij.psi.search.searches.ClassInheritorsSearch) UnsupportedPatternException(com.intellij.structuralsearch.UnsupportedPatternException) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) PsiShortNamesCache(com.intellij.psi.search.PsiShortNamesCache) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ArrayList(java.util.ArrayList)

Example 43 with Processor

use of com.intellij.util.Processor in project intellij-plugins by JetBrains.

the class InterceptorRefResolveConverterImpl method fromString.

public InterceptorOrStackBase fromString(@Nullable @NonNls final String name, final ConvertContext context) {
    if (name == null) {
        return null;
    }
    final Condition<InterceptorOrStackBase> nameCondition = interceptorOrStackBase -> name.equals(interceptorOrStackBase.getName().getStringValue());
    final Ref<InterceptorOrStackBase> resolveResult = new Ref<>();
    final Processor<StrutsPackage> processor = strutsPackage -> {
        final InterceptorOrStackBase result = ContainerUtil.find(getAllInterceptors(strutsPackage), nameCondition);
        if (result != null) {
            resolveResult.set(result);
            return false;
        }
        return true;
    };
    final StrutsPackageHierarchyWalker walker = new StrutsPackageHierarchyWalker(ConverterUtil.getCurrentStrutsPackage(context), processor);
    walker.walkUp();
    return resolveResult.get();
}
Also used : Collection(java.util.Collection) NonNls(org.jetbrains.annotations.NonNls) InterceptorOrStackBase(com.intellij.struts2.dom.struts.strutspackage.InterceptorOrStackBase) ContainerUtil(com.intellij.util.containers.ContainerUtil) StrutsPackageHierarchyWalker(com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) SmartList(com.intellij.util.SmartList) Processor(com.intellij.util.Processor) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) ConverterUtil(com.intellij.struts2.dom.ConverterUtil) InterceptorRefResolveConverter(com.intellij.struts2.dom.struts.strutspackage.InterceptorRefResolveConverter) ConvertContext(com.intellij.util.xml.ConvertContext) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) Condition(com.intellij.openapi.util.Condition) StrutsPackageHierarchyWalker(com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker) Ref(com.intellij.openapi.util.Ref) InterceptorOrStackBase(com.intellij.struts2.dom.struts.strutspackage.InterceptorOrStackBase) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage)

Example 44 with Processor

use of com.intellij.util.Processor in project intellij-plugins by JetBrains.

the class ResultTypeResolvingConverterImpl method fromString.

public ResultType fromString(@Nullable @NonNls final String name, final ConvertContext context) {
    if (StringUtil.isEmpty(name)) {
        return null;
    }
    final Condition<ResultType> nameCondition = resultType -> Comparing.equal(name, resultType.getName().getStringValue());
    final Ref<ResultType> resolveResult = new Ref<>();
    final Processor<StrutsPackage> processor = strutsPackage -> {
        final ResultType result = ContainerUtil.find(strutsPackage.getResultTypes(), nameCondition);
        if (result != null) {
            resolveResult.set(result);
            return false;
        }
        return true;
    };
    final StrutsPackageHierarchyWalker walker = new StrutsPackageHierarchyWalker(ConverterUtil.getCurrentStrutsPackage(context), processor);
    walker.walkUp();
    return resolveResult.get();
}
Also used : StringUtil(com.intellij.openapi.util.text.StringUtil) Collection(java.util.Collection) NonNls(org.jetbrains.annotations.NonNls) ContainerUtil(com.intellij.util.containers.ContainerUtil) StrutsPackageHierarchyWalker(com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Comparing(com.intellij.openapi.util.Comparing) SmartList(com.intellij.util.SmartList) ResultType(com.intellij.struts2.dom.struts.strutspackage.ResultType) Processor(com.intellij.util.Processor) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) ConverterUtil(com.intellij.struts2.dom.ConverterUtil) ResultTypeResolvingConverter(com.intellij.struts2.dom.struts.action.ResultTypeResolvingConverter) ConvertContext(com.intellij.util.xml.ConvertContext) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) Condition(com.intellij.openapi.util.Condition) StrutsPackageHierarchyWalker(com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker) Ref(com.intellij.openapi.util.Ref) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) ResultType(com.intellij.struts2.dom.struts.strutspackage.ResultType)

Example 45 with Processor

use of com.intellij.util.Processor in project intellij-plugins by JetBrains.

the class DefaultInterceptorRefResolveConverterImpl method fromString.

public InterceptorStack fromString(@Nullable @NonNls final String name, final ConvertContext context) {
    if (name == null) {
        return null;
    }
    final Condition<InterceptorStack> nameCondition = interceptorStack -> name.equals(interceptorStack.getName().getStringValue());
    final Ref<InterceptorStack> resolveResult = new Ref<>();
    final Processor<StrutsPackage> processor = strutsPackage -> {
        final InterceptorStack result = ContainerUtil.find(strutsPackage.getInterceptorStacks(), nameCondition);
        if (result != null) {
            resolveResult.set(result);
            return false;
        }
        return true;
    };
    final StrutsPackageHierarchyWalker walker = new StrutsPackageHierarchyWalker(getCurrentStrutsPackage(context), processor);
    walker.walkUp();
    return resolveResult.get();
}
Also used : DefaultInterceptorRefResolveConverter(com.intellij.struts2.dom.struts.strutspackage.DefaultInterceptorRefResolveConverter) Collection(java.util.Collection) NonNls(org.jetbrains.annotations.NonNls) ContainerUtil(com.intellij.util.containers.ContainerUtil) StrutsPackageHierarchyWalker(com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) SmartList(com.intellij.util.SmartList) Processor(com.intellij.util.Processor) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) InterceptorStack(com.intellij.struts2.dom.struts.strutspackage.InterceptorStack) ConvertContext(com.intellij.util.xml.ConvertContext) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) DomUtil(com.intellij.util.xml.DomUtil) Condition(com.intellij.openapi.util.Condition) StrutsPackageHierarchyWalker(com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker) Ref(com.intellij.openapi.util.Ref) InterceptorStack(com.intellij.struts2.dom.struts.strutspackage.InterceptorStack) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage)

Aggregations

Processor (com.intellij.util.Processor)83 NotNull (org.jetbrains.annotations.NotNull)65 Project (com.intellij.openapi.project.Project)49 Nullable (org.jetbrains.annotations.Nullable)49 ContainerUtil (com.intellij.util.containers.ContainerUtil)42 com.intellij.psi (com.intellij.psi)31 List (java.util.List)28 ApplicationManager (com.intellij.openapi.application.ApplicationManager)25 StringUtil (com.intellij.openapi.util.text.StringUtil)25 VirtualFile (com.intellij.openapi.vfs.VirtualFile)25 java.util (java.util)25 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)24 ProgressManager (com.intellij.openapi.progress.ProgressManager)21 Logger (com.intellij.openapi.diagnostic.Logger)20 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)20 NonNls (org.jetbrains.annotations.NonNls)18 Ref (com.intellij.openapi.util.Ref)16 Collection (java.util.Collection)16 SmartList (com.intellij.util.SmartList)14 Document (com.intellij.openapi.editor.Document)13