Java Code Examples for com.intellij.util.NullableFunction#fun()

The following examples show how to use com.intellij.util.NullableFunction#fun() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SdkComboBox.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@SuppressWarnings("unchecked")
public <T extends MutableModuleExtension<?>> void insertModuleItems(@Nonnull T moduleExtension,
                                                                    @Nonnull NullableFunction<T, MutableModuleInheritableNamedPointer<Sdk>> sdkPointerFunction) {

  for (Module module : ModuleManager.getInstance(moduleExtension.getModule().getProject()).getModules()) {
    // dont add self module
    if (module == moduleExtension.getModule()) {
      continue;
    }

    ModuleExtension extension = ModuleUtilCore.getExtension(module, moduleExtension.getId());
    if (extension == null) {
      continue;
    }
    MutableModuleInheritableNamedPointer<Sdk> sdkPointer = sdkPointerFunction.fun((T)extension);
    if (sdkPointer != null) {
      // recursive depend
      if (sdkPointer.getModule() == moduleExtension.getModule()) {
        continue;
      }
      addItem(new ModuleExtensionSdkComboBoxItem(extension, sdkPointer));
    }
  }
}
 
Example 2
Source File: SemServiceImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
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<>();
          result.add(element);
        }
      }
      finally {
        myCreatingSem.decrementAndGet();
      }
    }
  }
  return result == null ? Collections.emptyList() : Collections.unmodifiableList(result);
}
 
Example 3
Source File: PsalmValidatorConfigurationProvider.java    From idea-php-generics-plugin with MIT License 5 votes vote down vote up
protected void fillSettingsByDefaultValue(@NotNull PsalmValidatorConfiguration settings, @NotNull PsalmValidatorConfiguration localConfiguration, @NotNull NullableFunction<String, String> preparePath) {
    super.fillSettingsByDefaultValue(settings, localConfiguration, preparePath);

    String toolPath = preparePath.fun(localConfiguration.getToolPath());
    if (StringUtil.isNotEmpty(toolPath)) {
        settings.setToolPath(toolPath);
    }

    settings.setTimeout(localConfiguration.getTimeout());
}
 
Example 4
Source File: PhpStanValidatorConfigurationProvider.java    From idea-php-generics-plugin with MIT License 5 votes vote down vote up
protected void fillSettingsByDefaultValue(@NotNull PhpStanValidatorConfiguration settings, @NotNull PhpStanValidatorConfiguration localConfiguration, @NotNull NullableFunction<String, String> preparePath) {
    super.fillSettingsByDefaultValue(settings, localConfiguration, preparePath);

    String toolPath = preparePath.fun(localConfiguration.getToolPath());
    if (StringUtil.isNotEmpty(toolPath)) {
        settings.setToolPath(toolPath);
    }

    settings.setTimeout(localConfiguration.getTimeout());
}
 
Example 5
Source File: SubmitModel.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static List<P4Job> getJobs(@NotNull NullableFunction<Object, Object> dataSupplier) {
    Object ret = dataSupplier.fun("jobIds");
    if (ret != null) {
        return (List<P4Job>) ret;
    }
    return Collections.emptyList();
}
 
Example 6
Source File: SubmitModel.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
@Nullable
public static JobStatus getSubmitStatus(@NotNull NullableFunction<Object, Object> dataSupplier) {
    final Object ret = dataSupplier.fun("jobStatus");
    if (ret != null) {
        return (JobStatus) ret;
    }
    return null;
}
 
Example 7
Source File: ExternalSystemApiUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static <K, V> Map<K, List<V>> groupBy(@Nonnull Collection<V> nodes, @Nonnull NullableFunction<V, K> grouper) {
  Map<K, List<V>> result = ContainerUtilRt.newHashMap();
  for (V data : nodes) {
    K key = grouper.fun(data);
    if (key == null) {
      LOG.warn(String.format(
              "Skipping entry '%s' during grouping. Reason: it's not possible to build a grouping key with grouping strategy '%s'. " + "Given entries: %s",
              data, grouper.getClass(), nodes));
      continue;
    }
    List<V> grouped = result.get(key);
    if (grouped == null) {
      result.put(key, grouped = ContainerUtilRt.newArrayList());
    }
    grouped.add(data);
  }

  if (!result.isEmpty() && result.keySet().iterator().next() instanceof Comparable) {
    List<K> ordered = ContainerUtilRt.newArrayList(result.keySet());
    Collections.sort(ordered, COMPARABLE_GLUE);
    Map<K, List<V>> orderedResult = ContainerUtilRt.newLinkedHashMap();
    for (K k : ordered) {
      orderedResult.put(k, result.get(k));
    }
    return orderedResult;
  }
  return result;
}
 
Example 8
Source File: PsiFileGistImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
PsiFileGistImpl(@Nonnull String id, int version, @Nonnull DataExternalizer<Data> externalizer, @Nonnull NullableFunction<PsiFile, Data> calculator) {
  myCalculator = (project, file) -> {
    PsiFile psiFile = getPsiFile(project, file);
    return psiFile == null ? null : calculator.fun(psiFile);
  };
  myPersistence = GistManager.getInstance().newVirtualFileGist(id, version, externalizer, myCalculator);
  myCacheKey = Key.create("PsiFileGist " + id);
}