-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb38e0f
commit fc235f3
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...d/src/main/java/io/github/mela/command/provided/mappers/providers/EnumMapperProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.github.mela.command.provided.mappers.providers; | ||
|
||
import io.github.mela.command.bind.CommandBindings; | ||
import io.github.mela.command.bind.TargetType; | ||
import io.github.mela.command.bind.map.ArgumentMapper; | ||
import io.github.mela.command.bind.map.ArgumentMapperProvider; | ||
import io.github.mela.command.provided.mappers.EnumMapper; | ||
import java.lang.reflect.Type; | ||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* @author Johnny_JayJay (https://www.github.com/JohnnyJayJay) | ||
*/ | ||
public class EnumMapperProvider implements ArgumentMapperProvider { | ||
|
||
|
||
@SuppressWarnings({"unchecked", "rawtypes"}) | ||
@Nonnull | ||
@Override | ||
public ArgumentMapper<?> provideFor(@Nonnull TargetType type, @Nonnull CommandBindings bindings) { | ||
Class enumType = (Class) type.getType(); | ||
return new EnumMapper(enumType); | ||
} | ||
|
||
@Override | ||
public boolean canProvideFor(@Nonnull TargetType targetType) { | ||
Type type = targetType.getType(); | ||
if (!(type instanceof Class<?>) || type == Enum.class) { | ||
return false; | ||
} | ||
Class<?> clazz = (Class<?>) type; | ||
return Enum.class.isAssignableFrom(clazz); | ||
} | ||
} |