Java 类com.intellij.psi.search.searches.ClassInheritorsSearch 实例源码

项目:intellij-plugin    文件:AggregatesNode.java   
@Override
protected MultiMap computeChildren(@Nullable PsiFile psiFile) {
    MultiMap<PsiFile, AggregateNode> children = new MultiMap<>();
    Project project = getProject();
    if (project != null) {
        JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project);
        PsiClass psiClass = javaPsiFacade.findClass(AGGREGATE_ROOT_INTERFACE, GlobalSearchScope.allScope(project));
        if (psiClass != null) {
            ClassInheritorsSearch.search(psiClass, GlobalSearchScope.allScope(project), true).forEach(candidate -> {
                String qualifiedName = candidate.getQualifiedName();
                if (qualifiedName != null && !qualifiedName.startsWith(BUSINESS_PACKAGE) && !isAbstract(candidate)) {
                    children.putValue(candidate.getContainingFile(), new AggregateNode(this, candidate));
                }
            });
        }

    }
    return children;
}
项目:intellij-plugin    文件:ToolsNode.java   
protected MultiMap<PsiFile, ToolNode> computeChildren(PsiFile psiFile) {
    MultiMap<PsiFile, ToolNode> children = new MultiMap<>();
    Project project = getProject();
    if (project != null) {
        PsiClass toolInterface = JavaPsiFacade.getInstance(project).findClass(TOOL_INTERFACE, GlobalSearchScope.allScope(project));
        if (toolInterface != null) {
            ClassInheritorsSearch.search(toolInterface, GlobalSearchScope.allScope(project), true).forEach(psiClass -> {
                PsiFile containingFile = psiClass.getContainingFile();
                if (!isAbstract(psiClass)) {
                    children.putValue(containingFile, new ToolNode(this, psiClass));
                }
            });
        }
    }
    return children;
}
项目:XposedPlugin    文件:XposedInitAssetManager.java   
public void syncDeclaredXposedHooks() {
    if (mXposedModCls == null) {
        mXposedModCls = findXposedModCls();
    }
    GlobalSearchScope moduleScope = GlobalSearchScope.moduleScope(mModule);
    Query<PsiClass> query = ClassInheritorsSearch.search(mXposedModCls, moduleScope, true);
    mDeclaredXposedHooks.clear();
    query.forEach(new Processor<PsiClass>() {
        @Override
        public boolean process(PsiClass psiClass) {
            mDeclaredXposedHooks.add(psiClass.getQualifiedName());
            return true;
        }
    });
    writeXposedInitFile();
}
项目: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);
    }
  }));
}
项目:intellij-ce-playground    文件:GuessManagerImpl.java   
private void addExprTypesByDerivedClasses(LinkedHashSet<PsiType> set, PsiExpression expr) {
  PsiType type = expr.getType();
  if (!(type instanceof PsiClassType)) return;
  PsiClass refClass = PsiUtil.resolveClassInType(type);
  if (refClass == null) return;

  PsiManager manager = PsiManager.getInstance(myProject);
  PsiElementProcessor.CollectElementsWithLimit<PsiClass> processor = new PsiElementProcessor.CollectElementsWithLimit<PsiClass>(5);
  ClassInheritorsSearch.search(refClass, true).forEach(new PsiElementProcessorAdapter<PsiClass>(processor));
  if (processor.isOverflow()) return;

  for (PsiClass derivedClass : processor.getCollection()) {
    if (derivedClass instanceof PsiAnonymousClass) continue;
    PsiType derivedType = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createType(derivedClass);
    set.add(derivedType);
  }
}
项目:intellij-ce-playground    文件:ExtractMethodUtil.java   
static Map<PsiMethodCallExpression, PsiMethod> encodeOverloadTargets(final PsiClass targetClass,
                                                      final SearchScope processConflictsScope,
                                                      final String overloadName,
                                                      final PsiElement extractedFragment) {
  final Map<PsiMethodCallExpression, PsiMethod> ret = new HashMap<PsiMethodCallExpression, PsiMethod>();
  encodeInClass(targetClass, overloadName, extractedFragment, ret);

  ClassInheritorsSearch.search(targetClass, processConflictsScope, true).forEach(new Processor<PsiClass>() {
    public boolean process(PsiClass inheritor) {
      encodeInClass(inheritor, overloadName, extractedFragment, ret);
      return true;
    }
  });

  return ret;
}
项目:intellij-ce-playground    文件:SPIClassProviderReferenceElement.java   
@NotNull
@Override
public Object[] getVariants() {
  final String name = getContainingFile().getName();
  final PsiClass superProvider = JavaPsiFacade.getInstance(getProject()).findClass(name, getResolveScope());
  if (superProvider != null) {
    final List<Object> result = new ArrayList<Object>();
    ClassInheritorsSearch.search(superProvider).forEach(new Processor<PsiClass>() {
      @Override
      public boolean process(PsiClass psiClass) {
        if (!psiClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
          final String jvmClassName = ClassUtil.getJVMClassName(psiClass);
          if (jvmClassName != null) {
            result.add(LookupElementBuilder.create(psiClass, jvmClassName));
          }
        }
        return true;
      }
    });
    return ArrayUtil.toObjectArray(result);
  }
  return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
项目:intellij-ce-playground    文件:SubtypesHierarchyTreeStructure.java   
@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()]);
}
项目:intellij-ce-playground    文件:PushDownProcessor.java   
@Override
@NotNull
protected UsageInfo[] findUsages() {
  final PsiClass[] inheritors = ClassInheritorsSearch.search(myClass, false).toArray(PsiClass.EMPTY_ARRAY);
  final List<UsageInfo> usages = new ArrayList<UsageInfo>(inheritors.length);
  for (PsiClass inheritor : inheritors) {
    usages.add(new UsageInfo(inheritor));
  }

  final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(myClass);
  if (interfaceMethod != null && isMoved(interfaceMethod)) {
    FunctionalExpressionSearch.search(myClass).forEach(new Processor<PsiFunctionalExpression>() {
      @Override
      public boolean process(PsiFunctionalExpression expression) {
        usages.add(new UsageInfo(expression));
        return true;
      }
    });
  }

  return usages.toArray(new UsageInfo[usages.size()]);
}
项目:intellij-ce-playground    文件:RenameJavaVariableProcessor.java   
private static void findSubmemberHidesFieldCollisions(final PsiField field, final String newName, final List<UsageInfo> result) {
  if (field.getContainingClass() == null) return;
  if (field.hasModifierProperty(PsiModifier.PRIVATE)) return;
  final PsiClass containingClass = field.getContainingClass();
  Collection<PsiClass> inheritors = ClassInheritorsSearch.search(containingClass, true).findAll();
  for (PsiClass inheritor : inheritors) {
    PsiField conflictingField = inheritor.findFieldByName(newName, false);
    if (conflictingField != null) {
      result.add(new SubmemberHidesMemberUsageInfo(conflictingField, field));
    } 
    else { //local class
      final PsiMember member = PsiTreeUtil.getParentOfType(inheritor, PsiMember.class);
      if (member != null) {
        final ArrayList<PsiVariable> variables = new ArrayList<PsiVariable>();
        ControlFlowUtil.collectOuterLocals(variables, inheritor, inheritor, member);
        for (PsiVariable variable : variables) {
          if (newName.equals(variable.getName())) {
            result.add(new FieldHidesLocalUsageInfo(variable, field));
          }
        }
      }
    }
  }
}
项目:intellij-ce-playground    文件:RenameJavaMethodProcessor.java   
private static void findSubmemberHidesMemberCollisions(final PsiMethod method, final String newName, final List<UsageInfo> result) {
  final PsiClass containingClass = method.getContainingClass();
  if (containingClass == null) return;
  if (method.hasModifierProperty(PsiModifier.PRIVATE)) return;
  Collection<PsiClass> inheritors = ClassInheritorsSearch.search(containingClass, true).findAll();

  MethodSignature oldSignature = method.getSignature(PsiSubstitutor.EMPTY);
  MethodSignature newSignature = MethodSignatureUtil.createMethodSignature(newName, oldSignature.getParameterTypes(),
                                                                           oldSignature.getTypeParameters(),
                                                                           oldSignature.getSubstitutor(),
                                                                           method.isConstructor());
  for (PsiClass inheritor : inheritors) {
    PsiSubstitutor superSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(containingClass, inheritor, PsiSubstitutor.EMPTY);
    final PsiMethod[] methodsByName = inheritor.findMethodsByName(newName, false);
    for (PsiMethod conflictingMethod : methodsByName) {
      if (newSignature.equals(conflictingMethod.getSignature(superSubstitutor))) {
        result.add(new SubmemberHidesMemberUsageInfo(conflictingMethod, method));
        break;
      }
    }
  }
}
项目:intellij-ce-playground    文件:InlineToAnonymousClassHandler.java   
private static boolean findClassInheritors(final PsiClass element) {
  final Collection<PsiElement> inheritors = new ArrayList<PsiElement>();
  if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable(){
    @Override
    public void run() {
      ApplicationManager.getApplication().runReadAction(new Runnable() {
        @Override
        public void run() {
          final PsiClass inheritor = ClassInheritorsSearch.search(element).findFirst();
          if (inheritor != null) {
            inheritors.add(inheritor);
          } else {
            final PsiFunctionalExpression functionalExpression = FunctionalExpressionSearch.search(element).findFirst();
            if (functionalExpression != null) {
              inheritors.add(functionalExpression);
            }
          }
        }
      });
    }
  }, "Searching for class \"" + element.getQualifiedName() + "\" inheritors ...", true, element.getProject())) return false;
  return inheritors.isEmpty();
}
项目:intellij-ce-playground    文件:RefactoringHierarchyUtil.java   
private static void _findImplementingClasses(PsiClass anInterface, final Set<PsiClass> visited, final Collection<PsiClass> result) {
  LOG.assertTrue(anInterface.isInterface());
  visited.add(anInterface);
  ClassInheritorsSearch.search(anInterface, false).forEach(new PsiElementProcessorAdapter<PsiClass>(new PsiElementProcessor<PsiClass>() {
    public boolean execute(@NotNull PsiClass aClass) {
      if (!aClass.isInterface()) {
        result.add(aClass);
      }
      else if (!visited.contains(aClass)){
        _findImplementingClasses(aClass, visited, result);
      }
      return true;
    }

  }));
}
项目:intellij-ce-playground    文件:InheritanceToDelegationProcessor.java   
@NotNull
protected UsageInfo[] findUsages() {
  ArrayList<UsageInfo> usages = new ArrayList<UsageInfo>();
  final PsiClass[] inheritors = ClassInheritorsSearch.search(myClass, true).toArray(PsiClass.EMPTY_ARRAY);
  myClassInheritors = new HashSet<PsiClass>();
  myClassInheritors.add(myClass);
  addAll(myClassInheritors, inheritors);

  {
    ClassReferenceScanner scanner = new ClassReferenceSearchingScanner(myClass);
    final MyClassInstanceReferenceVisitor instanceReferenceVisitor = new MyClassInstanceReferenceVisitor(myClass, usages);
    scanner.processReferences(new ClassInstanceScanner(myClass, instanceReferenceVisitor));

    MyClassMemberReferencesVisitor visitor = new MyClassMemberReferencesVisitor(usages, instanceReferenceVisitor);
    myClass.accept(visitor);

    myClassImplementedInterfaces = instanceReferenceVisitor.getImplementedInterfaces();
  }
  for (PsiClass inheritor : inheritors) {
    processClass(inheritor, usages);
  }

  return usages.toArray(new UsageInfo[usages.size()]);
}
项目:intellij-ce-playground    文件:SrcRepositoryUseTest.java   
public void testAnonymousClass() throws Exception {
  setupLoadingFilter();

  PsiClass cloneableClass = myJavaFacade.findClass("java.lang.Cloneable", GlobalSearchScope.allScope(myProject));
  PsiClass[] inheritors = ClassInheritorsSearch.search(cloneableClass, GlobalSearchScope.projectScope(myProject), true).toArray(PsiClass.EMPTY_ARRAY);
  assertEquals(2, inheritors.length);
  assertTrue(inheritors[0] instanceof PsiAnonymousClass || inheritors[1] instanceof PsiAnonymousClass);
  PsiAnonymousClass anonClass = (PsiAnonymousClass)(inheritors[0] instanceof PsiAnonymousClass ? inheritors[0] : inheritors[1]);

  PsiClassType baseClassRef = anonClass.getBaseClassType();
  assertEquals("Cloneable", baseClassRef.getPresentableText());
  assertEquals(cloneableClass, baseClassRef.resolve());
  assertEquals("java.lang.Cloneable", baseClassRef.getCanonicalText());

  teardownLoadingFilter();

  assertTrue(anonClass.getParent() instanceof PsiNewExpression);
}
项目:intellij-ce-playground    文件:SrcRepositoryUseTest.java   
public void testAnonymousClass2() throws Exception {
  setupLoadingFilter();

  PsiClass throwable = myJavaFacade.findClass("java.lang.Throwable", GlobalSearchScope.allScope(myProject));
  PsiClass[] inheritors = ClassInheritorsSearch.search(throwable, GlobalSearchScope.projectScope(myProject), true).toArray(PsiClass.EMPTY_ARRAY);
  assertEquals(1, inheritors.length);
  assertTrue(inheritors[0] instanceof PsiAnonymousClass);
  PsiAnonymousClass anonClass = (PsiAnonymousClass)inheritors[0];

  PsiClassType baseClassRef = anonClass.getBaseClassType();
  assertEquals("Throwable", baseClassRef.getPresentableText());
  assertEquals(throwable, baseClassRef.resolve());
  assertEquals("java.lang.Throwable", baseClassRef.getCanonicalText());

  teardownLoadingFilter();

  assertTrue(anonClass.getParent() instanceof PsiNewExpression);
}
项目:intellij-ce-playground    文件:DeclareStyleableNameConverter.java   
@NotNull
@Override
public Object[] getVariants() {
  final PsiClass viewClass = JavaPsiFacade.getInstance(myElement.getProject())
    .findClass(AndroidUtils.VIEW_CLASS_NAME, myFacet.getModule().getModuleWithDependenciesAndLibrariesScope(false));
  if (viewClass == null) {
    return EMPTY_ARRAY;
  }
  final Set<Object> shortNames = new HashSet<Object>();

  ClassInheritorsSearch.search(viewClass, myFacet.getModule().getModuleWithDependenciesScope(), true).
    forEach(new Processor<PsiClass>() {
      @Override
      public boolean process(PsiClass aClass) {
        final String name = aClass.getName();

        if (name != null) {
          shortNames.add(JavaLookupElementBuilder.forClass(aClass, name, true));
        }
        return true;
      }
    });
  return shortNames.toArray();
}
项目:intellij-ce-playground    文件:RenderErrorPanel.java   
@NotNull
private static Collection<PsiClass> findInheritors(@NotNull final Module module, @NotNull final String name) {
  if (!ApplicationManager.getApplication().isReadAccessAllowed()) {
    return ApplicationManager.getApplication().runReadAction(new Computable<Collection<PsiClass>>() {
      @Override
      public Collection<PsiClass> compute() {
        return findInheritors(module, name);
      }
    });
  }

  Project project = module.getProject();
  try {
    PsiClass base = JavaPsiFacade.getInstance(project).findClass(name, GlobalSearchScope.allScope(project));
    if (base != null) {
      GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, false);
      return ClassInheritorsSearch.search(base, scope, true).findAll();
    }
  }
  catch (IndexNotReadyException ignored) {
  }
  return Collections.emptyList();
}
项目:intellij-ce-playground    文件:ClassMayBeInterfaceInspection.java   
@Override
public void doFix(Project project, ProblemDescriptor descriptor) {
  final PsiIdentifier classNameIdentifier = (PsiIdentifier)descriptor.getPsiElement();
  final PsiClass interfaceClass = (PsiClass)classNameIdentifier.getParent();
  final SearchScope searchScope = interfaceClass.getUseScope();
  final List<PsiClass> elements = new ArrayList();
  elements.add(interfaceClass);
  for (final PsiClass inheritor : ClassInheritorsSearch.search(interfaceClass, searchScope, false)) {
    elements.add(inheritor);
  }
  if (!FileModificationService.getInstance().preparePsiElementsForWrite(elements)) {
    return;
  }
  moveSubClassExtendsToImplements(elements);
  changeClassToInterface(interfaceClass);
  moveImplementsToExtends(interfaceClass);
}
项目:intellij-ce-playground    文件:ObjectEqualityInspection.java   
private boolean implementersHaveOnlyPrivateConstructors(final PsiClass aClass) {
  final GlobalSearchScope scope = GlobalSearchScope.allScope(aClass.getProject());
  final PsiElementProcessor.CollectElementsWithLimit<PsiClass> processor = new PsiElementProcessor.CollectElementsWithLimit(6);
  final ProgressManager progressManager = ProgressManager.getInstance();
  progressManager.runProcess(new Runnable() {
    @Override
    public void run() {
      ClassInheritorsSearch.search(aClass, scope, true, true).forEach(new PsiElementProcessorAdapter<PsiClass>(processor));
    }
  }, null);
  if (processor.isOverflow()) {
    return false;
  }
  final Collection<PsiClass> implementers = processor.getCollection();
  for (PsiClass implementer : implementers) {
    if (!implementer.isInterface() && !implementer.hasModifierProperty(PsiModifier.ABSTRACT)) {
      if (!hasOnlyPrivateConstructors(implementer)) {
        return false;
      }
    }
  }
  return true;
}
项目:intellij-ce-playground    文件:MethodUtils.java   
public static boolean isOverriddenInHierarchy(PsiMethod method, PsiClass baseClass) {
  // previous implementation:
  // final Query<PsiMethod> search = OverridingMethodsSearch.search(method);
  //for (PsiMethod overridingMethod : search) {
  //    final PsiClass aClass = overridingMethod.getContainingClass();
  //    if (InheritanceUtil.isCorrectDescendant(aClass, baseClass, true)) {
  //        return true;
  //    }
  //}
  // was extremely slow and used an enormous amount of memory for clone()
  final Query<PsiClass> search = ClassInheritorsSearch.search(baseClass, baseClass.getUseScope(), true, true, true);
  for (PsiClass inheritor : search) {
    final PsiMethod overridingMethod = inheritor.findMethodBySignature(method, false);
    if (overridingMethod != null) {
      return true;
    }
  }
  return false;
}
项目:intellij-ce-playground    文件:ConvertInterfaceToClassIntention.java   
private static boolean moveSubClassImplementsToExtends(PsiClass oldInterface) throws IncorrectOperationException {
  final Project project = oldInterface.getProject();
  final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
  final PsiElementFactory elementFactory = psiFacade.getElementFactory();
  final PsiJavaCodeReferenceElement oldInterfaceReference = elementFactory.createClassReferenceElement(oldInterface);
  final SearchScope searchScope = oldInterface.getUseScope();
  final Query<PsiClass> query = ClassInheritorsSearch.search(oldInterface, searchScope, false);
  final Collection<PsiClass> inheritors = query.findAll();
  final boolean success = CommonRefactoringUtil.checkReadOnlyStatusRecursively(project, inheritors, false);
  if (!success) {
    return false;
  }
  for (PsiClass inheritor : inheritors) {
    final PsiReferenceList implementsList = inheritor.getImplementsList();
    final PsiReferenceList extendsList = inheritor.getExtendsList();
    if (implementsList != null) {
      moveReference(implementsList, extendsList, oldInterfaceReference);
    }
  }
  return true;
}
项目:intellij-ce-playground    文件:ConvertInterfaceToClassPredicate.java   
public boolean satisfiedBy(PsiElement element) {
  final PsiElement parent = element.getParent();
  if (!(parent instanceof PsiClass)) {
    return false;
  }
  final PsiClass aClass = (PsiClass)parent;
  if (!aClass.isInterface() || aClass.isAnnotationType()) {
    return false;
  }
  final PsiElement leftBrace = aClass.getLBrace();
  final int offsetInParent = element.getStartOffsetInParent();
  if (leftBrace == null ||
      offsetInParent >= leftBrace.getStartOffsetInParent()) {
    return false;
  }
  final SearchScope useScope = aClass.getUseScope();
  for (PsiClass inheritor :
    ClassInheritorsSearch.search(aClass, useScope, true)) {
    if (inheritor.isInterface()) {
      return false;
    }
  }
  return !AnnotationUtil.isAnnotated(aClass, CommonClassNames.JAVA_LANG_FUNCTIONAL_INTERFACE, false, true);
}
项目:intellij-ce-playground    文件:JavaFXNSDescriptor.java   
@NotNull
@Override
public XmlElementDescriptor[] getRootElementsDescriptors(@Nullable XmlDocument document) {
  if (document != null) {
    final Project project = document.getProject();
    final PsiClass paneClass = JavaPsiFacade.getInstance(project).findClass(JavaFxCommonClassNames.JAVAFX_SCENE_LAYOUT_PANE, GlobalSearchScope.allScope(project));
    if (paneClass != null) {
      final ArrayList<XmlElementDescriptor> result = new ArrayList<XmlElementDescriptor>();
      ClassInheritorsSearch.search(paneClass, paneClass.getUseScope(), true, true, false).forEach(new Processor<PsiClass>() {
        @Override
        public boolean process(PsiClass psiClass) {
          result.add(new JavaFxClassBackedElementDescriptor(psiClass.getName(), psiClass));
          return true;
        }
      });
      return result.toArray(new XmlElementDescriptor[result.size()]);
    }
  }
  return new XmlElementDescriptor[0];
}
项目:IntelliJ_Jahia_plugin    文件:ActionNode.java   
public ActionNode(PsiClass psiClass) {
    super(null);
    setIcon(AllIcons.FileTypes.Java);
    this.psiClass = psiClass;

    Query<PsiClass> actionClasses = ClassInheritorsSearch.search(this.psiClass, GlobalSearchScope.projectScope(this.psiClass.getProject()), false);
    ArrayList<PsiClass> actionClassesList = Lists.newArrayList(actionClasses);
    actionClassesList.sort(new Comparator<PsiClass>() {
        @Override
        public int compare(PsiClass o1, PsiClass o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    for (PsiClass actionClass : actionClassesList) {
        if (this.psiClass.equals(actionClass.getSuperClass())) {
            add(new ActionNode(actionClass));
        }
    }
}
项目:IntelliJ_Jahia_plugin    文件:ActionsNode.java   
public ActionsNode(CndSimpleNode parent, Project project) {
        super(parent);
        setIcon(CndIcons.JAHIA_ACTION);

        PsiClass jahiaActionClass = JavaPsiFacade.getInstance(project).findClass(JAHIA_ACTION_CLASS, GlobalSearchScope.allScope(project));
        if (jahiaActionClass != null) {
            Query<PsiClass> actionClasses = ClassInheritorsSearch.search(jahiaActionClass, GlobalSearchScope.projectScope(project), false);
            ArrayList<PsiClass> actionClassesList = Lists.newArrayList(actionClasses);
            actionClassesList.sort(new Comparator<PsiClass>() {
                @Override
                public int compare(PsiClass o1, PsiClass o2) {
                    return o1.getName().compareTo(o2.getName());
                }
            });
            for (PsiClass actionClass : actionClassesList) {
                if (jahiaActionClass.equals(actionClass.getSuperClass())) {
                    add(new ActionNode(actionClass));
                }
                //TODO: change icon if abstract?
//                ArrayUtils.toString(actionClass.getModifierList());
            }
        }
    }
项目:IntelliJ_Jahia_plugin    文件:FilterNode.java   
public FilterNode(PsiClass psiClass) {
    super(null);
    setIcon(AllIcons.FileTypes.Java);
    this.psiClass = psiClass;

    Query<PsiClass> actionClasses = ClassInheritorsSearch.search(this.psiClass, GlobalSearchScope.projectScope(this.psiClass.getProject()), false);
    ArrayList<PsiClass> actionClassesList = Lists.newArrayList(actionClasses);
    actionClassesList.sort(new Comparator<PsiClass>() {
        @Override
        public int compare(PsiClass o1, PsiClass o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    for (PsiClass actionClass : actionClassesList) {
        if (this.psiClass.equals(actionClass.getSuperClass())) {
            add(new FilterNode(actionClass));
        }
    }
}
项目:IntelliJ_Jahia_plugin    文件:FiltersNode.java   
public FiltersNode(CndSimpleNode parent, Project project) {
    super(parent);
    setIcon(CndIcons.JAHIA_FILTER);

    PsiClass jahiaFilterClass = JavaPsiFacade.getInstance(project).findClass(JAHIA_FILTER_CLASS, GlobalSearchScope.allScope(project));
    if (jahiaFilterClass != null) {
        Query<PsiClass> filterClasses = ClassInheritorsSearch.search(jahiaFilterClass, GlobalSearchScope.projectScope(project), false);
        ArrayList<PsiClass> filterClassesList = Lists.newArrayList(filterClasses);
        filterClassesList.sort(new Comparator<PsiClass>() {
            @Override
            public int compare(PsiClass o1, PsiClass o2) {
                return o1.getName().compareTo(o2.getName());
            }
        });
        for (PsiClass filterClass : filterClassesList) {
            if (jahiaFilterClass.equals(filterClass.getSuperClass())) {
                add(new FilterNode(filterClass));
            }
            //TODO: change icon if abstract?
            //                ArrayUtils.toString(filterClass.getModifierList());
        }
    }
}
项目:defrac-plugin-intellij    文件:MacroClassReference.java   
@NotNull
@Override
public Object[] getVariants() {
  // all classes of current platform extending defrac.macro.Macro are eligible
  final Project project = getElement().getProject();
  final DefracFacet facet = DefracFacet.getInstance(getElement());

  if(facet == null) {
    return NO_VARIANTS;
  }

  final PsiClass macro =
      JavaPsiFacade.getInstance(project).findClass(
          Names.defrac_compiler_macro_Macro, GlobalSearchScope.allScope(project));

  if(macro == null) {
    return NO_VARIANTS;
  }

  final GlobalSearchScope scope = facet.getMacroSearchScope(platform);
  final Query<PsiClass> query =
      ClassInheritorsSearch.search(macro, scope, true, true);

  return variantsViaQuery(query);
}
项目:tools-idea    文件:ClassImplementationsSearch.java   
public static boolean processImplementations(final PsiClass psiClass, final Processor<? super PsiClass> processor) {
  final boolean showInterfaces = Registry.is("ide.goto.implementation.show.interfaces");
  return ClassInheritorsSearch.search(psiClass, ApplicationManager.getApplication().runReadAction(new Computable<SearchScope>() {
    @Override
    public SearchScope compute() {
      return psiClass.getUseScope();
    }
  }), true).forEach(new PsiElementProcessorAdapter<PsiClass>(new PsiElementProcessor<PsiClass>() {
    public boolean execute(@NotNull PsiClass element) {
      if (!showInterfaces && element.isInterface()) {
        return true;
      }
      return processor.process(element);
    }
  }));
}
项目:tools-idea    文件:GuessManagerImpl.java   
private void addExprTypesByDerivedClasses(LinkedHashSet<PsiType> set, PsiExpression expr) {
  PsiType type = expr.getType();
  if (!(type instanceof PsiClassType)) return;
  PsiClass refClass = PsiUtil.resolveClassInType(type);
  if (refClass == null) return;

  PsiManager manager = PsiManager.getInstance(myProject);
  PsiElementProcessor.CollectElementsWithLimit<PsiClass> processor = new PsiElementProcessor.CollectElementsWithLimit<PsiClass>(5);
  ClassInheritorsSearch.search(refClass, true).forEach(new PsiElementProcessorAdapter<PsiClass>(processor));
  if (processor.isOverflow()) return;

  for (PsiClass derivedClass : processor.getCollection()) {
    if (derivedClass instanceof PsiAnonymousClass) continue;
    PsiType derivedType = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createType(derivedClass);
    set.add(derivedType);
  }
}
项目:tools-idea    文件:JavaLineMarkerProvider.java   
private static void collectInheritingClasses(PsiClass aClass, Collection<LineMarkerInfo> result) {
  if (aClass.hasModifierProperty(PsiModifier.FINAL)) {
    return;
  }
  if (CommonClassNames.JAVA_LANG_OBJECT.equals(aClass.getQualifiedName())) return; // It's useless to have overridden markers for object.

  PsiClass inheritor = ClassInheritorsSearch.search(aClass, false).findFirst();
  if (inheritor != null) {
    final Icon icon = aClass.isInterface() ? AllIcons.Gutter.ImplementedMethod : AllIcons.Gutter.OverridenMethod;
    PsiElement range = aClass.getNameIdentifier();
    if (range == null) range = aClass;
    MarkerType type = MarkerType.SUBCLASSED_CLASS;
    LineMarkerInfo info = new LineMarkerInfo<PsiElement>(range, range.getTextRange(),
                                                         icon, Pass.UPDATE_OVERRIDEN_MARKERS, type.getTooltip(),
                                                         type.getNavigationHandler(),
                                                         GutterIconRenderer.Alignment.RIGHT);
    result.add(info);
  }
}
项目:tools-idea    文件:MarkerType.java   
public static String getSubclassedClassTooltip(PsiClass aClass) {
  PsiElementProcessor.CollectElementsWithLimit<PsiClass> processor = new PsiElementProcessor.CollectElementsWithLimit<PsiClass>(5, new THashSet<PsiClass>());
  ClassInheritorsSearch.search(aClass, true).forEach(new PsiElementProcessorAdapter<PsiClass>(processor));

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

  PsiClass[] subclasses = processor.toArray(new PsiClass[processor.getCollection().size()]);
  if (subclasses.length == 0) return null;

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

  String start = aClass.isInterface()
                 ? DaemonBundle.message("interface.is.implemented.by.header")
                 : DaemonBundle.message("class.is.subclassed.by.header");
  @NonNls String pattern = "&nbsp;&nbsp;&nbsp;&nbsp;{0}";
  return GutterIconTooltipHelper.composeText(subclasses, start, pattern);
}
项目:tools-idea    文件:MarkerType.java   
public static void navigateToSubclassedClass(MouseEvent e, 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.CollectElementsWithLimit<PsiClass> collectProcessor = new PsiElementProcessor.CollectElementsWithLimit<PsiClass>(2, new THashSet<PsiClass>());
  if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
    @Override
    public void run() {
      ClassInheritorsSearch.search(aClass, true).forEach(new PsiElementProcessorAdapter<PsiClass>(collectProcessor));
    }
  }, SEARCHING_FOR_OVERRIDDEN_METHODS, true, aClass.getProject(), (JComponent)e.getComponent())) {
    return;
  }

  PsiClass[] inheritors = collectProcessor.toArray(PsiClass.EMPTY_ARRAY);
  if (inheritors.length == 0) return;
  final PsiClassListCellRenderer renderer = new PsiClassListCellRenderer();
  final SubclassUpdater subclassUpdater = new SubclassUpdater(aClass, renderer);
  Arrays.sort(inheritors, renderer.getComparator());
  PsiElementListNavigator.openTargets(e, inheritors, subclassUpdater.getCaption(inheritors.length), CodeInsightBundle.message("goto.implementation.findUsages.title", aClass.getName()), renderer, subclassUpdater);
}
项目:tools-idea    文件: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);
    }
  });
}
项目:tools-idea    文件:SPIClassProviderReferenceElement.java   
@NotNull
@Override
public Object[] getVariants() {
  final String name = getContainingFile().getName();
  final PsiClass superProvider = JavaPsiFacade.getInstance(getProject()).findClass(name, getResolveScope());
  if (superProvider != null) {
    final List<Object> result = new ArrayList<Object>();
    ClassInheritorsSearch.search(superProvider).forEach(new Processor<PsiClass>() {
      @Override
      public boolean process(PsiClass psiClass) {
        final String jvmClassName = ClassUtil.getJVMClassName(psiClass);
        if (jvmClassName != null) {
          result.add(LookupElementBuilder.create(psiClass, jvmClassName));
        }
        return false;
      }
    });
    return ArrayUtil.toObjectArray(result);
  }
  return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
项目:tools-idea    文件:ClassHierarchyScopeDescriptor.java   
@Nullable
public SearchScope getScope() {
  if (myCachedScope == null) {
    TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myProject).createAllProjectScopeChooser(IdeBundle.message("prompt.choose.base.class.of.the.hierarchy"));

    chooser.showDialog();

    PsiClass aClass = chooser.getSelected();
    if (aClass == null) return null;

    List<PsiElement> classesToSearch = new LinkedList<PsiElement>();
    classesToSearch.add(aClass);

    classesToSearch.addAll(ClassInheritorsSearch.search(aClass, true).findAll());

    myCachedScope = new LocalSearchScope(PsiUtilCore.toPsiElementArray(classesToSearch),
                                         IdeBundle.message("scope.hierarchy", ClassPresentationUtil.getNameForClass(aClass, true)));
  }

  return myCachedScope;
}
项目:tools-idea    文件:RenameJavaMethodProcessor.java   
private static void findSubmemberHidesMemberCollisions(final PsiMethod method, final String newName, final List<UsageInfo> result) {
  final PsiClass containingClass = method.getContainingClass();
  if (containingClass == null) return;
  if (method.hasModifierProperty(PsiModifier.PRIVATE)) return;
  Collection<PsiClass> inheritors = ClassInheritorsSearch.search(containingClass, true).findAll();

  MethodSignature oldSignature = method.getSignature(PsiSubstitutor.EMPTY);
  MethodSignature newSignature = MethodSignatureUtil.createMethodSignature(newName, oldSignature.getParameterTypes(),
                                                                           oldSignature.getTypeParameters(),
                                                                           oldSignature.getSubstitutor(),
                                                                           method.isConstructor());
  for (PsiClass inheritor : inheritors) {
    PsiSubstitutor superSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(containingClass, inheritor, PsiSubstitutor.EMPTY);
    final PsiMethod[] methodsByName = inheritor.findMethodsByName(newName, false);
    for (PsiMethod conflictingMethod : methodsByName) {
      if (newSignature.equals(conflictingMethod.getSignature(superSubstitutor))) {
        result.add(new SubmemberHidesMemberUsageInfo(conflictingMethod, method));
        break;
      }
    }
  }
}
项目:tools-idea    文件:ExtractMethodUtil.java   
static Map<PsiMethodCallExpression, PsiMethod> encodeOverloadTargets(final PsiClass targetClass,
                                                      final SearchScope processConflictsScope,
                                                      final String overloadName,
                                                      final PsiElement extractedFragment) {
  final Map<PsiMethodCallExpression, PsiMethod> ret = new HashMap<PsiMethodCallExpression, PsiMethod>();
  encodeInClass(targetClass, overloadName, extractedFragment, ret);

  ClassInheritorsSearch.search(targetClass, processConflictsScope, true).forEach(new Processor<PsiClass>() {
    public boolean process(PsiClass inheritor) {
      encodeInClass(inheritor, overloadName, extractedFragment, ret);
      return true;
    }
  });

  return ret;
}
项目:tools-idea    文件:RefactoringHierarchyUtil.java   
private static void _findImplementingClasses(PsiClass anInterface, final Set<PsiClass> visited, final Collection<PsiClass> result) {
  LOG.assertTrue(anInterface.isInterface());
  visited.add(anInterface);
  ClassInheritorsSearch.search(anInterface, false).forEach(new PsiElementProcessorAdapter<PsiClass>(new PsiElementProcessor<PsiClass>() {
    public boolean execute(@NotNull PsiClass aClass) {
      if (!aClass.isInterface()) {
        result.add(aClass);
      }
      else if (!visited.contains(aClass)){
        _findImplementingClasses(aClass, visited, result);
      }
      return true;
    }

  }));
}