001/*
002 * Copyright (C) 2022 - 2024, the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *    http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package io.github.ascopes.jct.compilers;
017
018import io.github.ascopes.jct.ex.JctCompilerException;
019import io.github.ascopes.jct.filemanagers.JctFileManager;
020import java.util.Collection;
021import java.util.List;
022import javax.tools.JavaCompiler;
023import org.jspecify.annotations.Nullable;
024
025/**
026 * Factory for producing {@link JctCompilation} objects by performing a physical compilation with a
027 * compiler.
028 *
029 * @author Ashley Scopes
030 * @since 0.0.1
031 */
032public interface JctCompilationFactory {
033
034  /**
035   * Create a compilation.
036   *
037   * @param flags          the flags to pass to the compiler.
038   * @param fileManager    the file manager to use for file management.
039   * @param jsr199Compiler the compiler backend to use.
040   * @param classNames     the binary names of the classes to compile. If this is {@code null}, then
041   *                       classes should be discovered automatically.
042   * @return the compilation result that contains whether the compiler succeeded or failed, amongst
043   *     other information.
044   * @throws JctCompilerException if any prerequisites fail, such as no compilation units being
045   *                              found, or if the underlying JSR-199 compiler raises an unhandled
046   *                              exception and cannot complete when invoked.
047   * @throws NullPointerException if any inputs are unexpectedly set to {@code null}.
048   */
049  JctCompilation createCompilation(
050      List<String> flags,
051      JctFileManager fileManager,
052      JavaCompiler jsr199Compiler,
053      @Nullable Collection<String> classNames
054  );
055}