Java 类com.intellij.util.NullableFunction 实例源码

项目:intellij-ce-playground    文件:ExpectedTypesProvider.java   
@Nullable
protected static PsiType checkMethod(@NotNull PsiMethod method, @NotNull @NonNls final String className, @NotNull final NullableFunction<PsiClass,PsiType> function) {
  final PsiClass containingClass = method.getContainingClass();
  if (containingClass == null) return null;

  if (className.equals(containingClass.getQualifiedName())) {
    return function.fun(containingClass);
  }
  final PsiType[] type = {null};
  DeepestSuperMethodsSearch.search(method).forEach(new Processor<PsiMethod>() {
    @Override
    public boolean process(@NotNull PsiMethod psiMethod) {
      final PsiClass rootClass = psiMethod.getContainingClass();
      assert rootClass != null;
      if (className.equals(rootClass.getQualifiedName())) {
        type[0] = function.fun(rootClass);
        return false;
      }
      return true;
    }
  });
  return type[0];
}
项目:intellij-ce-playground    文件:SliceLeafAnalyzer.java   
static SliceNode filterTree(SliceNode oldRoot,
                            NullableFunction<SliceNode, SliceNode> filter,
                            PairProcessor<SliceNode, List<SliceNode>> postProcessor) {
  SliceNode filtered = filter.fun(oldRoot);
  if (filtered == null) return null;

  List<SliceNode> childrenFiltered = new ArrayList<SliceNode>();
  if (oldRoot.myCachedChildren != null) {
    for (SliceNode child : oldRoot.myCachedChildren) {
      SliceNode childFiltered = filterTree(child, filter,postProcessor);
      if (childFiltered != null) {
        childrenFiltered.add(childFiltered);
      }
    }
  }
  boolean success = postProcessor == null || postProcessor.process(filtered, childrenFiltered);
  if (!success) return null;
  filtered.myCachedChildren = new ArrayList<SliceNode>(childrenFiltered);
  return filtered;
}
项目:intellij-ce-playground    文件:RemoteTemplatesFactory.java   
private static List<ArchivedProjectTemplate> createGroupTemplates(Element groupElement) {
  return ContainerUtil.mapNotNull(groupElement.getChildren(TEMPLATE), new NullableFunction<Element, ArchivedProjectTemplate>() {
    @Override
    public ArchivedProjectTemplate fun(final Element element) {
      if (!checkRequiredPlugins(element)) {
        return null;
      }

      final ModuleType moduleType = ModuleTypeManager.getInstance().findByID(element.getChildText("moduleType"));
      final String path = element.getChildText("path");
      final String description = element.getChildTextTrim("description");
      String name = element.getChildTextTrim("name");
      RemoteProjectTemplate template = new RemoteProjectTemplate(name, element, moduleType, path, description);
      template.populateFromElement(element);
      return template;
    }
  });
}
项目:intellij-ce-playground    文件:SmartExtensionPoint.java   
@NotNull
public final List<V> getExtensions() {
  synchronized (myExplicitExtensions) {
    if (myCache == null) {
      myExtensionPoint = getExtensionPoint();
      myExtensionPoint.addExtensionPointListener(this);
      myCache = new ArrayList<V>(myExplicitExtensions);
      myCache.addAll(ContainerUtil.mapNotNull(myExtensionPoint.getExtensions(), new NullableFunction<Extension, V>() {
        @Override
        @Nullable
        public V fun(final Extension extension) {
          return getExtension(extension);
        }
      }));
    }
    return myCache;
  }
}
项目:intellij-ce-playground    文件:NonProjectFileAccessTest.java   
private void typeAndCheck(VirtualFile file,
                          @Nullable final NonProjectFileWritingAccessProvider.UnlockOption option,
                          boolean fileHasBeenChanged) {
  Editor editor = getEditor(file);

  NullableFunction<List<VirtualFile>, NonProjectFileWritingAccessProvider.UnlockOption> unlocker =
    new NullableFunction<List<VirtualFile>, NonProjectFileWritingAccessProvider.UnlockOption>() {
      @Nullable
      @Override
      public NonProjectFileWritingAccessProvider.UnlockOption fun(List<VirtualFile> files) {
        return option;
      }
    };
  NonProjectFileWritingAccessProvider.setCustomUnlocker(unlocker);

  String before = editor.getDocument().getText();
  typeInChar(editor, 'a');

  if (fileHasBeenChanged) {
    assertEquals("Text should be changed", 'a' + before, editor.getDocument().getText());
  }
  else {
    assertEquals("Text should not be changed", before, editor.getDocument().getText());
  }
}
项目:intellij-ce-playground    文件:DvcsTaskHandler.java   
@NotNull
private List<R> getRepositories(@NotNull Collection<String> urls) {
  final List<R> repositories = myRepositoryManager.getRepositories();
  return ContainerUtil.mapNotNull(urls, new NullableFunction<String, R>() {
    @Nullable
    @Override
    public R fun(final String s) {

      return ContainerUtil.find(repositories, new Condition<R>() {
        @Override
        public boolean value(R repository) {
          return s.equals(repository.getPresentableUrl());
        }
      });
    }
  });
}
项目:intellij-ce-playground    文件:CommitHelper.java   
public CommitHelper(final Project project,
                    final ChangeList changeList,
                    final List<Change> includedChanges,
                    final String actionName,
                    final String commitMessage,
                    final List<CheckinHandler> handlers,
                    final boolean allOfDefaultChangeListChangesIncluded,
                    final boolean synchronously, final NullableFunction<Object, Object> additionalDataHolder,
                    @Nullable CommitResultHandler customResultHandler) {
  myProject = project;
  myChangeList = changeList;
  myIncludedChanges = includedChanges;
  myActionName = actionName;
  myCommitMessage = commitMessage;
  myHandlers = handlers;
  myAllOfDefaultChangeListChangesIncluded = allOfDefaultChangeListChangesIncluded;
  myForceSyncCommit = synchronously;
  myAdditionalData = additionalDataHolder;
  myCustomResultHandler = customResultHandler;
  myConfiguration = VcsConfiguration.getInstance(myProject);
  myDirtyScopeManager = VcsDirtyScopeManager.getInstance(myProject);
  myFeedback = new HashSet<String>();
}
项目:intellij-ce-playground    文件:ZipUtil.java   
public static void unzip(@Nullable ProgressIndicator progress,
                         @NotNull File targetDir,
                         @NotNull File zipArchive,
                         @Nullable NullableFunction<String, String> pathConvertor,
                         @Nullable ContentProcessor contentProcessor,
                         boolean unwrapSingleTopLevelFolder) throws IOException {
  File unzipToDir = getUnzipToDir(progress, targetDir, unwrapSingleTopLevelFolder);
  ZipFile zipFile = new ZipFile(zipArchive, ZipFile.OPEN_READ);
  try {
    Enumeration<? extends ZipEntry> entries = zipFile.entries();
    while (entries.hasMoreElements()) {
      ZipEntry entry = entries.nextElement();
      InputStream entryContentStream = zipFile.getInputStream(entry);
      unzipEntryToDir(progress, entry, entryContentStream, unzipToDir, pathConvertor, contentProcessor);
      entryContentStream.close();
    }
  }
  finally {
    zipFile.close();
  }
  doUnwrapSingleTopLevelFolder(unwrapSingleTopLevelFolder, unzipToDir, targetDir);
}
项目:intellij-ce-playground    文件:SemServiceImpl.java   
private MultiMap<SemKey, NullableFunction<PsiElement, ? extends SemElement>> collectProducers() {
  final MultiMap<SemKey, NullableFunction<PsiElement, ? extends SemElement>> map = MultiMap.createSmart();

  final SemRegistrar registrar = new SemRegistrar() {
    @Override
    public <T extends SemElement, V extends PsiElement> void registerSemElementProvider(SemKey<T> key,
                                                                                        final ElementPattern<? extends V> place,
                                                                                        final NullableFunction<V, T> provider) {
      map.putValue(key, new NullableFunction<PsiElement, SemElement>() {
        @Override
        public SemElement fun(PsiElement element) {
          if (place.accepts(element)) {
            return provider.fun((V)element);
          }
          return null;
        }
      });
    }
  };

  for (SemContributorEP contributor : myProject.getExtensions(SemContributor.EP_NAME)) {
    contributor.registerSemProviders(myProject.getPicoContainer(), registrar);
  }

  return map;
}
项目:intellij-ce-playground    文件:SemServiceImpl.java   
@NotNull
private List<SemElement> createSemElements(SemKey key, PsiElement psi) {
  List<SemElement> result = null;
  final Collection<NullableFunction<PsiElement, ? extends SemElement>> producers = myProducers.get(key);
  if (!producers.isEmpty()) {
    for (final NullableFunction<PsiElement, ? extends SemElement> producer : producers) {
      myCreatingSem.incrementAndGet();
      try {
        final SemElement element = producer.fun(psi);
        if (element != null) {
          if (result == null) result = new SmartList<SemElement>();
          result.add(element);
        }
      }
      finally {
        myCreatingSem.decrementAndGet();
      }
    }
  }
  return result == null ? Collections.<SemElement>emptyList() : Collections.unmodifiableList(result);
}
项目:intellij-ce-playground    文件:IndexedRelevantResource.java   
public static <K, V extends Comparable> List<IndexedRelevantResource<K, V>> getAllResources(ID<K, V> indexId,
                                                                                            @Nullable final Module module,
                                                                                            @NotNull Project project,
                                                                                            @Nullable NullableFunction<List<IndexedRelevantResource<K, V>>, IndexedRelevantResource<K, V>> chooser) {
  ArrayList<IndexedRelevantResource<K, V>> all = new ArrayList<IndexedRelevantResource<K, V>>();
  Collection<K> allKeys = FileBasedIndex.getInstance().getAllKeys(indexId, project);
  for (K key : allKeys) {
    List<IndexedRelevantResource<K, V>> resources = getResources(indexId, key, module, project, null);
    if (!resources.isEmpty()) {
      if (chooser == null) {
        all.add(resources.get(0));
      }
      else {
        IndexedRelevantResource<K, V> resource = chooser.fun(resources);
        if (resource != null) {
          all.add(resource);
        }
      }
    }
  }
  return all;
}
项目:intellij-ce-playground    文件:WorkingContextManager.java   
private synchronized List<ContextInfo> getContextHistory(String zipPostfix) {
  JBZipFile archive = null;
  try {
    archive = getTasksArchive(zipPostfix);
    List<JBZipEntry> entries = archive.getEntries();
    return ContainerUtil.mapNotNull(entries, new NullableFunction<JBZipEntry, ContextInfo>() {
      public ContextInfo fun(JBZipEntry entry) {
        return entry.getName().startsWith("/context") ? new ContextInfo(entry.getName(), entry.getTime(), entry.getComment()) : null;
      }
    });
  }
  catch (IOException e) {
    LOG.error(e);
    return Collections.emptyList();
  }
  finally {
    closeArchive(archive);
  }
}
项目:intellij-ce-playground    文件:SvnCheckinEnvironment.java   
public List<VcsException> commit(List<Change> changes,
                                 final String preparedComment,
                                 @NotNull NullableFunction<Object, Object> parametersHolder,
                                 final Set<String> feedback) {
  final List<VcsException> exception = new ArrayList<VcsException>();
  final List<FilePath> committables = getCommitables(changes);
  final ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();

  if (progress != null) {
    doCommit(committables, preparedComment, exception, feedback);
  }
  else if (ApplicationManager.getApplication().isDispatchThread()) {
    ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
      public void run() {
        doCommit(committables, preparedComment, exception, feedback);
      }
    }, SvnBundle.message("progress.title.commit"), false, mySvnVcs.getProject());
  }
  else {
    doCommit(committables, preparedComment, exception, feedback);
  }

  return exception;
}
项目:intellij-ce-playground    文件:PropertiesCopyHandler.java   
@Override
public void doCopy(PsiElement[] elements, PsiDirectory defaultTargetDirectory) {
  final IProperty representative = PropertiesImplUtil.getProperty(elements[0]);
  final String key = representative.getKey();
  if (key == null) {
    return;
  }
  final ResourceBundle resourceBundle = representative.getPropertiesFile().getResourceBundle();
  final List<IProperty> properties = ContainerUtil.mapNotNull(resourceBundle.getPropertiesFiles(),
                                                              new NullableFunction<PropertiesFile, IProperty>() {
                                                                @Nullable
                                                                @Override
                                                                public IProperty fun(PropertiesFile propertiesFile) {
                                                                  return propertiesFile.findPropertyByKey(key);
                                                                }
                                                              });

  final PropertiesCopyDialog dlg = new PropertiesCopyDialog(properties, resourceBundle);
  if (dlg.showAndGet()) {
    final String propertyNewName = dlg.getCurrentPropertyName();
    final ResourceBundle destinationResourceBundle = dlg.getCurrentResourceBundle();
    copyPropertyToAnotherBundle(properties, propertyNewName, destinationResourceBundle);
  }
}
项目:intellij-ce-playground    文件:PropertiesPrefixGroup.java   
@NotNull
@Override
public IProperty[] getProperties() {
  final List<IProperty> elements = ContainerUtil.mapNotNull(getChildren(), new NullableFunction<TreeElement, IProperty>() {
    @Nullable
    @Override
    public IProperty fun(final TreeElement treeElement) {
      if (treeElement instanceof PropertiesStructureViewElement) {
        PropertiesStructureViewElement propertiesElement = (PropertiesStructureViewElement)treeElement;
        return propertiesElement.getValue();
      }
      else if (treeElement instanceof ResourceBundlePropertyStructureViewElement) {
        return ((ResourceBundlePropertyStructureViewElement)treeElement).getProperties()[0];
      }
      return null;
    }
  });
  return elements.toArray(new IProperty[elements.size()]);
}
项目:intellij-ce-playground    文件:LanguageResolvingUtil.java   
private static List<LanguageDefinition> collectLibraryLanguages(final ConvertContext context,
                                                                final Collection<PsiClass> allLanguages) {
  return ContainerUtil.mapNotNull(Language.getRegisteredLanguages(), new NullableFunction<Language, LanguageDefinition>() {
    @Override
    public LanguageDefinition fun(Language language) {
      if (language.getID().isEmpty() ||
          language instanceof DependentLanguage) {
        return null;
      }
      final PsiClass psiClass = DomJavaUtil.findClass(language.getClass().getName(), context.getInvocationElement());
      if (psiClass == null) {
        return null;
      }

      if (!allLanguages.contains(psiClass)) {
        return null;
      }

      final LanguageFileType type = language.getAssociatedFileType();
      final Icon icon = type != null ? type.getIcon() : null;
      return new LanguageDefinition(language.getID(),
                                    psiClass,
                                    icon, language.getDisplayName());
    }
  });
}
项目:intellij-ce-playground    文件:GroovyLanguageInjectionSupport.java   
@Override
public boolean removeInjectionInPlace(@Nullable final PsiLanguageInjectionHost psiElement) {
  if (!isStringLiteral(psiElement)) return false;

  GrLiteralContainer host = (GrLiteralContainer)psiElement;
  final HashMap<BaseInjection, Pair<PsiMethod, Integer>> injectionsMap = ContainerUtil.newHashMap();
  final ArrayList<PsiElement> annotations = new ArrayList<PsiElement>();
  final Project project = host.getProject();
  final Configuration configuration = Configuration.getProjectInstance(project);
  collectInjections(host, configuration, this, injectionsMap, annotations);

  if (injectionsMap.isEmpty() && annotations.isEmpty()) return false;
  final ArrayList<BaseInjection> originalInjections = new ArrayList<BaseInjection>(injectionsMap.keySet());
  final List<BaseInjection> newInjections = ContainerUtil.mapNotNull(originalInjections, new NullableFunction<BaseInjection, BaseInjection>() {
    @Override
    public BaseInjection fun(final BaseInjection injection) {
      final Pair<PsiMethod, Integer> pair = injectionsMap.get(injection);
      final String placeText = JavaLanguageInjectionSupport.getPatternStringForJavaPlace(pair.first, pair.second);
      final BaseInjection newInjection = injection.copy();
      newInjection.setPlaceEnabled(placeText, false);
      return InjectorUtils.canBeRemoved(newInjection) ? null : newInjection;
    }
  });
  configuration.replaceInjectionsWithUndo(project, newInjections, originalInjections, annotations);
  return true;
}
项目:intellij-ce-playground    文件:XsltIncludeIndex.java   
private static boolean _process(VirtualFile[] files, Project project, Processor<XmlFile> processor) {
  final PsiManager psiManager = PsiManager.getInstance(project);
  final PsiFile[] psiFiles = ContainerUtil.map2Array(files, PsiFile.class, new NullableFunction<VirtualFile, PsiFile>() {
    public PsiFile fun(VirtualFile file) {
      return psiManager.findFile(file);
    }
  });
  for (final PsiFile psiFile : psiFiles) {
    if (XsltSupport.isXsltFile(psiFile)) {
      if (!processor.process((XmlFile)psiFile)) {
        return false;
      }
    }
  }
  return true;
}
项目:tools-idea    文件:ExpectedTypesProvider.java   
@Nullable
protected static PsiType checkMethod(@NotNull PsiMethod method, @NotNull @NonNls final String className, @NotNull final NullableFunction<PsiClass,PsiType> function) {
  final PsiClass containingClass = method.getContainingClass();
  if (containingClass == null) return null;

  if (className.equals(containingClass.getQualifiedName())) {
    return function.fun(containingClass);
  }
  final PsiType[] type = {null};
  DeepestSuperMethodsSearch.search(method).forEach(new Processor<PsiMethod>() {
    @Override
    public boolean process(@NotNull PsiMethod psiMethod) {
      final PsiClass rootClass = psiMethod.getContainingClass();
      assert rootClass != null;
      if (className.equals(rootClass.getQualifiedName())) {
        type[0] = function.fun(rootClass);
        return false;
      }
      return true;
    }
  });
  return type[0];
}
项目:tools-idea    文件:SliceLeafAnalyzer.java   
static SliceNode filterTree(SliceNode oldRoot, NullableFunction<SliceNode, SliceNode> filter, PairProcessor<SliceNode, List<SliceNode>> postProcessor){
  SliceNode filtered = filter.fun(oldRoot);
  if (filtered == null) return null;

  List<SliceNode> childrenFiltered = new ArrayList<SliceNode>();
  if (oldRoot.myCachedChildren != null) {
    for (SliceNode child : oldRoot.myCachedChildren) {
      SliceNode childFiltered = filterTree(child, filter,postProcessor);
      if (childFiltered != null) {
        childrenFiltered.add(childFiltered);
      }
    }
  }
  boolean success = postProcessor == null || postProcessor.process(filtered, childrenFiltered);
  if (!success) return null;
  filtered.myCachedChildren = new ArrayList<SliceNode>(childrenFiltered);
  return filtered;
}
项目:tools-idea    文件:SmartExtensionPoint.java   
@NotNull
public final List<V> getExtensions() {
  synchronized (myExplicitExtensions) {
    if (myCache == null) {
      myExtensionPoint = getExtensionPoint();
      myExtensionPoint.addExtensionPointListener(this);
      myCache = new ArrayList<V>(myExplicitExtensions);
      myCache.addAll(ContainerUtil.mapNotNull(myExtensionPoint.getExtensions(), new NullableFunction<Extension, V>() {
        @Override
        @Nullable
        public V fun(final Extension extension) {
          return getExtension(extension);
        }
      }));
    }
    return myCache;
  }
}
项目:tools-idea    文件:EditorGutterComponentImpl.java   
private void doPaintFoldingTree(final Graphics2D g, final Rectangle clip, int firstVisibleOffset, int lastVisibleOffset) {
  final int anchorX = getFoldingAreaOffset();
  final int width = getFoldingAnchorWidth();

  doForVisibleFoldRegions(
    new NullableFunction<FoldRegion, Void>() {
      @Override
      public Void fun(FoldRegion foldRegion) {
        drawAnchor(foldRegion, width, clip, g, anchorX, false, false);
        return null;
      }
    },
    firstVisibleOffset,
    lastVisibleOffset
  );

  if (myActiveFoldRegion != null) {
    drawAnchor(myActiveFoldRegion, width, clip, g, anchorX, true, true);
    drawAnchor(myActiveFoldRegion, width, clip, g, anchorX, true, false);
  }
}
项目:tools-idea    文件:EditorGutterComponentImpl.java   
private void doForVisibleFoldRegions(@NotNull NullableFunction<FoldRegion, Void> action, int firstVisibleOffset, int lastVisibleOffset) {
  FoldRegion[] visibleFoldRegions = myEditor.getFoldingModel().fetchVisible();
  final Document document = myEditor.getDocument();
  for (FoldRegion visibleFoldRegion : visibleFoldRegions) {
    if (!visibleFoldRegion.isValid()) continue;
    final int startOffset = visibleFoldRegion.getStartOffset();
    if (startOffset > lastVisibleOffset) continue;
    final int endOffset = getEndOffset(visibleFoldRegion);
    if (endOffset < firstVisibleOffset) continue;
    if (document.getLineNumber(startOffset) >= document.getLineNumber(endOffset)) {
      //TODO den remove this check as soon as editor performance on dimension mapping is improved (IDEA-69317)
      continue;
    }
    action.fun(visibleFoldRegion);
  }
}
项目:tools-idea    文件:EditorGutterComponentImpl.java   
private void doPaintFoldingBoxBackground(final Graphics2D g, final Rectangle clip, int firstVisibleOffset, int lastVisibleOffset) {
  if (!isFoldingOutlineShown()) return;

  UIUtil.drawVDottedLine(g, getWhitespaceSeparatorOffset(), clip.y, clip.y + clip.height, null, getOutlineColor(false));

  final int anchorX = getFoldingAreaOffset();
  final int width = getFoldingAnchorWidth();

  if (myActiveFoldRegion != null) {
    drawFoldingLines(myActiveFoldRegion, clip, width, anchorX, g);
  }

  doForVisibleFoldRegions(
    new NullableFunction<FoldRegion, Void>() {
      @Override
      public Void fun(FoldRegion foldRegion) {
        drawAnchor(foldRegion, width, clip, g, anchorX, false, true);
        return null;
      }
    },
    firstVisibleOffset,
    lastVisibleOffset
  );
}
项目:tools-idea    文件:CommitHelper.java   
public CommitHelper(final Project project,
                    final ChangeList changeList,
                    final List<Change> includedChanges,
                    final String actionName,
                    final String commitMessage,
                    final List<CheckinHandler> handlers,
                    final boolean allOfDefaultChangeListChangesIncluded,
                    final boolean synchronously, final NullableFunction<Object, Object> additionalDataHolder,
                    @Nullable CommitResultHandler customResultHandler) {
  myProject = project;
  myChangeList = changeList;
  myIncludedChanges = includedChanges;
  myActionName = actionName;
  myCommitMessage = commitMessage;
  myHandlers = handlers;
  myAllOfDefaultChangeListChangesIncluded = allOfDefaultChangeListChangesIncluded;
  myForceSyncCommit = synchronously;
  myAdditionalData = additionalDataHolder;
  myCustomResultHandler = customResultHandler;
  myConfiguration = VcsConfiguration.getInstance(myProject);
  myDirtyScopeManager = VcsDirtyScopeManager.getInstance(myProject);
  myFeedback = new HashSet<String>();
}
项目:tools-idea    文件:SemServiceImpl.java   
@NotNull
private List<SemElement> createSemElements(SemKey key, PsiElement psi) {
  List<SemElement> result = null;
  final Collection<NullableFunction<PsiElement, ? extends SemElement>> producers = myProducers.get(key);
  if (!producers.isEmpty()) {
    for (final NullableFunction<PsiElement, ? extends SemElement> producer : producers) {
      myCreatingSem.incrementAndGet();
      try {
        final SemElement element = producer.fun(psi);
        if (element != null) {
          if (result == null) result = new SmartList<SemElement>();
          result.add(element);
        }
      }
      finally {
        myCreatingSem.decrementAndGet();
      }
    }
  }
  return result == null ? Collections.<SemElement>emptyList() : Collections.unmodifiableList(result);
}
项目:tools-idea    文件:IndexedRelevantResource.java   
public static <K, V extends Comparable> List<IndexedRelevantResource<K, V>> getAllResources(ID<K, V> indexId,
                                                                                            @Nullable final Module module,
                                                                                            @NotNull Project project,
                                                                                            @Nullable NullableFunction<List<IndexedRelevantResource<K, V>>, IndexedRelevantResource<K, V>> chooser) {
  ArrayList<IndexedRelevantResource<K, V>> all = new ArrayList<IndexedRelevantResource<K, V>>();
  Collection<K> allKeys = FileBasedIndex.getInstance().getAllKeys(indexId, project);
  for (K key : allKeys) {
    List<IndexedRelevantResource<K, V>> resources = getResources(indexId, key, module, project, null);
    if (!resources.isEmpty()) {
      if (chooser == null) {
        all.add(resources.get(0));
      }
      else {
        IndexedRelevantResource<K, V> resource = chooser.fun(resources);
        if (resource != null) {
          all.add(resource);
        }
      }
    }
  }
  return all;
}
项目:tools-idea    文件:XmlRefCountHolder.java   
private void registerId(@NotNull final String id, @NotNull final XmlAttributeValue attributeValue, final boolean soft) {
  List<Pair<XmlAttributeValue, Boolean>> list = myId2AttributeListMap.get(id);
  if (list == null) {
    list = new ArrayList<Pair<XmlAttributeValue, Boolean>>();
    myId2AttributeListMap.put(id, list);
  }
  else if (!soft) {
    // mark as duplicate
    List<XmlAttributeValue> notSoft = ContainerUtil.mapNotNull(list, new NullableFunction<Pair<XmlAttributeValue, Boolean>, XmlAttributeValue>() {
      @Override
      public XmlAttributeValue fun(Pair<XmlAttributeValue, Boolean> pair) {
        return pair.second ? null : pair.first;
      }
    });
    if (!notSoft.isEmpty()) {
      myPossiblyDuplicateIds.addAll(notSoft);
      myPossiblyDuplicateIds.add(attributeValue);
    }
  }

  list.add(new Pair<XmlAttributeValue, Boolean>(attributeValue, soft));
}
项目:tools-idea    文件:WorkingContextManager.java   
private synchronized List<ContextInfo> getContextHistory(String zipPostfix) {
  JBZipFile archive = null;
  try {
    archive = getTasksArchive(zipPostfix);
    List<JBZipEntry> entries = archive.getEntries();
    return ContainerUtil.mapNotNull(entries, new NullableFunction<JBZipEntry, ContextInfo>() {
      public ContextInfo fun(JBZipEntry entry) {
        return entry.getName().startsWith("/context") ? new ContextInfo(entry.getName(), entry.getTime(), entry.getComment()) : null;
      }
    });
  }
  catch (IOException e) {
    LOG.error(e);
    return Collections.emptyList();
  }
  finally {
    closeArchive(archive);
  }
}
项目:tools-idea    文件:MantisRepository.java   
private List<Task> getIssues(final int page, final int issuesOnPage, final MantisConnectPortType soap) throws Exception {
  IssueHeaderData[] issues;
  if (MantisFilter.LAST_TASKS.equals(myFilter)) {
    issues =
      soap.mc_project_get_issue_headers(getUsername(), getPassword(), BigInteger.valueOf(myProject.getId()), BigInteger.valueOf(page),
                                        BigInteger.valueOf(issuesOnPage));
  }
  else {
    issues = soap.mc_filter_get_issue_headers(getUsername(), getPassword(), BigInteger.valueOf(myProject.getId()),
                                              BigInteger.valueOf(myFilter.getId()), BigInteger.valueOf(page),
                                              BigInteger.valueOf(issuesOnPage));
  }
  return ContainerUtil.mapNotNull(issues, new NullableFunction<IssueHeaderData, Task>() {
    public Task fun(IssueHeaderData issueData) {
      return createIssue(issueData);
    }
  });
}
项目:tools-idea    文件:GitTaskHandler.java   
private List<GitRepository> getRepositories(Collection<String> urls) {
  final List<GitRepository> repositories = myRepositoryManager.getRepositories();
  return ContainerUtil.mapNotNull(urls, new NullableFunction<String, GitRepository>() {
    @Nullable
    @Override
    public GitRepository fun(final String s) {

      return ContainerUtil.find(repositories, new Condition<GitRepository>() {
        @Override
        public boolean value(GitRepository repository) {
          return s.equals(repository.getPresentableUrl());
        }
      });
    }
  });
}
项目:tools-idea    文件:JavaLanguageInjectionSupport.java   
public boolean removeInjectionInPlace(final PsiLanguageInjectionHost psiElement) {
  if (!isMine(psiElement)) return false;
  final HashMap<BaseInjection, Pair<PsiMethod, Integer>> injectionsMap = new HashMap<BaseInjection, Pair<PsiMethod, Integer>>();
  final ArrayList<PsiElement> annotations = new ArrayList<PsiElement>();
  final PsiLiteralExpression host = (PsiLiteralExpression)psiElement;
  final Project project = host.getProject();
  final Configuration configuration = Configuration.getProjectInstance(project);
  collectInjections(host, configuration, this, injectionsMap, annotations);

  if (injectionsMap.isEmpty() && annotations.isEmpty()) return false;
  final ArrayList<BaseInjection> originalInjections = new ArrayList<BaseInjection>(injectionsMap.keySet());
  final List<BaseInjection> newInjections = ContainerUtil.mapNotNull(originalInjections, new NullableFunction<BaseInjection, BaseInjection>() {
    public BaseInjection fun(final BaseInjection injection) {
      final Pair<PsiMethod, Integer> pair = injectionsMap.get(injection);
      final String placeText = getPatternStringForJavaPlace(pair.first, pair.second);
      final BaseInjection newInjection = injection.copy();
      newInjection.setPlaceEnabled(placeText, false);
      return InjectorUtils.canBeRemoved(newInjection)? null : newInjection;
    }
  });
  configuration.replaceInjectionsWithUndo(project, newInjections, originalInjections, annotations);
  return true;
}
项目:tools-idea    文件:XsltIncludeIndex.java   
private static boolean _process(VirtualFile[] files, Project project, Processor<XmlFile> processor) {
  final PsiManager psiManager = PsiManager.getInstance(project);
  final PsiFile[] psiFiles = ContainerUtil.map2Array(files, PsiFile.class, new NullableFunction<VirtualFile, PsiFile>() {
    public PsiFile fun(VirtualFile file) {
      return psiManager.findFile(file);
    }
  });
  for (final PsiFile psiFile : psiFiles) {
    if (XsltSupport.isXsltFile(psiFile)) {
      if (!processor.process((XmlFile)psiFile)) {
        return false;
      }
    }
  }
  return true;
}
项目:consulo-lua    文件:LuaMethodSeparatorMarkerProvider.java   
@RequiredReadAction
@Nullable
@Override
public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement element)
{
    if(myDaemonSettings.SHOW_METHOD_SEPARATORS)
    {
        if(element instanceof LuaDocComment)
        {
            LuaDocCommentOwner owner = ((LuaDocComment) element).getOwner();

            if(owner instanceof LuaFunctionDefinition)
            {
                TextRange range = new TextRange(element.getTextOffset(), owner.getTextRange().getEndOffset());
                LineMarkerInfo<PsiElement> info = new LineMarkerInfo<>(element, range, null, Pass.UPDATE_ALL, NullableFunction.NULL, null, GutterIconRenderer.Alignment.RIGHT);
                EditorColorsScheme scheme = myColorsManager.getGlobalScheme();
                info.separatorColor = scheme.getColor(CodeInsightColors.METHOD_SEPARATORS_COLOR);
                info.separatorPlacement = SeparatorPlacement.TOP;
                return info;
            }
        }
    }
    return null;
}
项目:consulo-haxe    文件:HaxePsiPackageReferenceSet.java   
public Collection<HaxePackage> resolvePackage()
{
    final HaxePsiPackageReference packageReference = getLastReference();
    if(packageReference == null)
    {
        return Collections.emptyList();
    }
    return ContainerUtil.map2List(packageReference.multiResolve(false), new NullableFunction<ResolveResult, HaxePackage>()
    {
        @Override
        public HaxePackage fun(final ResolveResult resolveResult)
        {
            return (HaxePackage) resolveResult.getElement();
        }
    });
}
项目:consulo-javaee    文件:JamAttributeMeta.java   
@NotNull
protected <T> List<T> getCollectionJam(PsiElementRef<PsiAnnotation> annoRef, NullableFunction<PsiAnnotationMemberValue, T> producer) {
  final PsiAnnotationMemberValue attr = getAttributeLink().findLinkedChild(annoRef.getPsiElement());
  if (attr == null) {
    return Collections.emptyList();
  }

  final ArrayList<T> result = new ArrayList<>();
  if (attr instanceof PsiArrayInitializerMemberValue) {
    for (PsiAnnotationMemberValue value : ((PsiArrayInitializerMemberValue)attr).getInitializers()) {
      ContainerUtil.addIfNotNull(result, producer.fun(value));
    }
  } else {
    ContainerUtil.addIfNotNull(result, producer.fun(attr));
  }
  return result;
}
项目:consulo-tasks    文件:WorkingContextManager.java   
private synchronized List<ContextInfo> getContextHistory(String zipPostfix) {
  JBZipFile archive = null;
  try {
    archive = getTasksArchive(zipPostfix);
    List<JBZipEntry> entries = archive.getEntries();
    return ContainerUtil.mapNotNull(entries, new NullableFunction<JBZipEntry, ContextInfo>() {
      public ContextInfo fun(JBZipEntry entry) {
        return entry.getName().startsWith("/context") ? new ContextInfo(entry.getName(), entry.getTime(), entry.getComment()) : null;
      }
    });
  }
  catch (IOException e) {
    LOG.error(e);
    return Collections.emptyList();
  }
  finally {
    closeArchive(archive);
  }
}
项目:consulo-tasks    文件:MantisRepository.java   
private List<Task> getIssues(final int page, final int issuesOnPage, final MantisConnectPortType soap) throws Exception {
  IssueHeaderData[] issues;
  if (MantisFilter.LAST_TASKS.equals(myFilter)) {
    issues =
      soap.mc_project_get_issue_headers(getUsername(), getPassword(), BigInteger.valueOf(myProject.getId()), BigInteger.valueOf(page),
                                        BigInteger.valueOf(issuesOnPage));
  }
  else {
    issues = soap.mc_filter_get_issue_headers(getUsername(), getPassword(), BigInteger.valueOf(myProject.getId()),
                                              BigInteger.valueOf(myFilter.getId()), BigInteger.valueOf(page),
                                              BigInteger.valueOf(issuesOnPage));
  }
  return ContainerUtil.mapNotNull(issues, new NullableFunction<IssueHeaderData, Task>() {
    public Task fun(IssueHeaderData issueData) {
      return createIssue(issueData);
    }
  });
}
项目:consulo    文件:SmartExtensionPoint.java   
@Nonnull
public final List<V> getExtensions() {
  synchronized (myExplicitExtensions) {
    if (myCache == null) {
      myExtensionPoint = getExtensionPoint();
      myExtensionPoint.addExtensionPointListener(this);
      myCache = new ArrayList<V>(myExplicitExtensions);
      myCache.addAll(ContainerUtil.mapNotNull(myExtensionPoint.getExtensions(), new NullableFunction<Extension, V>() {
        @Override
        @Nullable
        public V fun(final Extension extension) {
          return getExtension(extension);
        }
      }));
    }
    return myCache;
  }
}
项目:consulo    文件:DvcsTaskHandler.java   
@Nonnull
private List<R> getRepositories(@Nonnull Collection<String> urls) {
  final List<R> repositories = myRepositoryManager.getRepositories();
  return ContainerUtil.mapNotNull(urls, new NullableFunction<String, R>() {
    @Nullable
    @Override
    public R fun(final String s) {

      return ContainerUtil.find(repositories, new Condition<R>() {
        @Override
        public boolean value(R repository) {
          return s.equals(repository.getPresentableUrl());
        }
      });
    }
  });
}