Fix class cast exception in NodeTypeKey#getTypeName (#1230)

This commit is contained in:
Luck
2018-09-23 14:38:27 +01:00
Unverified
parent 1cc156d6f6
commit 1e7ef15e54
8 changed files with 9 additions and 20 deletions
@@ -27,9 +27,6 @@ package me.lucko.luckperms.api.nodetype;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
/**
* Marks an instance used as a key for a {@link NodeType}.
*
@@ -47,9 +44,8 @@ public interface NodeTypeKey<N extends NodeType> {
* @return the name of the represented type
*/
default @NonNull String getTypeName() {
ParameterizedType thisType = (ParameterizedType) getClass().getGenericSuperclass();
Type nodeType = thisType.getActualTypeArguments()[0];
return ((Class) nodeType).getSimpleName();
String name = getClass().getName();
return name.substring(name.lastIndexOf('.') + 1, name.length() - 2);
}
}
@@ -41,8 +41,7 @@ public interface DisplayNameType extends NodeType {
/**
* The key for this type.
*/
NodeTypeKey<DisplayNameType> KEY = new NodeTypeKey<DisplayNameType>() {
};
NodeTypeKey<DisplayNameType> KEY = new NodeTypeKey<DisplayNameType>(){};
/**
* Gets the display name.
@@ -42,8 +42,7 @@ public interface InheritanceType extends NodeType {
/**
* The key for this type.
*/
NodeTypeKey<InheritanceType> KEY = new NodeTypeKey<InheritanceType>() {
};
NodeTypeKey<InheritanceType> KEY = new NodeTypeKey<InheritanceType>(){};
/**
* Gets the name of the group to be inherited.
@@ -43,8 +43,7 @@ public interface MetaType extends NodeType, Map.Entry<String, String> {
/**
* The key for this type.
*/
NodeTypeKey<MetaType> KEY = new NodeTypeKey<MetaType>() {
};
NodeTypeKey<MetaType> KEY = new NodeTypeKey<MetaType>(){};
/**
* Gets the meta key.
@@ -43,8 +43,7 @@ public interface PrefixType extends NodeType {
/**
* The key for this type.
*/
NodeTypeKey<PrefixType> KEY = new NodeTypeKey<PrefixType>() {
};
NodeTypeKey<PrefixType> KEY = new NodeTypeKey<PrefixType>(){};
/**
* Gets the priority of the prefix assignment.
@@ -44,8 +44,7 @@ public interface RegexType extends NodeType {
/**
* The key for this type.
*/
NodeTypeKey<RegexType> KEY = new NodeTypeKey<RegexType>() {
};
NodeTypeKey<RegexType> KEY = new NodeTypeKey<RegexType>(){};
/**
* Gets the non-compiled pattern string.
@@ -43,8 +43,7 @@ public interface SuffixType extends NodeType {
/**
* The key for this type.
*/
NodeTypeKey<SuffixType> KEY = new NodeTypeKey<SuffixType>() {
};
NodeTypeKey<SuffixType> KEY = new NodeTypeKey<SuffixType>(){};
/**
* Gets the priority of the suffix assignment.
@@ -39,8 +39,7 @@ public interface WeightType extends NodeType {
/**
* The key for this type.
*/
NodeTypeKey<WeightType> KEY = new NodeTypeKey<WeightType>() {
};
NodeTypeKey<WeightType> KEY = new NodeTypeKey<WeightType>(){};
/**
* Gets the weight value.