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