// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.util;

import org.jetbrains.annotations.NotNull;

import java.util.function.Supplier;

/**
 * Use this class to evaluate a computable with default bundle.
 * <p>
 * It can be useful if a language plugin enabled, but some computation should be invoked with default locale, e.g., getting actions' default text/description.
 */
public class DefaultBundleService {
  private static final DefaultBundleService INSTANCE = new DefaultBundleService();
  private static final ThreadLocal<Boolean> ourDefaultBundle = ThreadLocal.withInitial(() -> false);

  @NotNull
  public static DefaultBundleService getInstance() {
    return INSTANCE;
  }

  @NotNull
  public <T> T compute(@NotNull Supplier<? extends T> computable) {
    ourDefaultBundle.set(true);
    try {
      return computable.get();
    }
    finally {
      ourDefaultBundle.set(false);
    }
  }

  public static boolean isDefaultBundle() {
    return ourDefaultBundle.get();
  }
}
@@ -866,24 +866,97 @@
 mputable) %7B%0A
+    final boolean isDefault = isDefaultBundle();%0A    if (!isDefault) %7B%0A  
     ourDefau
@@ -971,24 +971,30 @@
 .set(true);%0A
+    %7D%0A
     try %7B%0A  
@@ -1038,24 +1038,50 @@
   finally %7B%0A
+      if (!isDefault) %7B%0A  
       ourDef
@@ -1099,24 +1099,32 @@
 set(false);%0A
+      %7D%0A
     %7D%0A  %7D%0A%0A 

support reentrancy