Skip to content

Commit

Permalink
Add package annotations for default Nonnull, fix up inspection warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Sep 20, 2016
1 parent b48c2ac commit 9bb4147
Show file tree
Hide file tree
Showing 167 changed files with 961 additions and 1,262 deletions.
19 changes: 9 additions & 10 deletions src/main/java/mezz/jei/GuiEventHandler.java
@@ -1,6 +1,5 @@
package mezz.jei;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import mezz.jei.config.Config;
Expand All @@ -18,15 +17,14 @@
import org.lwjgl.input.Mouse;

public class GuiEventHandler {
@Nonnull
private static final String showRecipesText = Translator.translateToLocal("jei.tooltip.show.recipes");
@Nullable
private InputHandler inputHandler;
@Nullable
private GuiContainer previousGui = null;

@SubscribeEvent
public void onGuiInit(@Nonnull GuiScreenEvent.InitGuiEvent.Post event) {
public void onGuiInit(GuiScreenEvent.InitGuiEvent.Post event) {
JeiRuntime runtime = Internal.getRuntime();
if (runtime == null) {
return;
Expand All @@ -38,8 +36,9 @@ public void onGuiInit(@Nonnull GuiScreenEvent.InitGuiEvent.Post event) {
GuiContainer guiContainer = (GuiContainer) gui;
itemListOverlay.initGui(guiContainer);

RecipesGui recipesGui = new RecipesGui();
inputHandler = new InputHandler(recipesGui, itemListOverlay);
RecipeRegistry recipeRegistry = runtime.getRecipeRegistry();
RecipesGui recipesGui = new RecipesGui(recipeRegistry);
inputHandler = new InputHandler(recipeRegistry, recipesGui, itemListOverlay);
} else if (gui instanceof RecipesGui) {
if (inputHandler != null) {
inputHandler.onScreenResized();
Expand All @@ -50,7 +49,7 @@ public void onGuiInit(@Nonnull GuiScreenEvent.InitGuiEvent.Post event) {
}

@SubscribeEvent
public void onGuiOpen(@Nonnull GuiOpenEvent event) {
public void onGuiOpen(GuiOpenEvent event) {
JeiRuntime runtime = Internal.getRuntime();
if (runtime == null) {
return;
Expand All @@ -74,7 +73,7 @@ public void onGuiOpen(@Nonnull GuiOpenEvent event) {
}

@SubscribeEvent
public void onDrawBackgroundEventPost(@Nonnull GuiScreenEvent.BackgroundDrawnEvent event) {
public void onDrawBackgroundEventPost(GuiScreenEvent.BackgroundDrawnEvent event) {
JeiRuntime runtime = Internal.getRuntime();
if (runtime == null) {
return;
Expand All @@ -89,7 +88,7 @@ public void onDrawBackgroundEventPost(@Nonnull GuiScreenEvent.BackgroundDrawnEve
}

@SubscribeEvent
public void onDrawScreenEventPost(@Nonnull GuiScreenEvent.DrawScreenEvent.Post event) {
public void onDrawScreenEventPost(GuiScreenEvent.DrawScreenEvent.Post event) {
JeiRuntime runtime = Internal.getRuntime();
if (runtime == null) {
return;
Expand All @@ -98,7 +97,7 @@ public void onDrawScreenEventPost(@Nonnull GuiScreenEvent.DrawScreenEvent.Post e
GuiScreen gui = event.getGui();
if (gui instanceof GuiContainer) {
GuiContainer guiContainer = (GuiContainer) gui;
RecipeRegistry recipeRegistry = Internal.getRuntime().getRecipeRegistry();
RecipeRegistry recipeRegistry = runtime.getRecipeRegistry();
if (recipeRegistry.getRecipeClickableArea(guiContainer, event.getMouseX() - guiContainer.guiLeft, event.getMouseY() - guiContainer.guiTop) != null) {
TooltipRenderer.drawHoveringText(guiContainer.mc, showRecipesText, event.getMouseX(), event.getMouseY());
}
Expand All @@ -111,7 +110,7 @@ public void onDrawScreenEventPost(@Nonnull GuiScreenEvent.DrawScreenEvent.Post e
}

@SubscribeEvent
public void onClientTick(@Nonnull TickEvent.ClientTickEvent event) {
public void onClientTick(TickEvent.ClientTickEvent event) {
JeiRuntime runtime = Internal.getRuntime();
if (runtime == null) {
return;
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/mezz/jei/Internal.java
@@ -1,47 +1,50 @@
package mezz.jei;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import mezz.jei.util.StackHelper;
import mezz.jei.util.color.ColorNamer;

/** For JEI internal use only, these are normally accessed from the API. */
public class Internal {
@Nonnull
private static JeiHelpers helpers = new JeiHelpers();
@Nullable
private static JeiRuntime runtime;
@Nullable
private static ItemRegistry itemRegistry;
@Nullable
private static ColorNamer colorNamer;

private Internal() {

}

@Nonnull
public static JeiHelpers getHelpers() {
return helpers;
}

public static void setHelpers(@Nonnull JeiHelpers helpers) {
public static void setHelpers(JeiHelpers helpers) {
Internal.helpers = helpers;
}

@Nonnull
public static StackHelper getStackHelper() {
return helpers.getStackHelper();
}

@Nullable
public static JeiRuntime getRuntime() {
return runtime;
}

public static void setRuntime(JeiRuntime runtime) {
if (Internal.runtime != null) {
Internal.runtime.close();
JeiRuntime jeiRuntime = Internal.runtime;
if (jeiRuntime != null) {
jeiRuntime.close();
}
Internal.runtime = runtime;
}

@Nullable
public static ItemRegistry getItemRegistry() {
return itemRegistry;
}
Expand All @@ -50,6 +53,7 @@ public static void setItemRegistry(ItemRegistry itemRegistry) {
Internal.itemRegistry = itemRegistry;
}

@Nullable
public static ColorNamer getColorNamer() {
return colorNamer;
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/mezz/jei/ItemBlacklist.java
@@ -1,6 +1,5 @@
package mezz.jei;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.HashSet;
import java.util.List;
Expand All @@ -12,7 +11,6 @@
import net.minecraft.item.ItemStack;

public class ItemBlacklist implements IItemBlacklist {
@Nonnull
private final Set<String> itemBlacklist = new HashSet<String>();

@Override
Expand Down
25 changes: 9 additions & 16 deletions src/main/java/mezz/jei/ItemFilter.java
@@ -1,6 +1,5 @@
package mezz.jei;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -30,9 +29,7 @@
public class ItemFilter {

/** A cache for fast searches while typing or using backspace. Maps filterText to filteredItemMaps */
@Nonnull
private final LoadingCache<String, ImmutableList<ItemStackElement>> filteredItemMapsCache;
@Nonnull
private final ImmutableList<ItemStackElement> baseList;

public ItemFilter(final IItemRegistry itemRegistry) {
Expand All @@ -50,7 +47,6 @@ public void reset() {
this.filteredItemMapsCache.invalidateAll();
}

@Nonnull
public ImmutableList<ItemStackElement> getItemList() {
String[] filters = Config.getFilterText().split("\\|");

Expand All @@ -70,11 +66,9 @@ public ImmutableList<ItemStackElement> getItemList() {
/**
* {@link #getItemStacks()} is slow, so cache the previous value in case someone requests it often.
*/
@Nonnull
private ImmutableList<ItemStack> itemStacksCached = ImmutableList.of();
private String filterCached;

@Nonnull
public ImmutableList<ItemStack> getItemStacks() {
if (!Config.getFilterText().equals(filterCached)) {
ImmutableList.Builder<ItemStack> filteredStacks = ImmutableList.builder();
Expand All @@ -91,7 +85,6 @@ public int size() {
return getItemList().size();
}

@Nonnull
private static ImmutableList<ItemStackElement> createBaseList(IItemRegistry itemRegistry) {
ItemStackChecker itemStackChecker = new ItemStackChecker();

Expand All @@ -101,11 +94,11 @@ private static ImmutableList<ItemStackElement> createBaseList(IItemRegistry item
continue;
}

if (itemStackChecker.isItemStackHidden(itemStack)) {
if (itemStackChecker.isItemStackHidden(itemStack, itemRegistry)) {
continue;
}

ItemStackElement itemStackElement = ItemStackElement.create(itemStack);
ItemStackElement itemStackElement = ItemStackElement.create(itemStack, itemRegistry);
if (itemStackElement != null) {
baseList.add(itemStackElement);
}
Expand All @@ -115,7 +108,7 @@ private static ImmutableList<ItemStackElement> createBaseList(IItemRegistry item
int count = brokenItem.getCount();
if (count > 1) {
Item item = brokenItem.getElement();
String modName = Internal.getItemRegistry().getModNameForItem(item);
String modName = itemRegistry.getModNameForItem(item);
Log.error("Couldn't get ItemModel for {} item {}. Suppressed {} similar errors.", modName, item, count);
}
}
Expand All @@ -124,14 +117,14 @@ private static ImmutableList<ItemStackElement> createBaseList(IItemRegistry item
}

private static class OneWeigher implements Weigher<String, ImmutableList<ItemStackElement>> {
public int weigh(@Nonnull String key, @Nonnull ImmutableList<ItemStackElement> value) {
public int weigh(String key, ImmutableList<ItemStackElement> value) {
return 1;
}
}

private class ItemFilterCacheLoader extends CacheLoader<String, ImmutableList<ItemStackElement>> {
@Override
public ImmutableList<ItemStackElement> load(@Nonnull final String filterText) throws Exception {
public ImmutableList<ItemStackElement> load(final String filterText) throws Exception {
if (filterText.length() == 0) {
return baseList;
}
Expand Down Expand Up @@ -167,7 +160,7 @@ public ItemStackChecker() {
missingModel = itemModelMesher.getModelManager().getMissingModel();
}

public boolean isItemStackHidden(@Nonnull ItemStack itemStack) {
public boolean isItemStackHidden(ItemStack itemStack, IItemRegistry itemRegistry) {
if (isItemHiddenByBlacklist(itemStack)) {
return true;
}
Expand All @@ -182,13 +175,13 @@ public boolean isItemStackHidden(@Nonnull ItemStack itemStack) {
try {
itemModel = renderItem.getItemModelWithOverrides(itemStack, null, null);
} catch (RuntimeException e) {
String modName = Internal.getItemRegistry().getModNameForItem(item);
String modName = itemRegistry.getModNameForItem(item);
String stackInfo = ErrorUtil.getItemStackInfo(itemStack);
Log.error("Couldn't get ItemModel for {} itemStack {}", modName, stackInfo, e);
brokenItems.add(item);
return true;
} catch (LinkageError e) {
String modName = Internal.getItemRegistry().getModNameForItem(item);
String modName = itemRegistry.getModNameForItem(item);
String stackInfo = ErrorUtil.getItemStackInfo(itemStack);
Log.error("Couldn't get ItemModel for {} itemStack {}", modName, stackInfo, e);
brokenItems.add(item);
Expand All @@ -213,7 +206,7 @@ public Multiset<Item> getBrokenItems() {
return brokenItems;
}

private boolean isItemHiddenByBlacklist(@Nonnull ItemStack itemStack) {
private boolean isItemHiddenByBlacklist(ItemStack itemStack) {
try {
if (!itemBlacklist.isItemBlacklisted(itemStack)) {
return false;
Expand Down
39 changes: 15 additions & 24 deletions src/main/java/mezz/jei/ItemRegistry.java
@@ -1,36 +1,28 @@
package mezz.jei;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableListMultimap;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Locale;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableListMultimap;
import mezz.jei.api.IItemRegistry;
import mezz.jei.util.Log;
import mezz.jei.util.ModList;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

public class ItemRegistry implements IItemRegistry {
@Nonnull
private final ImmutableList<ItemStack> itemList;
@Nonnull
private final ImmutableListMultimap<String, ItemStack> itemsByModId;
@Nonnull
private final ImmutableList<ItemStack> potionIngredients;
@Nonnull
private final ImmutableList<ItemStack> fuels;
@Nonnull
private final ModList modList;

public ItemRegistry(@Nonnull ImmutableList<ItemStack> itemList,
@Nonnull ImmutableListMultimap<String, ItemStack> itemsByModId,
@Nonnull ImmutableList<ItemStack> potionIngredients,
@Nonnull ImmutableList<ItemStack> fuels,
@Nonnull ModList modList) {
public ItemRegistry(ImmutableList<ItemStack> itemList,
ImmutableListMultimap<String, ItemStack> itemsByModId,
ImmutableList<ItemStack> potionIngredients,
ImmutableList<ItemStack> fuels,
ModList modList) {
this.itemList = itemList;
this.itemsByModId = itemsByModId;
this.potionIngredients = potionIngredients;
Expand All @@ -39,24 +31,20 @@ public ItemRegistry(@Nonnull ImmutableList<ItemStack> itemList,
}

@Override
@Nonnull
public ImmutableList<ItemStack> getItemList() {
return itemList;
}

@Override
@Nonnull
public ImmutableList<ItemStack> getFuels() {
return fuels;
}

@Override
@Nonnull
public ImmutableList<ItemStack> getPotionIngredients() {
return potionIngredients;
}

@Nonnull
@Override
public String getModNameForItem(@Nullable Item item) {
if (item == null) {
Expand All @@ -66,12 +54,15 @@ public String getModNameForItem(@Nullable Item item) {
return modList.getModNameForItem(item);
}

@Nonnull
public String getModNameForModId(@Nonnull String modId) {
@Override
public String getModNameForModId(@Nullable String modId) {
if (modId == null) {
Log.error("Null modId", new NullPointerException());
return "";
}
return modList.getModNameForModId(modId);
}

@Nonnull
@Override
public ImmutableList<ItemStack> getItemListForModId(@Nullable String modId) {
if (modId == null) {
Expand Down

0 comments on commit 9bb4147

Please sign in to comment.