io.github.jdcmp.codegen.customization.AvailableInitializationMode Maven / Gradle / Ivy
package io.github.jdcmp.codegen.customization;
/**
* Configures the strategy for initializing fields of generated classes.
*/
public enum AvailableInitializationMode {
/**
* Generated classes contain a static initializer for field initialization.
*
*
* - The static initializer increases the size of the generated bytecode.
* - Provides the best compatibility, since no private/unofficial APIs must be used.
*
*/
STATIC_INITIALIZER {
@Override
public T map(InitializationModeMapper mapper) {
return mapper.onStaticInitializer();
}
},
/**
* Generated classes contain no mechanism for field initialization.
*
*
* - The absence of an initialization mechanism reduces the size of the generated bytecode.
* - Compatibility is worse compared to {@link #STATIC_INITIALIZER}. Initialization is handled
* using unsupported reflection features or similar hacks with sun.misc.Unsafe.
*
*/
EXTERNAL {
@Override
public T map(InitializationModeMapper mapper) {
return mapper.onStaticInitializer();
}
};
/**
* Maps the enum constant using the given mapper. See {@link InitializationModeMapper}.
*
* @param mapper The mapper
* @return A user-supplied return value
* @param Type of the return value
*/
abstract public T map(InitializationModeMapper mapper);
/**
* Maps an initialization mode to a user-supplied value. For every enum constant, there is one handler method present in
* this mapper.
*
* If any enum constants are added in the future, using this mapper will force implementors to handle the new
* "on"-method. This reduces the risk of missing cases in if
or switch
statements.
*
* @param Type of the return value
*/
public interface InitializationModeMapper {
/**
* Invoked when {@link AvailableInitializationMode#STATIC_INITIALIZER} is used.
*
* @return User-supplied return value
*/
T onStaticInitializer();
/**
* Invoked when {@link AvailableInitializationMode#EXTERNAL} is used.
*
* @return User-supplied return value
*/
T onExternal();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy