Clean up null issues, add more annotations (#3590)

This commit is contained in:
James Mitchell authored and LexManos committed 2017-01-11 15:17:56 -08:00
1 parent 43efa3cfc4
commit c545b8ecd4
130 files changed
+629 -262

No files matched your search

@@ -32,6 +32,8 @@ import java.util.Set;
import net.minecraft.stats.Achievement;
import javax.annotation.Nullable;
public class AchievementPage
{
private String name;
@@ -83,6 +85,7 @@ public class AchievementPage
* @param name The page's name.
* @return the achievement page with the given name or null if no such page
*/
@Nullable
public static AchievementPage getAchievementPage(String name)
{
for (AchievementPage page : achievementPages)
@@ -33,6 +33,8 @@ import net.minecraft.world.biome.BiomeProvider;
import net.minecraft.world.gen.structure.MapGenVillage;
import net.minecraftforge.common.util.EnumHelper;
import javax.annotation.Nullable;
public class BiomeManager
{
private static TrackedList<BiomeEntry>[] biomes = setupBiomes();
@@ -154,6 +156,7 @@ public class BiomeManager
}
}
@Nullable
public static ImmutableList<BiomeEntry> getBiomes(BiomeType type)
{
int idx = type.ordinal();
@@ -52,6 +52,8 @@ import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.FMLLog;
import javax.annotation.Nullable;
public class DimensionManager
{
private static Hashtable<Integer, WorldServer> worlds = new Hashtable<Integer, WorldServer>();
@@ -170,7 +172,7 @@ public class DimensionManager
return worlds.keySet().toArray(new Integer[worlds.size()]); //Only loaded dims, since usually used to cycle through loaded worlds
}
public static void setWorld(int id, WorldServer world, MinecraftServer server)
public static void setWorld(int id, @Nullable WorldServer world, MinecraftServer server)
{
if (world != null)
{
@@ -357,7 +359,7 @@ public class DimensionManager
return dimMap;
}
public static void loadDimensionDataMap(NBTTagCompound compoundTag)
public static void loadDimensionDataMap(@Nullable NBTTagCompound compoundTag)
{
dimensionMap.clear();
if (compoundTag == null)
@@ -387,6 +389,7 @@ public class DimensionManager
* Return the current root directory for the world save. Accesses getSaveHandler from the overworld
* @return the root directory of the save
*/
@Nullable
public static File getCurrentSaveRootDirectory()
{
if (DimensionManager.getWorld(0) != null)
@@ -139,7 +139,7 @@ public class ForgeChunkManager
@Override
public Chunk apply(@Nullable ChunkPos input)
{
return world.getChunkFromChunkCoords(input.chunkXPos, input.chunkZPos);
return input == null ? null : world.getChunkFromChunkCoords(input.chunkXPos, input.chunkZPos);
}
}));
world.theProfiler.endStartSection("regularChunkLoading");
@@ -687,6 +687,7 @@ public class ForgeChunkManager
return playerTicketLength - playerTickets.get(username).size();
}
@Nullable
public static Ticket requestPlayerTicket(Object mod, String player, World world, Type type)
{
ModContainer mc = getContainer(mod);
@@ -713,6 +714,7 @@ public class ForgeChunkManager
* @param type The type of ticket
* @return A ticket with which to register chunks for loading, or null if no further tickets are available
*/
@Nullable
public static Ticket requestTicket(Object mod, World world, Type type)
{
ModContainer container = getContainer(mod);
@@ -966,6 +968,7 @@ public class ForgeChunkManager
}
}
@Nullable
public static Chunk fetchDormantChunk(long coords, World world)
{
Cache<Long, Chunk> cache = dormantChunkCache.get(world);
@@ -1110,6 +1113,7 @@ public class ForgeChunkManager
return list;
}
@Nullable
public static ConfigCategory getConfigFor(Object mod)
{
ModContainer container = getContainer(mod);
@@ -552,7 +552,7 @@ public class ForgeHooks
return (MinecraftForge.EVENT_BUS.post(event) ? null : new float[]{event.getDistance(), event.getDamageMultiplier()});
}
public static int getLootingLevel(Entity target, Entity killer, DamageSource cause)
public static int getLootingLevel(Entity target, @Nullable Entity killer, DamageSource cause)
{
int looting = 0;
if (killer instanceof EntityLivingBase)
@@ -619,6 +619,7 @@ public class ForgeHooks
MinecraftForge.EVENT_BUS.post(new LivingJumpEvent(entity));
}
@Nullable
public static EntityItem onPlayerTossEvent(@Nonnull EntityPlayer player, @Nonnull ItemStack item, boolean includeName)
{
player.captureDrops = true;
@@ -649,6 +650,7 @@ public class ForgeHooks
return world.getBlockState(pos).getBlock().getEnchantPowerBonus(world, pos);
}
@Nullable
public static ITextComponent onServerChatEvent(NetHandlerPlayServer net, String raw, ITextComponent comp)
{
ServerChatEvent event = new ServerChatEvent(net.playerEntity, raw, comp);
@@ -793,7 +795,7 @@ public class ForgeHooks
return event.isCanceled() ? -1 : event.getExpToDrop();
}
public static EnumActionResult onPlaceItemIntoWorld(@Nonnull ItemStack itemstack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand)
public static EnumActionResult onPlaceItemIntoWorld(@Nonnull ItemStack itemstack, @Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side, float hitX, float hitY, float hitZ, @Nonnull EnumHand hand)
{
// handle all placement events here
int meta = itemstack.getItemDamage();
@@ -896,7 +898,7 @@ public class ForgeHooks
return false;
}
public static float onAnvilRepair(EntityPlayer player, ItemStack output, ItemStack left, ItemStack right)
public static float onAnvilRepair(EntityPlayer player, @Nonnull ItemStack output, @Nonnull ItemStack left, @Nonnull ItemStack right)
{
AnvilRepairEvent e = new AnvilRepairEvent(player, left, right, output);
MinecraftForge.EVENT_BUS.post(e);
@@ -1009,6 +1011,7 @@ public class ForgeHooks
return !event.isCanceled();
}
@Nullable
public static RayTraceResult rayTraceEyes(EntityLivingBase entity, double length)
{
Vec3d startPos = new Vec3d(entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ);
@@ -1016,6 +1019,7 @@ public class ForgeHooks
return entity.world.rayTraceBlocks(startPos, endPos);
}
@Nullable
public static Vec3d rayTraceEyeHitVec(EntityLivingBase entity, double length)
{
RayTraceResult git = rayTraceEyes(entity, length);
@@ -1085,6 +1089,8 @@ public class ForgeHooks
return ctx;
}
@Nullable
public static LootTable loadLootTable(Gson gson, ResourceLocation name, String data, boolean custom)
{
Deque<LootTableContext> que = lootContext.get();
@@ -1140,7 +1146,7 @@ public class ForgeHooks
public String validateEntryName(@Nullable String name)
{
if (!this.entryNames.contains(name))
if (name != null && !this.entryNames.contains(name))
{
this.entryNames.add(name);
return name;
@@ -94,6 +94,8 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import javax.annotation.Nullable;
public class ForgeModContainer extends DummyModContainer implements WorldAccessContainer
{
public static final String VERSION_CHECK_CAT = "version_checking";
@@ -541,6 +543,7 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
@Override
@Nullable
public Certificate getSigningCertificate()
{
Certificate[] certificates = getClass().getProtectionDomain().getCodeSource().getCertificates();
@@ -47,6 +47,8 @@ import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.common.versioning.ComparableVersion;
import javax.annotation.Nullable;
public class ForgeVersion
{
// This is Forge's Mod Id, used for the ForgeModContainer and resource locations
@@ -93,6 +95,7 @@ public class ForgeVersion
return getResult(ForgeModContainer.getInstance()).status;
}
@Nullable
public static String getTarget()
{
CheckResult res = getResult(ForgeModContainer.getInstance());
@@ -159,15 +162,17 @@ public class ForgeVersion
public static class CheckResult
{
public final Status status;
@Nullable
public final ComparableVersion target;
public final Map<ComparableVersion, String> changes;
@Nullable
public final String url;
private CheckResult(Status status, ComparableVersion target, Map<ComparableVersion, String> changes, String url)
private CheckResult(Status status, @Nullable ComparableVersion target, @Nullable Map<ComparableVersion, String> changes, @Nullable String url)
{
this.status = status;
this.target = target;
this.changes = changes == null ? null : Collections.unmodifiableMap(changes);
this.changes = changes == null ? Collections.<ComparableVersion, String>emptyMap() : Collections.unmodifiableMap(changes);
this.url = url;
}
}
@@ -35,6 +35,8 @@ import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import javax.annotation.Nullable;
/**
* Various implementations of ITimeValue.
*/
@@ -291,12 +293,13 @@ public final class TimeValues
private final ThreadLocal<Function<String, ITimeValue>> valueResolver = new ThreadLocal<Function<String, ITimeValue>>();
public void setValueResolver(Function<String, ITimeValue> valueResolver)
public void setValueResolver(@Nullable Function<String, ITimeValue> valueResolver)
{
this.valueResolver.set(valueResolver);
}
@SuppressWarnings("unchecked")
@Nullable
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type)
{
if(type.getRawType() != ITimeValue.class)
@@ -24,8 +24,9 @@ import net.minecraftforge.oredict.OreDictionary;
import javax.annotation.Nonnull;
public abstract class AbstractBrewingRecipe<T> implements IBrewingRecipe {
public abstract class AbstractBrewingRecipe<T> implements IBrewingRecipe
{
@Nonnull
private final ItemStack input;
private final T ingredient;
private final ItemStack output;
@@ -30,18 +30,19 @@ public interface IBrewingRecipe {
* being the item that goes in one of the three bottom slots of the brewing
* stand (e.g: water bottle)
*/
public boolean isInput(@Nonnull ItemStack input);
boolean isInput(@Nonnull ItemStack input);
/**
* Returns true if the passed ItemStack is an ingredient for this recipe.
* "Ingredient" being the item that goes in the top slot of the brewing
* stand (e.g: nether wart)
*/
public boolean isIngredient(@Nonnull ItemStack ingredient);
boolean isIngredient(@Nonnull ItemStack ingredient);
/**
* Returns the output when the passed input is brewed with the passed
* ingredient. Null if invalid input or ingredient.
* ingredient. Empty if invalid input or ingredient.
*/
public ItemStack getOutput(@Nonnull ItemStack input, @Nonnull ItemStack ingredient);
@Nonnull
ItemStack getOutput(@Nonnull ItemStack input, @Nonnull ItemStack ingredient);
}
@@ -58,6 +58,7 @@ public class VanillaBrewingRecipe implements IBrewingRecipe {
* or if the new potion is a splash potion when the old one wasn't.
*/
@Override
@Nonnull
public ItemStack getOutput(@Nonnull ItemStack input, @Nonnull ItemStack ingredient)
{
if (!input.isEmpty() && !ingredient.isEmpty() && isIngredient(ingredient))
@@ -26,6 +26,8 @@ import com.google.common.base.Throwables;
import net.minecraft.nbt.NBTBase;
import net.minecraft.util.EnumFacing;
import javax.annotation.Nullable;
/**
* This is the core holder object Capabilities.
* Each capability will have ONE instance of this class,
@@ -55,6 +57,7 @@ public class Capability<T>
* @param side The side of the object the instance is associated with.
* @return a NBT holding the data. Null if no data needs to be stored.
*/
@Nullable
NBTBase writeNBT(Capability<T> capability, T instance, EnumFacing side);
/**
@@ -103,6 +106,7 @@ public class Capability<T>
* Quick access to the IStorage's writeNBT.
* See {@link IStorage#writeNBT(Capability, Object, EnumFacing)} for documentation.
*/
@Nullable
public NBTBase writeNBT(T instance, EnumFacing side)
{
return storage.writeNBT(this, instance, side);
@@ -117,6 +121,7 @@ public class Capability<T>
*
* @return A NEW instance of the default implementation.
*/
@Nullable
public T getDefaultInstance()
{
try
@@ -54,7 +54,7 @@ public final class CapabilityDispatcher implements INBTSerializable<NBTTagCompou
}
@SuppressWarnings("unchecked")
public CapabilityDispatcher(Map<ResourceLocation, ICapabilityProvider> list, ICapabilityProvider parent)
public CapabilityDispatcher(Map<ResourceLocation, ICapabilityProvider> list, @Nullable ICapabilityProvider parent)
{
List<ICapabilityProvider> lstCaps = Lists.newArrayList();
List<INBTSerializable<NBTBase>> lstWriters = Lists.newArrayList();
@@ -39,6 +39,8 @@ import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.discovery.ASMDataTable;
import javax.annotation.Nullable;
public enum CapabilityManager
{
INSTANCE;
@@ -63,11 +65,10 @@ public enum CapabilityManager
try {
return implementation.newInstance();
} catch (InstantiationException e) {
Throwables.propagate(e);
throw Throwables.propagate(e);
} catch (IllegalAccessException e) {
Throwables.propagate(e);
throw Throwables.propagate(e);
}
return null;
}
});
}
@@ -115,6 +116,7 @@ public enum CapabilityManager
if (type == null)
{
FMLLog.log(Level.WARN, "Unable to inject capability at %s.%s (Invalid Annotation)", targetClass, targetName);
continue;
}
final String capabilityName = type.getInternalName().replace('/', '.').intern();
@@ -21,6 +21,7 @@ package net.minecraftforge.common.model;
import java.util.EnumMap;
import javax.annotation.Nullable;
import javax.vecmath.AxisAngle4f;
import javax.vecmath.Matrix3f;
import javax.vecmath.Matrix4f;
@@ -78,7 +79,7 @@ public final class TRSRTransformation implements IModelState, ITransformation
}
}
public TRSRTransformation(Vector3f translation, Quat4f leftRot, Vector3f scale, Quat4f rightRot)
public TRSRTransformation(@Nullable Vector3f translation, @Nullable Quat4f leftRot, @Nullable Vector3f scale, @Nullable Quat4f rightRot)
{
this.matrix = mul(translation, leftRot, scale, rightRot);
this.translation = translation != null ? translation : new Vector3f();
@@ -260,7 +261,7 @@ public final class TRSRTransformation implements IModelState, ITransformation
);
}
public static Matrix4f mul(Vector3f translation, Quat4f leftRot, Vector3f scale, Quat4f rightRot)
public static Matrix4f mul(@Nullable Vector3f translation, @Nullable Quat4f leftRot, @Nullable Vector3f scale, @Nullable Quat4f rightRot)
{
Matrix4f res = new Matrix4f(), t = new Matrix4f();
res.setIdentity();
@@ -57,6 +57,8 @@ import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.gson.annotations.SerializedName;
import javax.annotation.Nullable;
public final class AnimationStateMachine implements IAnimationStateMachine
{
private final ImmutableMap<String, ITimeValue> parameters;
@@ -310,6 +312,7 @@ public final class AnimationStateMachine implements IAnimationStateMachine
INSTANCE;
@SuppressWarnings("unchecked")
@Nullable
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type)
{
if(type.getRawType() != ImmutableMultimap.class || !(type.getType() instanceof ParameterizedType))
@@ -53,6 +53,8 @@ import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import javax.annotation.Nullable;
/**
* Various implementations of IClip, and utility methods.
*/
@@ -426,12 +428,13 @@ public final class Clips
private final ThreadLocal<Function<String, IClip>> clipResolver = new ThreadLocal<Function<String, IClip>>();
public void setClipResolver(Function<String, IClip> clipResolver)
public void setClipResolver(@Nullable Function<String, IClip> clipResolver)
{
this.clipResolver.set(clipResolver);
}
@SuppressWarnings("unchecked")
@Nullable
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type)
{
if(type.getRawType() != IClip.class)
@@ -37,6 +37,9 @@ import com.google.common.collect.ImmutableTable;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class ExtendedBlockState extends BlockStateContainer
{
private final ImmutableSet<IUnlistedProperty<?>> unlistedProperties;
@@ -68,7 +71,8 @@ public class ExtendedBlockState extends BlockStateContainer
}
@Override
protected StateImplementation createState(Block block, ImmutableMap<IProperty<?>, Comparable<?>> properties, ImmutableMap<IUnlistedProperty<?>, Optional<?>> unlistedProperties)
@Nonnull
protected StateImplementation createState(@Nonnull Block block, @Nonnull ImmutableMap<IProperty<?>, Comparable<?>> properties, @Nullable ImmutableMap<IUnlistedProperty<?>, Optional<?>> unlistedProperties)
{
if (unlistedProperties == null || unlistedProperties.isEmpty()) return super.createState(block, properties, unlistedProperties);
return new ExtendedStateImplementation(block, properties, unlistedProperties, null);
@@ -79,7 +83,7 @@ public class ExtendedBlockState extends BlockStateContainer
private final ImmutableMap<IUnlistedProperty<?>, Optional<?>> unlistedProperties;
private Map<Map<IProperty<?>, Comparable<?>>, BlockStateContainer.StateImplementation> normalMap;
protected ExtendedStateImplementation(Block block, ImmutableMap<IProperty<?>, Comparable<?>> properties, ImmutableMap<IUnlistedProperty<?>, Optional<?>> unlistedProperties, ImmutableTable<IProperty<?>, Comparable<?>, IBlockState> table)
protected ExtendedStateImplementation(Block block, ImmutableMap<IProperty<?>, Comparable<?>> properties, ImmutableMap<IUnlistedProperty<?>, Optional<?>> unlistedProperties, @Nullable ImmutableTable<IProperty<?>, Comparable<?>, IBlockState> table)
{
super(block, properties);
this.unlistedProperties = unlistedProperties;
@@ -87,7 +91,8 @@ public class ExtendedBlockState extends BlockStateContainer
}
@Override
public <T extends Comparable<T>, V extends T> IBlockState withProperty(IProperty<T> property, V value)
@Nonnull
public <T extends Comparable<T>, V extends T> IBlockState withProperty(@Nonnull IProperty<T> property, @Nonnull V value)
{
if (!this.getProperties().containsKey(property))
{
@@ -30,6 +30,8 @@ import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import javax.annotation.Nullable;
/**
* Represents a captured snapshot of a block which will not change
* automatically.
@@ -46,6 +48,7 @@ public class BlockSnapshot implements Serializable
private final int dimId;
private transient IBlockState replacedBlock;
private int flag;
@Nullable
private final NBTTagCompound nbt;
private transient World world;
private final ResourceLocation registryName;
@@ -73,7 +76,7 @@ public class BlockSnapshot implements Serializable
}
}
public BlockSnapshot(World world, BlockPos pos, IBlockState state, NBTTagCompound nbt)
public BlockSnapshot(World world, BlockPos pos, IBlockState state, @Nullable NBTTagCompound nbt)
{
this.setWorld(world);
this.dimId = world.provider.getDimension();
@@ -98,7 +101,7 @@ public class BlockSnapshot implements Serializable
/**
* Raw constructor designed for serialization usages.
*/
public BlockSnapshot(int dimension, BlockPos pos, String modId, String blockName, int meta, int flag, NBTTagCompound nbt)
public BlockSnapshot(int dimension, BlockPos pos, String modId, String blockName, int meta, int flag, @Nullable NBTTagCompound nbt)
{
this.dimId = dimension;
this.pos = pos.toImmutable();
@@ -322,6 +325,7 @@ public class BlockSnapshot implements Serializable
public void setReplacedBlock(IBlockState replacedBlock) { this.replacedBlock = replacedBlock; }
public int getFlag() { return flag; }
public void setFlag(int flag) { this.flag = flag; }
@Nullable
public NBTTagCompound getNbt() { return nbt; }
public void setWorld(World world) { this.world = world; }
public ResourceLocation getRegistryName() { return registryName; }
@@ -46,6 +46,8 @@ import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.gen.structure.StructureStrongholdPieces.Stronghold.Door;
import net.minecraftforge.classloading.FMLForgePlugin;
import javax.annotation.Nullable;
public class EnumHelper
{
private static Object reflectionFactory = null;
@@ -73,54 +75,67 @@ public class EnumHelper
{EnumRarity.class, TextFormatting.class, String.class}
};
@Nullable
public static EnumAction addAction(String name)
{
return addEnum(EnumAction.class, name);
}
@Nullable
public static ArmorMaterial addArmorMaterial(String name, String textureName, int durability, int[] reductionAmounts, int enchantability, SoundEvent soundOnEquip, float toughness)
{
return addEnum(ArmorMaterial.class, name, textureName, durability, reductionAmounts, enchantability, soundOnEquip, toughness);
}
@Nullable
public static EnumArt addArt(String name, String tile, int sizeX, int sizeY, int offsetX, int offsetY)
{
return addEnum(EnumArt.class, name, tile, sizeX, sizeY, offsetX, offsetY);
}
@Nullable
public static EnumCreatureAttribute addCreatureAttribute(String name)
{
return addEnum(EnumCreatureAttribute.class, name);
}
@Nullable
public static EnumCreatureType addCreatureType(String name, Class<?> typeClass, int maxNumber, Material material, boolean peaceful, boolean animal)
{
return addEnum(EnumCreatureType.class, name, typeClass, maxNumber, material, peaceful, animal);
}
@Nullable
public static Door addDoor(String name)
{
return addEnum(Door.class, name);
}
@Nullable
public static EnumEnchantmentType addEnchantmentType(String name, Predicate<Item> delegate)
{
return addEnum(EnumEnchantmentType.class, name, delegate);
}
@Nullable
public static Sensitivity addSensitivity(String name)
{
return addEnum(Sensitivity.class, name);
}
@Nullable
public static RayTraceResult.Type addMovingObjectType(String name)
{
return addEnum(RayTraceResult.Type.class, name);
}
@Nullable
public static EnumSkyBlock addSkyBlock(String name, int lightValue)
{
return addEnum(EnumSkyBlock.class, name, lightValue);
}
@Nullable
public static SleepResult addStatus(String name)
{
return addEnum(SleepResult.class, name);
}
@Nullable
public static ToolMaterial addToolMaterial(String name, int harvestLevel, int maxUses, float efficiency, float damage, int enchantability)
{
return addEnum(ToolMaterial.class, name, harvestLevel, maxUses, efficiency, damage, enchantability);
}
@Nullable
public static EnumRarity addRarity(String name, TextFormatting color, String displayName)
{
return addEnum(EnumRarity.class, name, color, displayName);
@@ -164,16 +179,20 @@ public class EnumHelper
return newConstructorAccessor.invoke(reflectionFactory, enumClass.getDeclaredConstructor(parameterTypes));
}
private static < T extends Enum<? >> T makeEnum(Class<T> enumClass, String value, int ordinal, Class<?>[] additionalTypes, Object[] additionalValues) throws Exception
private static < T extends Enum<? >> T makeEnum(Class<T> enumClass, @Nullable String value, int ordinal, Class<?>[] additionalTypes, @Nullable Object[] additionalValues) throws Exception
{
Object[] params = new Object[additionalValues.length + 2];
int additionalParamsCount = additionalValues == null ? 0 : additionalValues.length;
Object[] params = new Object[additionalParamsCount + 2];
params[0] = value;
params[1] = ordinal;
System.arraycopy(additionalValues, 0, params, 2, additionalValues.length);
if (additionalValues != null)
{
System.arraycopy(additionalValues, 0, params, 2, additionalValues.length);
}
return enumClass.cast(newInstance.invoke(getConstructorAccessor(enumClass, additionalTypes), new Object[] {params}));
}
public static void setFailsafeFieldValue(Field field, Object target, Object value) throws Exception
public static void setFailsafeFieldValue(Field field, @Nullable Object target, @Nullable Object value) throws Exception
{
field.setAccessible(true);
Field modifiersField = Field.class.getDeclaredField("modifiers");
@@ -202,12 +221,14 @@ public class EnumHelper
blankField(enumClass, "enumConstants");
}
@Nullable
private static <T extends Enum<? >> T addEnum(Class<T> enumType, String enumName, Object... paramValues)
{
setup();
return addEnum(commonTypes, enumType, enumName, paramValues);
}
@Nullable
protected static <T extends Enum<? >> T addEnum(Class<?>[][] map, Class<T> enumType, String enumName, Object... paramValues)
{
for (Class<?>[] lookup : map)
@@ -231,13 +252,15 @@ public class EnumHelper
addEnum(true, enumType, null, paramTypes, (Object[])null);
}
@Nullable
public static <T extends Enum<? >> T addEnum(Class<T> enumType, String enumName, Class<?>[] paramTypes, Object... paramValues)
{
return addEnum(false, enumType, enumName, paramTypes, paramValues);
}
@SuppressWarnings({ "unchecked", "serial" })
private static <T extends Enum<? >> T addEnum(boolean test, final Class<T> enumType, String enumName, final Class<?>[] paramTypes, Object[] paramValues)
@Nullable
private static <T extends Enum<? >> T addEnum(boolean test, final Class<T> enumType, @Nullable String enumName, final Class<?>[] paramTypes, @Nullable Object[] paramValues)
{
if (!isSetup)
{