Java Code Examples for com.intellij.openapi.util.Computable#compute()

The following examples show how to use com.intellij.openapi.util.Computable#compute() . 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: StubSerializationHelper.java    From consulo with Apache License 2.0 6 votes vote down vote up
void assignId(@Nonnull Computable<ObjectStubSerializer> serializer, String name) throws IOException {
  Computable<ObjectStubSerializer> old = myNameToLazySerializer.put(name, serializer);
  if (old != null) {
    ObjectStubSerializer existing = old.compute();
    ObjectStubSerializer computed = serializer.compute();
    if (existing != computed) {
      throw new AssertionError("ID: " + name + " is not unique, but found in both " + existing.getClass().getName() + " and " + computed.getClass().getName());
    }
    return;
  }

  int id;
  if (myUnmodifiable) {
    id = myNameStorage.tryEnumerate(name);
    if (id == 0) {
      LOG.debug("serialized " + name + " is ignored in unmodifiable stub serialization manager");
      return;
    }
  }
  else {
    id = myNameStorage.enumerate(name);
  }
  myIdToName.put(id, name);
  myNameToId.put(name, id);
}
 
Example 2
Source File: PantsMetadataService.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void removeData(
  @NotNull Computable<Collection<Module>> toRemove,
  @NotNull Collection<DataNode<TargetMetadata>> toIgnore,
  @NotNull ProjectData projectData,
  @NotNull Project project,
  @NotNull IdeModifiableModelsProvider modelsProvider
) {
  for (Module module : toRemove.compute()) {
    module.clearOption(PantsConstants.PANTS_TARGET_ADDRESSES_KEY);
  }
}
 
Example 3
Source File: HighlightDisplayKey.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static String getDisplayNameByKey(@Nullable HighlightDisplayKey key) {
  if (key == null) {
    return null;
  }
  else {
    final Computable<String> computable = ourKeyToDisplayNameMap.get(key);
    return computable == null ? null : computable.compute();
  }
}
 
Example 4
Source File: BaseApplication.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public <T> T runReadAction(@Nonnull final Computable<T> computation) {
  if (checkReadAccessAllowedAndNoPendingWrites()) {
    return computation.compute();
  }
  startRead();
  try {
    return computation.compute();
  }
  finally {
    endRead();
  }
}
 
Example 5
Source File: LayoutFocusTraversalPolicyExt.java    From consulo with Apache License 2.0 5 votes vote down vote up
public Component queryImpl(Computable<Component> runnable) {
  try {
    myQueryImpl = true;
    return runnable.compute();
  }
  finally {
    myQueryImpl = false;
  }
}
 
Example 6
Source File: CodeCompletionHandlerBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private <T> T withTimeout(long maxDurationMillis, @Nonnull Computable<T> task) {
  if (isTestingMode()) {
    return task.compute();
  }

  return ProgressIndicatorUtils.withTimeout(maxDurationMillis, task);
}
 
Example 7
Source File: StubSerializationHelper.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private ObjectStubSerializer instantiateSerializer(int id, @Nullable Stub parentStub) throws SerializerNotFoundException {
  String name = myIdToName.get(id);
  Computable<ObjectStubSerializer> lazy = name == null ? null : myNameToLazySerializer.get(name);
  ObjectStubSerializer serializer = lazy == null ? null : lazy.compute();
  if (serializer == null) {
    throw reportMissingSerializer(id, parentStub);
  }
  return serializer;
}
 
Example 8
Source File: PsiProximityComparator.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static WeighingComparable<PsiElement, ProximityLocation> getProximity(final Computable<? extends PsiElement> elementComputable, final PsiElement context, ProcessingContext processingContext) {
  PsiElement element = elementComputable.compute();
  if (element == null || context == null) return null;
  Module contextModule = processingContext.get(MODULE_BY_LOCATION);
  if (contextModule == null) {
    contextModule = ModuleUtilCore.findModuleForPsiElement(context);
    processingContext.put(MODULE_BY_LOCATION, contextModule);
  }

  return new WeighingComparable<>(elementComputable, new ProximityLocation(context, contextModule, processingContext), getProximityWeighers());
}
 
Example 9
Source File: FormatterImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public <T> T runWithFormattingDisabled(@Nonnull Computable<T> runnable) {
  disableFormatting();
  try {
    return runnable.compute();
  }
  finally {
    enableFormatting();
  }
}
 
Example 10
Source File: PopupChooserBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void addCancelCallback(Computable<Boolean> cbb) {
  Computable<Boolean> callback = myCancelCallback;
  myCancelCallback = () -> cbb.compute() && (callback == null || callback.compute());
}
 
Example 11
Source File: MockApplication.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public <T> T runReadAction(@Nonnull Computable<T> computation) {
  return computation.compute();
}
 
Example 12
Source File: MockApplication.java    From consulo with Apache License 2.0 4 votes vote down vote up
@RequiredUIAccess
@Override
public <T> T runWriteAction(@Nonnull Computable<T> computation) {
  return computation.compute();
}
 
Example 13
Source File: LookupImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private <T> T withLock(Computable<T> computable) {
  synchronized (myArrangerLock) {
    return computable.compute();
  }
}