public static void addDebuggerAgent(JavaParameters parameters, @Nullable Project project, boolean checkJdkVersion) {
    if (AsyncStacksUtils.isAgentEnabled()) {
      String prefix = "-javaagent:";
      ParametersList parametersList = parameters.getVMParametersList();
      if (!ContainerUtil.exists(parametersList.getParameters(), p -> p.startsWith(prefix) && p.contains(AGENT_JAR_NAME))) {
        Sdk jdk = parameters.getJdk();
        if (checkJdkVersion && jdk == null) {
          return;
        }
        JavaSdkVersion sdkVersion = jdk != null ? JavaSdk.getInstance().getVersion(jdk) : null;
        if (checkJdkVersion && (sdkVersion == null || !sdkVersion.isAtLeast(JavaSdkVersion.JDK_1_7))) {
          LOG.warn("Capture agent is not supported for JRE " + sdkVersion);
          return;
        }
        Path agentArtifactPath;

        Path classesRoot = Path.of(PathUtil.getJarPathForClass(DebuggerManagerImpl.class));
        // isDirectory(classesRoot) is used instead of `PluginManagerCore.isRunningFromSources()`
        // because we want to use installer's layout when running "IDEA (dev build)" run configuration
        // where the layout is quite the same as in installers.
        // but `PluginManagerCore.isRunningFromSources()` still returns `true` in this case
        if (Files.isDirectory(classesRoot)) {
          // Code runs from IDEA run configuration (code from .class file in out/ directory)
          try {
            // The agent file must have a fixed name (AGENT_JAR_NAME) which is mentioned in MANIFEST.MF inside
            Path debuggerAgentDir =
              FileUtil.createTempDirectory(new File(PathManager.getTempPath()), "debugger-agent", "", true).toPath();
            agentArtifactPath = debuggerAgentDir.resolve(AGENT_JAR_NAME);

            Path communityRoot = Path.of(PathManager.getCommunityHomePath());
            Path iml = BuildDependenciesJps.getProjectModule(communityRoot, "intellij.java.debugger.agent.holder");
            Path downloadedAgent = BuildDependenciesJps.getModuleLibrarySingleRoot(
              iml,
              "debugger-agent",
              "https://cache-redirector.jetbrains.com/intellij-dependencies",
              new BuildDependenciesCommunityRoot(Path.of(PathManager.getCommunityHomePath())));

            Files.copy(downloadedAgent, agentArtifactPath);
          }
          catch (IOException e) {
            throw new RuntimeException(e);
          }
        }
        else {
          agentArtifactPath = classesRoot.resolveSibling("rt").resolve(AGENT_JAR_NAME);
        }

        if (Files.exists(agentArtifactPath)) {
          String agentPath = JavaExecutionUtil.handleSpacesInAgentPath(agentArtifactPath.toAbsolutePath().toString(),
                                                                       "captureAgent", null,
                                                                       f -> f.getName().startsWith("debugger-agent"));
          if (agentPath != null) {
            try (AccessToken ignore = SlowOperations.knownIssue("IDEA-307303, EA-835503")) {
              parametersList.add(prefix + agentPath + generateAgentSettings(project));
            }
          }
        }
        else {
          LOG.error("Capture agent not found: " + agentArtifactPath);
        }
      }
      if (Registry.is("debugger.async.stacks.coroutines", false)) {
        parametersList.addProperty("kotlinx.coroutines.debug.enable.creation.stack.trace", "false");
        parametersList.addProperty("debugger.agent.enable.coroutines", "true");
      }
    }
  }
public static void addDebuggerAgent(JavaParameters parameters, @Nullable Project project, boolean checkJdkVersion)