package org.jetbrains.debugger;

import com.intellij.openapi.util.ActionCallback;
import com.intellij.openapi.util.AsyncResult;
import com.intellij.openapi.util.AsyncValueLoaderManager;
import com.intellij.util.CommonProcessors;
import com.intellij.util.Processor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public abstract class ScriptManagerBase<SCRIPT extends ScriptBase> implements ScriptManager {
  @SuppressWarnings("unchecked")
  private final AsyncValueLoaderManager<ScriptBase, String> scriptSourceLoader = new AsyncValueLoaderManager<ScriptBase, String>(ScriptBase.UPDATER) {
    @Override
    public void load(@NotNull ScriptBase script, @NotNull AsyncResult<String> result) {
      //noinspection unchecked
      loadScriptSource((SCRIPT)script, result);
    }
  };

  protected abstract void loadScriptSource(SCRIPT script, AsyncResult<String> result);

  @NotNull
  @Override
  public AsyncResult<String> getSource(@NotNull Script script) {
    if (!containsScript(script)) {
      return AsyncResult.rejected();
    }
    //noinspection unchecked
    return scriptSourceLoader.get((SCRIPT)script);
  }

  @Override
  public boolean hasSource(Script script) {
    //noinspection unchecked
    return scriptSourceLoader.has((SCRIPT)script);
  }

  public void setSource(@NotNull SCRIPT script, @Nullable String source) {
    scriptSourceLoader.set(script, source);
  }

  @Nullable
  @Override
  public ActionCallback getScriptSourceMapLoadCallback(@NotNull Script script) {
    return null;
  }

  @Override
  public Script forEachScript(@NotNull CommonProcessors.FindProcessor<Script> scriptProcessor) {
    forEachScript(((Processor<Script>)scriptProcessor));
    return scriptProcessor.getFoundValue();
  }
}
@@ -258,16 +258,46 @@
 cessor;%0A
+import com.intellij.util.Url;%0A
 import o
@@ -1789,10 +1789,218 @@
 e();%0A  %7D
+%0A%0A  public static boolean isSpecial(@NotNull Url url) %7B%0A    return !url.isInLocalFileSystem() && (url.getScheme() == null %7C%7C url.getScheme().equals(ScriptManager.VM_SCHEME) %7C%7C url.getAuthority() == null);%0A  %7D
 %0A%7D

remove dependency on JavaScriptDebugger