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

项目:intellij-ce-playground    文件:PathsList.java   
private Iterator<String> chooseFirstTimeItems(String path) {
  if (path == null) {
    return emptyIterator();
  }
  final StringTokenizer tokenizer = new StringTokenizer(path, File.pathSeparator);
  // in JDK 1.5 StringTokenizer implements Enumeration<Object> rather then Enumeration<String>, need to convert
  final Enumeration<String> en = new Enumeration<String>() {
    @Override
    public boolean hasMoreElements() {
      return tokenizer.hasMoreElements();
    }

    @Override
    public String nextElement() {
      return (String)tokenizer.nextElement();
    }
  };
  return FilteringIterator.create(iterate(en), new Condition<String>() {
    @Override
    public boolean value(String element) {
      element = element.trim();
      return !element.isEmpty() && !myPathSet.contains(element);
    }
  });
}
项目:intellij-ce-playground    文件:GrRefactoringConflictsUtil.java   
public static void analyzeModuleConflicts(final Project project,
                                          final Collection<? extends PsiElement> scopes,
                                          final UsageInfo[] usages,
                                          final PsiElement target,
                                          final MultiMap<PsiElement,String> conflicts) {
  if (scopes == null) return;
  final VirtualFile vFile = PsiUtilCore.getVirtualFile(target);
  if (vFile == null) return;


  List<GroovyPsiElement> groovyScopes =
    ContainerUtil.collect(scopes.iterator(), new FilteringIterator.InstanceOf<GroovyPsiElement>(GroovyPsiElement.class));
  analyzeModuleConflicts(project, groovyScopes, usages, vFile, conflicts);
  scopes.removeAll(groovyScopes);
  RefactoringConflictsUtil.analyzeModuleConflicts(project, scopes, usages, vFile, conflicts);
}
项目:tools-idea    文件:PathsList.java   
private Iterator<String> chooseFirstTimeItems(String path) {
  if (path == null) {
    return emptyIterator();
  }
  final StringTokenizer tokenizer = new StringTokenizer(path, File.pathSeparator);
  // in JDK 1.5 StringTokenizer implements Enumeration<Object> rather then Enumeration<String>, need to convert
  final Enumeration<String> en = new Enumeration<String>() {
    @Override
    public boolean hasMoreElements() {
      return tokenizer.hasMoreElements();
    }

    @Override
    public String nextElement() {
      return (String)tokenizer.nextElement();
    }
  };
  return FilteringIterator.create(iterate(en), new Condition<String>() {
    @Override
    public boolean value(String element) {
      element = element.trim();
      return !element.isEmpty() && !myPathSet.contains(element);
    }
  });
}
项目:intellij-ce-playground    文件:ModuleLibraryTable.java   
@Override
@NotNull
public Iterator<Library> getLibraryIterator() {
  FilteringIterator<OrderEntry, LibraryOrderEntry> filteringIterator =
    new FilteringIterator<OrderEntry, LibraryOrderEntry>(myRootModel.getOrderIterator(), MODULE_LIBRARY_ORDER_ENTRY_FILTER);
  return new ConvertingIterator<LibraryOrderEntry, Library>(filteringIterator, ORDER_ENTRY_TO_LIBRARY_CONVERTOR);
}
项目:intellij-ce-playground    文件:InlinePropertyHandler.java   
public boolean canInlineElement(PsiElement element) {
  if (element instanceof PsiJavaToken && ((PsiJavaToken)element).getTokenType() == JavaTokenType.STRING_LITERAL) {
    PsiReference[] references = element.getParent().getReferences();
    return ContainerUtil.find(references, FilteringIterator.instanceOf(PropertyReference.class)) != null;
  }
  return element instanceof IProperty;
}
项目:tools-idea    文件:ModuleLibraryTable.java   
@Override
@NotNull
public Iterator<Library> getLibraryIterator() {
  FilteringIterator<OrderEntry, LibraryOrderEntry> filteringIterator =
    new FilteringIterator<OrderEntry, LibraryOrderEntry>(myRootModel.getOrderIterator(), MODULE_LIBRARY_ORDER_ENTRY_FILTER);
  return new ConvertingIterator<LibraryOrderEntry, Library>(filteringIterator, ORDER_ENTRY_TO_LIBRARY_CONVERTOR);
}
项目:guards    文件:GuardPopupController.java   
static JList findJList(ListPopup popup) {
    Set<Component> lists = JBSwingUtilities.uiTraverser().preOrderTraversal(popup.getContent())
            .filter(new FilteringIterator.InstanceOf<>(JList.class)).toSet();
    if ( lists.size() != 1 ) {
        throw new IllegalStateException("Expected exactly one JList");
    }
    return (JList)lists.iterator().next();
}
项目:guards    文件:ExtendedKeyboardActionDispatcher.java   
ExtendedKeyboardActionDispatcher(ListPopup popup) {
    this.popup = popup;
    Set<Component> lists = JBSwingUtilities.uiTraverser().preOrderTraversal(popup.getContent())
            .filter(new FilteringIterator.InstanceOf<>(JList.class)).toSet();
    if ( lists.size() != 1 ) {
        list = null;
    }
    else {
        list = (JList)lists.iterator().next();
    }
}
项目:consulo    文件:ModuleLibraryTable.java   
@Override
@Nonnull
public Iterator<Library> getLibraryIterator() {
  FilteringIterator<OrderEntry, LibraryOrderEntry> filteringIterator =
    new FilteringIterator<OrderEntry, LibraryOrderEntry>(myRootLayer.getOrderIterator(), MODULE_LIBRARY_ORDER_ENTRY_FILTER);
  return new ConvertingIterator<LibraryOrderEntry, Library>(filteringIterator, ORDER_ENTRY_TO_LIBRARY_CONVERTOR);
}
项目:consulo    文件:ThrowableInterner.java   
@Override
public int computeHashCode(Throwable throwable) {
  String message = throwable.getMessage();
  if (message != null) {
    return message.hashCode();
  }
  Object[] backtrace = getBacktrace(throwable);
  if (backtrace != null) {
    Object[] stack = (Object[])ContainerUtil.find(backtrace, FilteringIterator.instanceOf(Object[].class));
    return Arrays.hashCode(stack);
  }
  return Arrays.hashCode(throwable.getStackTrace());
}
项目:intellij-ce-playground    文件:DefaultHighlightVisitorBasedInspection.java   
@Override
public void visitFile(final PsiFile file) {
  final VirtualFile virtualFile = file.getVirtualFile();
  if (virtualFile == null) {
    return;
  }

  final Project project = file.getProject();
  Document document = PsiDocumentManager.getInstance(project).getDocument(file);
  if (document == null) return;
  DaemonProgressIndicator progress = new DaemonProgressIndicator();
  progress.start();
  try {
    TextEditorHighlightingPassRegistrarEx passRegistrarEx = TextEditorHighlightingPassRegistrarEx.getInstanceEx(project);
    List<TextEditorHighlightingPass> passes = passRegistrarEx.instantiateMainPasses(file, document, HighlightInfoProcessor.getEmpty());
    List<GeneralHighlightingPass> gpasses = ContainerUtil.collect(passes.iterator(), FilteringIterator.instanceOf(GeneralHighlightingPass.class));
    for (final GeneralHighlightingPass gpass : gpasses) {
      gpass.setHighlightVisitorProducer(new NotNullProducer<HighlightVisitor[]>() {
        @NotNull
        @Override
        public HighlightVisitor[] produce() {
          gpass.incVisitorUsageCount(1);
          return new HighlightVisitor[]{new DefaultHighlightVisitor(project, highlightErrorElements, runAnnotators, true)};
        }
      });
    }


    for (TextEditorHighlightingPass pass : gpasses) {
      pass.doCollectInformation(progress);
      List<HighlightInfo> infos = pass.getInfos();
      for (HighlightInfo info : infos) {
        if (info == null) continue;
        //if (info.type == HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT) continue;
        if (info.getSeverity().compareTo(HighlightSeverity.INFORMATION) <= 0) continue;
        result.add(Pair.create(file, info));
      }
    }
  }
  finally {
    progress.stop();
  }
}
项目:intellij-ce-playground    文件:ExternalDependenciesManagerImpl.java   
@NotNull
@Override
public <T extends ProjectExternalDependency> List<T> getDependencies(@NotNull Class<T> aClass) {
  return ContainerUtil.collect(myDependencies.iterator(), FilteringIterator.instanceOf(aClass));
}
项目:intellij-ce-playground    文件:ApplyNonConflicts.java   
private static Iterator<Change> getNotConflicts(MergeList mergeList) {
  if (mergeList == null) return new ArrayList<Change>(1).iterator();
  return FilteringIterator.create(mergeList.getAllChanges(), MergeList.NOT_CONFLICTS);
}
项目:intellij-ce-playground    文件:IJSwingUtilities.java   
@Nullable
public static <T extends Component> T findParentOfType(Component focusOwner, Class<T> aClass) {
  return (T)ContainerUtil.find(getParents(focusOwner), (FilteringIterator.InstanceOf<T>)FilteringIterator.instanceOf(aClass));

}
项目:intellij-ce-playground    文件:IJSwingUtilities.java   
@Nullable
public static Component findParentByInterface(Component focusOwner, Class aClass) {
  return ContainerUtil.find(getParents(focusOwner), FilteringIterator.instanceOf(aClass));
}
项目:intellij-ce-playground    文件:RepositoryTreeNode.java   
@NotNull
public List<RepositoryTreeNode> getAlreadyLoadedChildren() {
  return ContainerUtil.collect(myChildren.iterator(), FilteringIterator.instanceOf(RepositoryTreeNode.class));
}
项目:tools-idea    文件:ApplyNonConflicts.java   
private static Iterator<Change> getNotConflicts(DataContext dataContext) {
  MergeList mergeList = MergeList.fromDataContext(dataContext);
  if (mergeList == null) return new ArrayList<Change>(1).iterator();
  return FilteringIterator.create(mergeList.getAllChanges(), MergeList.NOT_CONFLICTS);
}
项目:tools-idea    文件:IJSwingUtilities.java   
@Nullable
public static <T extends Component> T findParentOfType(Component focusOwner, Class<T> aClass) {
  return (T)ContainerUtil.find(getParents(focusOwner), (FilteringIterator.InstanceOf<T>)FilteringIterator.instanceOf(aClass));
}
项目:consulo    文件:DefaultHighlightVisitorBasedInspection.java   
@Override
public void visitFile(final PsiFile file) {
  final VirtualFile virtualFile = file.getVirtualFile();
  if (virtualFile == null) {
    return;
  }

  final Project project = file.getProject();
  Document document = PsiDocumentManager.getInstance(project).getDocument(file);
  if (document == null) return;
  DaemonProgressIndicator progress = new DaemonProgressIndicator();
  progress.start();
  try {
    TextEditorHighlightingPassRegistrarEx passRegistrarEx = TextEditorHighlightingPassRegistrarEx.getInstanceEx(project);
    List<TextEditorHighlightingPass> passes = passRegistrarEx.instantiateMainPasses(file, document, HighlightInfoProcessor.getEmpty());
    List<GeneralHighlightingPass> gpasses = ContainerUtil.collect(passes.iterator(), FilteringIterator.instanceOf(GeneralHighlightingPass.class));
    for (final GeneralHighlightingPass gpass : gpasses) {
      gpass.setHighlightVisitorProducer(() -> {
        gpass.incVisitorUsageCount(1);

        HighlightVisitor visitor = new DefaultHighlightVisitor(project, highlightErrorElements, runAnnotators, true,
                                                               ServiceManager.getService(project, CachedAnnotators.class));
        return new HighlightVisitor[]{visitor};
      });
    }


    for (TextEditorHighlightingPass pass : gpasses) {
      pass.doCollectInformation(progress);
      List<HighlightInfo> infos = pass.getInfos();
      for (HighlightInfo info : infos) {
        if (info == null) continue;
        //if (info.type == HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT) continue;
        if (info.getSeverity().compareTo(HighlightSeverity.INFORMATION) <= 0) continue;
        result.add(Pair.create(file, info));
      }
    }
  }
  finally {
    progress.stop();
  }
}
项目:consulo    文件:ApplyNonConflicts.java   
private static Iterator<Change> getNotConflicts(DataContext dataContext) {
  MergeList mergeList = MergeList.fromDataContext(dataContext);
  if (mergeList == null) return new ArrayList<Change>(1).iterator();
  return FilteringIterator.create(mergeList.getAllChanges(), MergeList.NOT_CONFLICTS);
}
项目:consulo    文件:IJSwingUtilities.java   
@Nullable
public static <T extends Component> T findParentOfType(Component focusOwner, Class<T> aClass) {
  return (T)ContainerUtil.find(getParents(focusOwner), (FilteringIterator.InstanceOf<T>)FilteringIterator.instanceOf(aClass));

}
项目:consulo    文件:IJSwingUtilities.java   
@Nullable
public static Component findParentByInterface(Component focusOwner, Class aClass) {
  return ContainerUtil.find(getParents(focusOwner), FilteringIterator.instanceOf(aClass));
}
项目:consulo-java    文件:LiveVariablesAnalyzer.java   
/**
 * @return true if completed, false if "too complex"
 */
private boolean runDfa(boolean forward, PairFunction<Instruction, BitSet, BitSet> handleState)
{
    Set<Instruction> entryPoints = ContainerUtil.newHashSet();
    if(forward)
    {
        entryPoints.add(myInstructions[0]);
    }
    else
    {
        entryPoints.addAll(ContainerUtil.findAll(myInstructions, FilteringIterator.instanceOf(ReturnInstruction.class)));
    }

    Queue<InstructionState> queue = new Queue<>(10);
    for(Instruction i : entryPoints)
    {
        queue.addLast(new InstructionState(i, new BitSet()));
    }

    int limit = myForwardMap.size() * 20;
    Set<InstructionState> processed = ContainerUtil.newHashSet();
    while(!queue.isEmpty())
    {
        int steps = processed.size();
        if(steps > limit)
        {
            return false;
        }
        if(steps % 1024 == 0)
        {
            ProgressManager.checkCanceled();
        }
        InstructionState state = queue.pullFirst();
        Instruction instruction = state.first;
        Collection<Instruction> nextInstructions = forward ? myForwardMap.get(instruction) : myBackwardMap.get(instruction);
        BitSet nextVars = handleState.fun(instruction, state.second);
        for(Instruction next : nextInstructions)
        {
            InstructionState nextState = new InstructionState(next, nextVars);
            if(processed.add(nextState))
            {
                queue.addLast(nextState);
            }
        }
    }
    return true;
}