001/*
002 * Copyright (C) 2022 - 2025, 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.junit;
017
018import io.github.ascopes.jct.compilers.JctCompiler;
019import io.github.ascopes.jct.compilers.impl.JavacJctCompilerImpl;
020import org.junit.jupiter.params.support.AnnotationConsumer;
021
022/**
023 * Argument provider for the {@link JavacCompilerTest} annotation.
024 *
025 * @author Ashley Scopes
026 * @since 0.0.1
027 */
028public final class JavacCompilersProvider extends AbstractCompilersProvider
029    implements AnnotationConsumer<JavacCompilerTest> {
030
031  JavacCompilersProvider() {
032    // Visible for testing only.
033  }
034
035  @Override
036  protected JctCompiler initializeNewCompiler() {
037    return new JavacJctCompilerImpl();
038  }
039
040  @Override
041  protected int minSupportedVersion() {
042    return JavacJctCompilerImpl.getEarliestSupportedVersionInt();
043  }
044
045  @Override
046  protected int maxSupportedVersion() {
047    return JavacJctCompilerImpl.getLatestSupportedVersionInt();
048  }
049
050  @Override
051  public void accept(JavacCompilerTest annotation) {
052    var min = annotation.minVersion();
053    var max = annotation.maxVersion();
054    var configurers = annotation.configurers();
055    var versioning = annotation.versionStrategy();
056    configure(min, max, configurers, versioning);
057  }
058}