Skip to content

Commit

Permalink
pop review
Browse files Browse the repository at this point in the history
  • Loading branch information
JRoy committed Aug 24, 2022
1 parent 9771d16 commit a6441d7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,10 @@ public void finalizeRegistration() {
Class<? extends Provider> highestProvider = null;
ProviderData highestProviderData = null;
int highestWeight = -1;
providerLoop:
for (final Class<? extends Provider> provider : entry.getValue()) {
try {
final ProviderData providerData = provider.getAnnotation(ProviderData.class);
if (providerData.weight() > highestWeight) {
for (final Method method : provider.getMethods()) {
if (method.isAnnotationPresent(ProviderTest.class)) {
final Boolean result = (Boolean) method.invoke(null);
if (!result) {
continue providerLoop;
}
}
}

if (providerData.weight() > highestWeight && testProvider(provider)) {
highestWeight = providerData.weight();
highestProvider = provider;
highestProviderData = providerData;
Expand All @@ -84,12 +74,21 @@ public void finalizeRegistration() {
registeredProviders.clear();
}

private <C extends Provider> C getProviderInstance(final Class<C> provider) {
private boolean testProvider(final Class<?> providerClass) throws InvocationTargetException, IllegalAccessException {
for (final Method method : providerClass.getMethods()) {
if (method.isAnnotationPresent(ProviderTest.class)) {
return (Boolean) method.invoke(null);
}
}
return true;
}

private <P extends Provider> P getProviderInstance(final Class<P> provider) {
try {
final Constructor<?> constructor = provider.getConstructors()[0];
if (constructor.getParameterTypes().length == 0) {
//noinspection unchecked
return (C) constructor.newInstance();
return (P) constructor.newInstance();
}
final Object[] args = new Object[constructor.getParameterTypes().length];

Expand All @@ -105,7 +104,7 @@ private <C extends Provider> C getProviderInstance(final Class<C> provider) {
}

//noinspection unchecked
return (C) constructor.newInstance(args);
return (P) constructor.newInstance(args);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
try {
return provider.getConstructor().newInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public EntityType getSpawnedType(final ItemStack eggItem) throws IllegalArgument
public static boolean test() {
try {
//noinspection unused
final Material yourMother = Material.COW_SPAWN_EGG;
final Material itMakesMeDeclareAVariable = Material.COW_SPAWN_EGG;
return true;
} catch (final Throwable ignored) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public int getMinHeight(World world) {

@ProviderTest
public static boolean test() {
// troll face
// TODO: THIS IS INCORRECT
return false;
}
}

0 comments on commit a6441d7

Please sign in to comment.