001/* 002 * ============================================================================ 003 * Copyright © 2002-2021 by Thomas Thrien. 004 * All Rights Reserved. 005 * ============================================================================ 006 * Licensed to the public under the agreements of the GNU Lesser General Public 007 * License, version 3.0 (the "License"). You may obtain a copy of the License at 008 * 009 * http://www.gnu.org/licenses/lgpl.html 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 014 * License for the specific language governing permissions and limitations 015 * under the License. 016 */ 017 018package org.tquadrat.foundation.config.ap.impl.codebuilders; 019 020import static org.apiguardian.api.API.Status.MAINTAINED; 021 022import java.util.function.BiFunction; 023 024import org.apiguardian.api.API; 025import org.tquadrat.foundation.annotation.ClassVersion; 026import org.tquadrat.foundation.config.SpecialPropertyType; 027import org.tquadrat.foundation.config.ap.CodeGenerationConfiguration; 028import org.tquadrat.foundation.config.ap.impl.CodeBuilder; 029import org.tquadrat.foundation.config.ap.impl.CodeGenerator; 030import org.tquadrat.foundation.config.ap.impl.PropertySpecImpl; 031import org.tquadrat.foundation.config.ap.impl.SpecialPropertySpec; 032import org.tquadrat.foundation.javacomposer.CodeBlock; 033import org.tquadrat.foundation.javacomposer.FieldSpec; 034import org.tquadrat.foundation.javacomposer.JavaComposer; 035import org.tquadrat.foundation.javacomposer.MethodSpec; 036import org.tquadrat.foundation.javacomposer.SuppressableWarnings; 037import org.tquadrat.foundation.javacomposer.TypeSpec; 038 039/** 040 * The API that provides access to the code generator context, including the 041 * already generated code. 042 * 043 * @extauthor Thomas Thrien - thomas.thrien@tquadrat.org 044 * @version $Id: CodeGeneratorContext.java 1061 2023-09-25 16:32:43Z tquadrat $ 045 * @UMLGraph.link 046 * @since 0.1.0 047 */ 048@ClassVersion( sourceVersion = "$Id: CodeGeneratorContext.java 1061 2023-09-25 16:32:43Z tquadrat $" ) 049@API( status = MAINTAINED, since = "0.1.0" ) 050public interface CodeGeneratorContext 051{ 052 /*---------*\ 053 ====** Methods **========================================================== 054 \*---------*/ 055 /** 056 * Adds a warning to the 057 * {@link java.lang.SuppressWarnings @SuppressWarnings} 058 * annotation for the constructor of the new configuration bean. 059 * 060 * @param warning The warning to suppress. 061 */ 062 public void addConstructorSuppressedWarning( final SuppressableWarnings warning ); 063 064 /** 065 * Provides access to the 066 * {@linkplain JavaComposer#classBuilder(CharSequence) class builder} 067 * for the configuration bean. 068 * 069 * @return The reference to the class builder. 070 */ 071 public TypeSpec.Builder getClassBuilder(); 072 073 /** 074 * Provides access to the 075 * {@link JavaComposer} 076 * instance that is used for the code generation. 077 * 078 * @return The reference for the composer. 079 */ 080 public JavaComposer getComposer(); 081 082 /** 083 * Provides the default implementation of the method that composes an 084 * 'add' method for a given property. 085 * 086 * @return The composer method. 087 */ 088 public static BiFunction<CodeBuilder, PropertySpecImpl,MethodSpec> getAddMethodComposer() { return CodeBuilderBase::composeAddMethod; } 089 090 /** 091 * Provides the default implementation of the method that composes a 092 * constructor fragment for the initialisation of a given property in case 093 * it is annotated with 094 * {@link org.tquadrat.foundation.config.EnvironmentVariable @EnvironmentVariable}. 095 * 096 * @return The composer method. 097 */ 098 public static BiFunction<CodeBuilder, PropertySpecImpl,CodeBlock> getConstructorFragment4EnvironmentComposer() { return CodeBuilderBase::composeConstructorFragment4Environment; } 099 100 /** 101 * Provides the default implementation of the method that composes a 102 * constructor fragment for the initialisation of a given property in case 103 * it is annotated with 104 * {@link org.tquadrat.foundation.config.EnvironmentVariable @EnvironmentVariable}. 105 * 106 * @return The composer method. 107 */ 108 public static BiFunction<CodeBuilder, PropertySpecImpl,CodeBlock> getConstructorFragment4SystemPreferenceComposer() { return CodeBuilderBase::composeConstructorFragment4SystemPreference; } 109 110 /** 111 * Provides the default implementation of the method that composes a 112 * constructor fragment for the initialisation of a given property in case 113 * it is annotated with 114 * {@link org.tquadrat.foundation.config.EnvironmentVariable @EnvironmentVariable}. 115 * 116 * @return The composer method. 117 */ 118 public static BiFunction<CodeBuilder, PropertySpecImpl,CodeBlock> getConstructorFragment4SystemPropComposer() { return CodeBuilderBase::composeConstructorFragment4SystemProp; } 119 120 /** 121 * Provides the default implementation of the method that composes a field 122 * for a given property. 123 * 124 * @return The composer method. 125 */ 126 public static BiFunction<CodeBuilder, PropertySpecImpl,FieldSpec> getFieldComposer() { return CodeBuilderBase::composeField; } 127 128 /** 129 * Provides the default implementation of the method that composes a 130 * getter for a given property. 131 * 132 * @return The composer method. 133 */ 134 public static BiFunction<CodeBuilder, PropertySpecImpl,MethodSpec> getGetterComposer() { return CodeBuilderBase::composeGetter; } 135 136 /** 137 * Provides the default implementation of the method that composes a 138 * setter for a given property. 139 * 140 * @return The composer method. 141 */ 142 public static BiFunction<CodeBuilder, PropertySpecImpl,MethodSpec> getSetterComposer() { return CodeBuilderBase::composeSetter; } 143 144 /** 145 * Provides access to the configuration. 146 * 147 * @return The configuration. 148 */ 149 public CodeGenerationConfiguration getConfiguration(); 150 151 /** 152 * Provides access to the builder for the constructor. 153 * 154 * @return The reference to the constructor builder. 155 */ 156 public MethodSpec.Builder getConstructorBuilder(); 157 158 /** 159 * Provides access to the code builder for the constructor body. 160 * 161 * @return The reference to constructor body code builder. 162 */ 163 public CodeBlock.Builder getConstructorCodeBuilder(); 164 165 /** 166 * Returns the definition for the special property type. 167 * 168 * @param type The special property type. 169 * @return The special property specification. 170 */ 171 public default SpecialPropertySpec retrieveSpecialPropertySpecification( final SpecialPropertyType type ) 172 { 173 final var retValue = CodeGenerator.getSpecialPropertySpecification( type ); 174 175 //---* Done *---------------------------------------------------------- 176 return retValue; 177 } // retrieveSpecialPropertySpecification() 178} 179// interface CodeGeneratorContext 180 181/* 182 * End of File 183 */