/*
 * Bach - Java Shell Builder
 * Copyright (C) 2020 Christian Stein
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package de.sormuras.bach.tool;

import java.util.List;

/** A {@code javac} tool call configuration. */
public final class Javac implements Call<Javac> {

  public static Javac of() {
    return new Javac(List.of());
  }

  private final List<Argument> arguments;

  public Javac(List<Argument> arguments) {
    this.arguments = arguments;
  }

  @Override
  public String name() {
    return "javac";
  }

  @Override
  public List<Argument> arguments() {
    return arguments;
  }

  @Override
  public Javac with(List<Argument> arguments) {
    return new Javac(arguments);
  }

  public Javac withTerminateCompilationIfWarningsOccur() {
    return with("-W" + "error");
  }

  public Javac withCompileForJavaRelease(int release) {
    return with("--release", release);
  }

  public Javac withRecommendedWarnings() {
    return with("-X" + "lint");
  }

  public Javac withWarnings(String key, String... more) {
    var moreKeys = more.length == 0 ? "" : ',' + String.join(",", more);
    return with("-X" + "lint:" + key + moreKeys);
  }
}

@@ -681,16 +681,38 @@
 il.List;
+%0Aimport java.util.Map;
 %0A%0A/** A 
@@ -1500,32 +1500,689 @@
 + %22lint%22);%0A  %7D%0A%0A
+  public Javac withModuleSourcePaths(Iterable%3CString%3E moduleSourcePaths) %7B%0A    return with(moduleSourcePaths, Javac::withModuleSourcePath);%0A  %7D%0A%0A  public Javac withModuleSourcePath(String moduleSourcePath) %7B%0A    return with(%22--module-source-path%22, moduleSourcePath);%0A  %7D%0A%0A  public Javac withPatchModules(Map%3CString, String%3E patches) %7B%0A    return with(patches.entrySet(), Javac::withPatchModule);%0A  %7D%0A%0A  private Javac withPatchModule(Map.Entry%3CString, String%3E patch) %7B%0A    return withPatchModule(patch.getKey(), patch.getValue());%0A  %7D%0A%0A  public Javac withPatchModule(String module, String path) %7B%0A    return with(%22--patch-module%22, module + '=' + path);%0A  %7D%0A%0A
   public Javac w

Extend javac call with more module-related generators