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.junit;
017
018import io.github.ascopes.jct.compilers.JctCompiler;
019
020/**
021 * Strategy for setting a version on a JUnit compiler annotation.
022 *
023 * @author Ashley Scopes
024 * @since 0.0.1
025 */
026public enum VersionStrategy {
027
028  /**
029   * Set the {@link JctCompiler#release release}.
030   */
031  RELEASE {
032    @Override
033    public void configureCompiler(JctCompiler compiler, int version) {
034      compiler
035          .release(version)
036          .name(compiler.getName() + " (release = Java " + version + ")");
037    }
038  },
039
040  /**
041   * Set the {@link JctCompiler#source source}.
042   */
043  SOURCE {
044    @Override
045    public void configureCompiler(JctCompiler compiler, int version) {
046      compiler
047          .source(version)
048          .name(compiler.getName() + " (source = Java " + version + ")");
049    }
050  },
051
052  /**
053   * Set the {@link JctCompiler#target target}.
054   */
055  TARGET {
056    @Override
057    public void configureCompiler(JctCompiler compiler, int version) {
058      compiler
059          .target(version)
060          .name(compiler.getName() + " (target = Java " + version + ")");
061    }
062  },
063
064  /**
065   * Set the {@link JctCompiler#source source} and {@link JctCompiler#target target}.
066   */
067  SOURCE_AND_TARGET {
068    @Override
069    public void configureCompiler(JctCompiler compiler, int version) {
070      compiler
071          .source(version)
072          .target(version)
073          .name(compiler.getName() + " (source and target = Java " + version + ")");
074    }
075  };
076
077  /**
078   * Set the given version on the compiler, according to the strategy in use.
079   *
080   * @param compiler the compiler to configure.
081   * @param version  the version to set.
082   */
083  public abstract void configureCompiler(JctCompiler compiler, int version);
084}