Java 类com.intellij.psi.PsiFunctionalExpression 实例源码

项目:intellij-ce-playground    文件:ClassImplementationsSearch.java   
public static boolean processImplementations(final PsiClass psiClass, final Processor<PsiElement> processor, SearchScope scope) {
  if (!FunctionalExpressionSearch.search(psiClass, scope).forEach(new Processor<PsiFunctionalExpression>() {
    @Override
    public boolean process(PsiFunctionalExpression expression) {
      return processor.process(expression);
    }
  })) {
    return false;
  }

  final boolean showInterfaces = Registry.is("ide.goto.implementation.show.interfaces");
  return ClassInheritorsSearch.search(psiClass, scope, true).forEach(new PsiElementProcessorAdapter<PsiClass>(new PsiElementProcessor<PsiClass>() {
    public boolean execute(@NotNull PsiClass element) {
      if (!showInterfaces && element.isInterface()) {
        return true;
      }
      return processor.process(element);
    }
  }));
}
项目:consulo-java    文件:MethodImplementationsSearch.java   
public static boolean processImplementations(final PsiMethod psiMethod, final Processor<PsiElement> consumer, final SearchScope searchScope)
{
    if(!FunctionalExpressionSearch.search(psiMethod, searchScope).forEach(new Processor<PsiFunctionalExpression>()
    {
        @Override
        public boolean process(PsiFunctionalExpression expression)
        {
            return consumer.process(expression);
        }
    }))
    {
        return false;
    }
    List<PsiMethod> methods = new ArrayList<PsiMethod>();
    getOverridingMethods(psiMethod, methods, searchScope);
    return ContainerUtil.process(methods, consumer);
}
项目:consulo-java    文件:FunctionalExpressionSearch.java   
public static Query<PsiFunctionalExpression> search(@NotNull final PsiMethod psiMethod, @NotNull final SearchScope scope)
{
    return ApplicationManager.getApplication().runReadAction(new Computable<Query<PsiFunctionalExpression>>()
    {
        @Override
        public Query<PsiFunctionalExpression> compute()
        {
            if(!psiMethod.hasModifierProperty(PsiModifier.STATIC) && !psiMethod.hasModifierProperty(PsiModifier.DEFAULT))
            {
                final PsiClass containingClass = psiMethod.getContainingClass();
                if(containingClass != null)
                {
                    return INSTANCE.createUniqueResultsQuery(new SearchParameters(containingClass, scope));
                }
            }

            return EmptyQuery.getEmptyQuery();
        }
    });
}
项目:intellij-ce-playground    文件:MethodImplementationsSearch.java   
public static boolean processImplementations(final PsiMethod psiMethod, final Processor<PsiElement> consumer,
                                             final SearchScope searchScope) {
  if (!FunctionalExpressionSearch.search(psiMethod, searchScope).forEach(new Processor<PsiFunctionalExpression>() {
    @Override
    public boolean process(PsiFunctionalExpression expression) {
      return consumer.process(expression);
    }
  })) {
    return false;
  }
  List<PsiMethod> methods = new ArrayList<PsiMethod>();
  getOverridingMethods(psiMethod, methods, searchScope);
  return ContainerUtil.process(methods, consumer);
}
项目:intellij-ce-playground    文件:FunctionalExpressionSearch.java   
public static Query<PsiFunctionalExpression> search(@NotNull final PsiMethod psiMethod, @NotNull final SearchScope scope) {
  return ApplicationManager.getApplication().runReadAction(new Computable<Query<PsiFunctionalExpression>>() {
    @Override
    public Query<PsiFunctionalExpression> compute() {
      if (!psiMethod.hasModifierProperty(PsiModifier.STATIC) && !psiMethod.hasModifierProperty(PsiModifier.DEFAULT)) {
        final PsiClass containingClass = psiMethod.getContainingClass();
        if (containingClass != null) {
          return INSTANCE.createUniqueResultsQuery(new SearchParameters(containingClass, scope));
        }
      }

      return EmptyQuery.getEmptyQuery();
    }
  });
}
项目:consulo-java    文件:MarkerType.java   
public static String getSubclassedClassTooltip(@NotNull PsiClass aClass)
{
    PsiElementProcessor.CollectElementsWithLimit<PsiClass> processor = new PsiElementProcessor.CollectElementsWithLimit<>(5, new THashSet<>());
    ClassInheritorsSearch.search(aClass).forEach(new PsiElementProcessorAdapter<>(processor));

    if(processor.isOverflow())
    {
        return DaemonBundle.message(aClass.isInterface() ? "interface.is.implemented.too.many" : "class.is.subclassed.too.many");
    }

    PsiClass[] subclasses = processor.toArray(PsiClass.EMPTY_ARRAY);
    if(subclasses.length == 0)
    {
        final PsiElementProcessor.CollectElementsWithLimit<PsiFunctionalExpression> functionalImplementations = new PsiElementProcessor.CollectElementsWithLimit<>(2, new THashSet<>());
        FunctionalExpressionSearch.search(aClass).forEach(new PsiElementProcessorAdapter<>(functionalImplementations));
        if(!functionalImplementations.getCollection().isEmpty())
        {
            return "Has functional implementations";
        }
        return null;
    }

    Comparator<PsiClass> comparator = PsiClassListCellRenderer.INSTANCE.getComparator();
    Arrays.sort(subclasses, comparator);

    String start = DaemonBundle.message(aClass.isInterface() ? "interface.is.implemented.by.header" : "class.is.subclassed.by.header");
    @NonNls String pattern = "&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"#javaClass/{0}\">{0}</a>";
    return composeText(subclasses, start, pattern, IdeActions.ACTION_GOTO_IMPLEMENTATION);
}
项目:consulo-java    文件:MarkerType.java   
public static void navigateToSubclassedClass(MouseEvent e, @NotNull final PsiClass aClass)
{
    if(DumbService.isDumb(aClass.getProject()))
    {
        DumbService.getInstance(aClass.getProject()).showDumbModeNotification("Navigation to overriding methods is not possible during index update");
        return;
    }

    final PsiElementProcessor.FindElement<PsiClass> collectProcessor = new PsiElementProcessor.FindElement<>();
    final PsiElementProcessor.FindElement<PsiFunctionalExpression> collectExprProcessor = new PsiElementProcessor.FindElement<>();
    if(!ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
        ClassInheritorsSearch.search(aClass).forEach(new PsiElementProcessorAdapter<>(collectProcessor));
        if(collectProcessor.getFoundElement() == null)
        {
            FunctionalExpressionSearch.search(aClass).forEach(new PsiElementProcessorAdapter<>(collectExprProcessor));
        }
    }, SEARCHING_FOR_OVERRIDDEN_METHODS, true, aClass.getProject(), (JComponent) e.getComponent()))
    {
        return;
    }

    final List<NavigatablePsiElement> inheritors = new ArrayList<>();
    ContainerUtil.addIfNotNull(inheritors, collectProcessor.getFoundElement());
    ContainerUtil.addIfNotNull(inheritors, collectExprProcessor.getFoundElement());
    if(inheritors.isEmpty())
    {
        return;
    }
    final PsiClassOrFunctionalExpressionListCellRenderer renderer = new PsiClassOrFunctionalExpressionListCellRenderer();
    final SubclassUpdater subclassUpdater = new SubclassUpdater(aClass, renderer);
    Collections.sort(inheritors, renderer.getComparator());
    PsiElementListNavigator.openTargets(e, inheritors.toArray(new NavigatablePsiElement[inheritors.size()]), subclassUpdater.getCaption(inheritors.size()), CodeInsightBundle.message("goto" +
            ".implementation.findUsages.title", aClass.getName()), renderer, subclassUpdater);
}
项目:consulo-java    文件:MarkerType.java   
@Override
public void run(@NotNull final ProgressIndicator indicator)
{
    super.run(indicator);
    ClassInheritorsSearch.search(myClass, ApplicationManager.getApplication().runReadAction(new Computable<SearchScope>()
    {
        @Override
        public SearchScope compute()
        {
            return myClass.getUseScope();
        }
    }), true).forEach(new CommonProcessors.CollectProcessor<PsiClass>()
    {
        @Override
        public boolean process(final PsiClass o)
        {
            if(!updateComponent(o, myRenderer.getComparator()))
            {
                indicator.cancel();
            }
            indicator.checkCanceled();
            return super.process(o);
        }
    });

    FunctionalExpressionSearch.search(myClass).forEach(new CommonProcessors.CollectProcessor<PsiFunctionalExpression>()
    {
        @Override
        public boolean process(final PsiFunctionalExpression expr)
        {
            if(!updateComponent(expr, myRenderer.getComparator()))
            {
                indicator.cancel();
            }
            indicator.checkCanceled();
            return super.process(expr);
        }
    });
}
项目:consulo-java    文件:MarkerType.java   
@Override
public void run(@NotNull final ProgressIndicator indicator)
{
    super.run(indicator);
    GlobalSearchScope scope = GlobalSearchScope.allScope(PsiUtilCore.getProjectInReadAction(myMethod));
    OverridingMethodsSearch.search(myMethod, scope, true).forEach(new CommonProcessors.CollectProcessor<PsiMethod>()
    {
        @Override
        public boolean process(PsiMethod psiMethod)
        {
            if(!updateComponent(psiMethod, myRenderer.getComparator()))
            {
                indicator.cancel();
            }
            indicator.checkCanceled();
            return super.process(psiMethod);
        }
    });
    PsiClass psiClass = ApplicationManager.getApplication().runReadAction((Computable<PsiClass>) myMethod::getContainingClass);
    FunctionalExpressionSearch.search(psiClass).forEach(new CommonProcessors.CollectProcessor<PsiFunctionalExpression>()
    {
        @Override
        public boolean process(final PsiFunctionalExpression expr)
        {
            if(!updateComponent(expr, myRenderer.getComparator()))
            {
                indicator.cancel();
            }
            indicator.checkCanceled();
            return super.process(expr);
        }
    });
}
项目:consulo-java    文件:SubtypesHierarchyTreeStructure.java   
@Override
@NotNull
protected final Object[] buildChildren(@NotNull final HierarchyNodeDescriptor descriptor)
{
    final Object element = ((TypeHierarchyNodeDescriptor) descriptor).getPsiClass();
    if(!(element instanceof PsiClass))
    {
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    final PsiClass psiClass = (PsiClass) element;
    if(CommonClassNames.JAVA_LANG_OBJECT.equals(psiClass.getQualifiedName()))
    {
        return new Object[]{IdeBundle.message("node.hierarchy.java.lang.object")};
    }
    if(psiClass instanceof PsiAnonymousClass)
    {
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    if(psiClass.hasModifierProperty(PsiModifier.FINAL))
    {
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    final SearchScope searchScope = psiClass.getUseScope().intersectWith(getSearchScope(myCurrentScopeType, psiClass));
    final List<PsiClass> classes = new ArrayList<PsiClass>(ClassInheritorsSearch.search(psiClass, searchScope, false).findAll());
    final List<HierarchyNodeDescriptor> descriptors = new ArrayList<HierarchyNodeDescriptor>(classes.size());
    for(PsiClass aClass : classes)
    {
        descriptors.add(new TypeHierarchyNodeDescriptor(myProject, descriptor, aClass, false));
    }
    FunctionalExpressionSearch.search(psiClass, searchScope).forEach(new Processor<PsiFunctionalExpression>()
    {
        @Override
        public boolean process(PsiFunctionalExpression expression)
        {
            descriptors.add(new TypeHierarchyNodeDescriptor(myProject, descriptor, expression, false));
            return true;
        }
    });
    return descriptors.toArray(new HierarchyNodeDescriptor[descriptors.size()]);
}
项目:consulo-java    文件:SupertypesHierarchyTreeStructure.java   
@Override
@NotNull
protected final Object[] buildChildren(@NotNull final HierarchyNodeDescriptor descriptor)
{
    final Object element = ((TypeHierarchyNodeDescriptor) descriptor).getPsiClass();
    if(element instanceof PsiClass)
    {
        final PsiClass psiClass = (PsiClass) element;
        final PsiClass[] supers = psiClass.getSupers();
        final List<HierarchyNodeDescriptor> descriptors = new ArrayList<HierarchyNodeDescriptor>();
        final PsiClass objectClass = JavaPsiFacade.getInstance(myProject).findClass(CommonClassNames.JAVA_LANG_OBJECT, psiClass.getResolveScope());
        for(PsiClass aSuper : supers)
        {
            if(!psiClass.isInterface() || !aSuper.equals(objectClass))
            {
                descriptors.add(new TypeHierarchyNodeDescriptor(myProject, descriptor, aSuper, false));
            }
        }
        return descriptors.toArray(new HierarchyNodeDescriptor[descriptors.size()]);
    }
    else if(element instanceof PsiFunctionalExpression)
    {
        final PsiClass functionalInterfaceClass = PsiUtil.resolveClassInType(((PsiFunctionalExpression) element).getFunctionalInterfaceType());
        if(functionalInterfaceClass != null)
        {
            return new HierarchyNodeDescriptor[]{new TypeHierarchyNodeDescriptor(myProject, descriptor, functionalInterfaceClass, false)};
        }
    }
    return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
项目:intellij-ce-playground    文件:FunctionalExpressionSearch.java   
public static Query<PsiFunctionalExpression> search(@NotNull final PsiClass aClass, @NotNull SearchScope scope) {
  return INSTANCE.createUniqueResultsQuery(new SearchParameters(aClass, scope));
}
项目:intellij-ce-playground    文件:FunctionalExpressionSearch.java   
public static Query<PsiFunctionalExpression> search(@NotNull final PsiMethod psiMethod) {
  return search(psiMethod, GlobalSearchScope.allScope(PsiUtilCore.getProjectInReadAction(psiMethod)));
}
项目:intellij-ce-playground    文件:FunctionalExpressionSearch.java   
public static Query<PsiFunctionalExpression> search(@NotNull final PsiClass aClass) {
  return search(aClass, GlobalSearchScope.allScope(PsiUtilCore.getProjectInReadAction(aClass)));
}
项目:consulo-java    文件:FunctionalExpressionSearch.java   
public static Query<PsiFunctionalExpression> search(@NotNull final PsiClass aClass, @NotNull SearchScope scope)
{
    return INSTANCE.createUniqueResultsQuery(new SearchParameters(aClass, scope));
}
项目:consulo-java    文件:FunctionalExpressionSearch.java   
public static Query<PsiFunctionalExpression> search(@NotNull final PsiMethod psiMethod)
{
    return search(psiMethod, GlobalSearchScope.allScope(PsiUtilCore.getProjectInReadAction(psiMethod)));
}
项目:consulo-java    文件:FunctionalExpressionSearch.java   
public static Query<PsiFunctionalExpression> search(@NotNull final PsiClass aClass)
{
    return search(aClass, GlobalSearchScope.allScope(PsiUtilCore.getProjectInReadAction(aClass)));
}
项目:consulo-java    文件:MarkerType.java   
private static void navigateToOverriddenMethod(MouseEvent e, @NotNull final PsiMethod method)
{
    if(DumbService.isDumb(method.getProject()))
    {
        DumbService.getInstance(method.getProject()).showDumbModeNotification("Navigation to overriding classes is not possible during index update");
        return;
    }

    PsiElementProcessor.CollectElementsWithLimit<PsiMethod> collectProcessor = new PsiElementProcessor.CollectElementsWithLimit<>(2, new THashSet<>());
    PsiElementProcessor.CollectElementsWithLimit<PsiFunctionalExpression> collectExprProcessor = new PsiElementProcessor.CollectElementsWithLimit<>(2, new THashSet<>());
    final boolean isAbstract = method.hasModifierProperty(PsiModifier.ABSTRACT);
    if(!ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
        GlobalSearchScope scope = GlobalSearchScope.allScope(PsiUtilCore.getProjectInReadAction(method));
        OverridingMethodsSearch.search(method, scope, true).forEach(new PsiElementProcessorAdapter<>(collectProcessor));
        if(isAbstract && collectProcessor.getCollection().size() < 2)
        {
            final PsiClass aClass = ReadAction.compute(method::getContainingClass);
            if(aClass != null)
            {
                FunctionalExpressionSearch.search(aClass).forEach(new PsiElementProcessorAdapter<>(collectExprProcessor));
            }
        }
    }, SEARCHING_FOR_OVERRIDING_METHODS, true, method.getProject(), (JComponent) e.getComponent()))
    {
        return;
    }

    final PsiMethod[] methodOverriders = collectProcessor.toArray(PsiMethod.EMPTY_ARRAY);
    final List<NavigatablePsiElement> overridings = new ArrayList<>();
    overridings.addAll(collectProcessor.getCollection());
    overridings.addAll(collectExprProcessor.getCollection());
    if(overridings.isEmpty())
    {
        return;
    }
    boolean showMethodNames = !PsiUtil.allMethodsHaveSameSignature(methodOverriders);
    MethodOrFunctionalExpressionCellRenderer renderer = new MethodOrFunctionalExpressionCellRenderer(showMethodNames);
    Collections.sort(overridings, renderer.getComparator());
    final OverridingMethodsUpdater methodsUpdater = new OverridingMethodsUpdater(method, renderer);
    PsiElementListNavigator.openTargets(e, overridings.toArray(new NavigatablePsiElement[overridings.size()]), methodsUpdater.getCaption(overridings.size()), "Overriding methods of " + method
            .getName(), renderer, methodsUpdater);
}