Java 类com.intellij.util.containers.JBTreeTraverser 实例源码

项目:consulo    文件:TreeUtil.java   
@Nonnull
public static JBTreeTraverser<TreePath> treePathTraverser(@Nonnull JTree tree) {
  TreeModel model = tree.getModel();
  JBIterable<Integer> numbers = JBIterable.generate(0, i -> i + 1);
  Object root = model.getRoot();
  TreePath rootPath = root == null ? null : new TreePath(root);
  return new JBTreeTraverser<TreePath>(o -> {
    Object parent = o.getLastPathComponent();
    int count = model.getChildCount(parent);

    return count == 0 ? JBIterable.empty() :
           numbers.take(count).map(
                   index -> o.pathByAddingChild(model.getChild(parent, index)));
  })
          .withRoot(rootPath);
}
项目:yii2support    文件:TestModel.java   
@NotNull
@Override
public JBTreeTraverser<DasObject> traverser() {

    List<DasObject> list = new LinkedList<>();
    TestNamespace namespace = new TestNamespace();
    TestTable table1 = new TestTable("person", namespace, project);

    table1.addColumn(new TestColumn("name", project));
    table1.addColumn(new TestColumn("surname", project));
    table1.addColumn(new TestColumn("birth_date", project));
    list.add(table1);
    TestTable table2 = new TestTable("address", namespace, project);
    table2.addColumn(new TestColumn("street", project));
    table2.addColumn(new TestColumn("city", project));
    list.add(table2);
    return new JBTreeTraverser<>(dasObject -> () -> new Iterator<DasObject>() {
        int current = 0;

        @Override
        public boolean hasNext() {
            return list.size() > current;
        }

        @Override
        public DasObject next() {
            return list.get(current++);

        }
    });
}
项目:consulo    文件:ComponentTreeEventDispatcher.java   
private ComponentTreeEventDispatcher(@Nullable final Component root, @Nonnull Class<T> listenerClass) {
  myListenerClass = listenerClass;
  myMulticaster = EventDispatcher.createMulticaster(listenerClass, new Getter<Iterable<T>>() {
    @Nullable
    @Override
    public Iterable<T> get() {
      JBTreeTraverser<Component> traverser = UIUtil.uiTraverser(root);
      if (root == null) traverser = traverser.withRoots(Arrays.asList(Window.getWindows()));
      return traverser.postOrderDfsTraversal().filter(myListenerClass);
    }
  });
}
项目:intellij-ce-playground    文件:UIUtil.java   
@NotNull
public static JBTreeTraverser<Component> uiTraverser() {
  return new JBTreeTraverser<Component>(COMPONENT_CHILDREN);
}
项目:intellij-ce-playground    文件:UIUtil.java   
@NotNull
public static JBTreeTraverser<Component> uiTraverser(@Nullable Component component) {
  return new JBTreeTraverser<Component>(COMPONENT_CHILDREN).withRoot(component);
}
项目:consulo    文件:UIUtil.java   
@Nonnull
public static JBTreeTraverser<Component> uiTraverser() {
  return new JBTreeTraverser<Component>(COMPONENT_CHILDREN);
}
项目:consulo    文件:UIUtil.java   
@Nonnull
public static JBTreeTraverser<Component> uiTraverser(@Nullable Component component) {
  return new JBTreeTraverser<Component>(COMPONENT_CHILDREN).withRoot(component);
}
项目:consulo    文件:ReflectionUtil.java   
@Nonnull
public static JBTreeTraverser<Class> classTraverser(@Nullable Class root) {
  return new JBTreeTraverser<Class>(CLASS_STRUCTURE).unique().withRoot(root);
}
项目: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);
    }
}