mirror of
https://github.com/FalsePattern/FalsePatternLib.git
synced 2026-11-11 11:27:29 +00:00
replace default config warnings with crashes
This commit is contained in:
10 files changed
+19
-111
No files matched your search
@@ -46,6 +46,16 @@ public abstract class AConfigField<T> {
|
||||
protected final String comment;
|
||||
private boolean uninitialized;
|
||||
|
||||
public static RuntimeException noDefault(Field field, String annotation) {
|
||||
return new RuntimeException("The field "
|
||||
+ field.getName()
|
||||
+ " in class "
|
||||
+ field.getDeclaringClass().getName()
|
||||
+ " has no "
|
||||
+ annotation
|
||||
+ " annotation!");
|
||||
}
|
||||
|
||||
protected AConfigField(Field field, Configuration configuration, String category, Property.Type type) {
|
||||
this(field, configuration, category, type, false);
|
||||
}
|
||||
|
||||
+1
-13
@@ -43,19 +43,7 @@ public class BooleanConfigField extends AConfigField<Boolean> {
|
||||
primitive = field.getType().isPrimitive();
|
||||
defaultValue = Optional.ofNullable(field.getAnnotation(Config.DefaultBoolean.class))
|
||||
.map(Config.DefaultBoolean::value)
|
||||
.orElseGet(() -> {
|
||||
Share.LOG.warn("The field "
|
||||
+ field.getName()
|
||||
+ " in class "
|
||||
+ field.getDeclaringClass().getName()
|
||||
+ " has no DefaultBoolean annotation!\nThis will be a crash in FalsePatternLib 0.11, update your code!");
|
||||
try {
|
||||
return field.getType().isPrimitive() ? field.getBoolean(null)
|
||||
: (Boolean) field.get(null);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
.orElseThrow(() -> noDefault(field, "DefaultBoolean"));
|
||||
property.setDefaultValue(defaultValue);
|
||||
if (!property.isBooleanValue()) {
|
||||
setToDefault();
|
||||
|
||||
+1
-12
@@ -42,18 +42,7 @@ public class BooleanListConfigField extends AListConfigField<boolean[]> {
|
||||
super(field, configuration, category, Property.Type.BOOLEAN);
|
||||
defaultValue = Optional.ofNullable(field.getAnnotation(Config.DefaultBooleanList.class))
|
||||
.map(Config.DefaultBooleanList::value)
|
||||
.orElseGet(() -> {
|
||||
Share.LOG.warn("The field "
|
||||
+ field.getName()
|
||||
+ " in class "
|
||||
+ field.getDeclaringClass().getName()
|
||||
+ " has no DefaultBooleanList annotation!\nThis will be a crash in FalsePatternLib 0.11, update your code!");
|
||||
try {
|
||||
return (boolean[]) field.get(null);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
.orElseThrow(() -> noDefault(field, "DefaultBooleanList"));
|
||||
property.setDefaultValues(defaultValue);
|
||||
if (!property.isBooleanList()) {
|
||||
setToDefault();
|
||||
|
||||
+1
-13
@@ -49,19 +49,7 @@ public class DoubleConfigField extends AConfigField<Double> {
|
||||
max = range.map(Config.RangeDouble::max).orElse(Double.MAX_VALUE);
|
||||
defaultValue = Optional.ofNullable(field.getAnnotation(Config.DefaultDouble.class))
|
||||
.map(Config.DefaultDouble::value)
|
||||
.orElseGet(() -> {
|
||||
Share.LOG.warn("The field "
|
||||
+ field.getName()
|
||||
+ " in class "
|
||||
+ field.getDeclaringClass().getName()
|
||||
+ " has no DefaultDouble annotation!\nThis will be a crash in FalsePatternLib 0.11, update your code!");
|
||||
try {
|
||||
return field.getType().isPrimitive() ? field.getInt(null)
|
||||
: (Double) field.get(null);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
.orElseThrow(() -> noDefault(field, "DefaultDouble"));
|
||||
property.setDefaultValue(defaultValue);
|
||||
property.setMinValue(min);
|
||||
property.setMaxValue(max);
|
||||
|
||||
+1
-12
@@ -48,18 +48,7 @@ public class DoubleListConfigField extends AListConfigField<double[]> {
|
||||
max = range.map(Config.RangeDouble::max).orElse(Double.MAX_VALUE);
|
||||
defaultValue = Optional.ofNullable(field.getAnnotation(Config.DefaultDoubleList.class))
|
||||
.map(Config.DefaultDoubleList::value)
|
||||
.orElseGet(() -> {
|
||||
Share.LOG.warn("The field "
|
||||
+ field.getName()
|
||||
+ " in class "
|
||||
+ field.getDeclaringClass().getName()
|
||||
+ " has no DefaultDoubleList annotation!\nThis will be a crash in FalsePatternLib 0.11, update your code!");
|
||||
try {
|
||||
return (double[]) field.get(null);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
.orElseThrow(() -> noDefault(field, "DefaultDoubleList"));
|
||||
property.setDefaultValues(defaultValue);
|
||||
property.setMinValue(min);
|
||||
property.setMaxValue(max);
|
||||
|
||||
+1
-12
@@ -62,18 +62,7 @@ public class EnumConfigField<T extends Enum<T>> extends AConfigField<T> {
|
||||
+ defName
|
||||
+ "\" was not found in enum "
|
||||
+ enumClass.getName())))
|
||||
.orElseGet(() -> {
|
||||
Share.LOG.warn("The field "
|
||||
+ field.getName()
|
||||
+ " in class "
|
||||
+ field.getDeclaringClass().getName()
|
||||
+ " has no DefaultEnum annotation!\nThis will be a crash in FalsePatternLib 0.11, update your code!");
|
||||
try {
|
||||
return enumClass.cast(field.get(null));
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
.orElseThrow(() -> noDefault(field, "DefaultEnum"));
|
||||
maxLength = enumNameMap.keySet().stream().mapToInt(String::length).max().orElse(0);
|
||||
property.setDefaultValue(defaultValue.name());
|
||||
property.setValidValues(enumNameMap.keySet().toArray(new String[0]));
|
||||
|
||||
@@ -49,19 +49,7 @@ public class IntConfigField extends AConfigField<Integer> {
|
||||
max = range.map(Config.RangeInt::max).orElse(Integer.MAX_VALUE);
|
||||
defaultValue = Optional.ofNullable(field.getAnnotation(Config.DefaultInt.class))
|
||||
.map(Config.DefaultInt::value)
|
||||
.orElseGet(() -> {
|
||||
Share.LOG.warn("The field "
|
||||
+ field.getName()
|
||||
+ " in class "
|
||||
+ field.getDeclaringClass().getName()
|
||||
+ " has no DefaultInt annotation!\nThis will be a crash in FalsePatternLib 0.11, update your code!");
|
||||
try {
|
||||
return field.getType().isPrimitive() ? field.getInt(null)
|
||||
: (Integer) field.get(null);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
.orElseThrow(() -> noDefault(field, "DefaultInt"));
|
||||
property.setDefaultValue(defaultValue);
|
||||
property.setMinValue(min);
|
||||
property.setMaxValue(max);
|
||||
|
||||
+1
-12
@@ -48,18 +48,7 @@ public class IntListConfigField extends AListConfigField<int[]> {
|
||||
max = range.map(Config.RangeInt::max).orElse(Integer.MAX_VALUE);
|
||||
defaultValue = Optional.ofNullable(field.getAnnotation(Config.DefaultIntList.class))
|
||||
.map(Config.DefaultIntList::value)
|
||||
.orElseGet(() -> {
|
||||
Share.LOG.warn("The field "
|
||||
+ field.getName()
|
||||
+ " in class "
|
||||
+ field.getDeclaringClass().getName()
|
||||
+ " has no DefaultIntList annotation!\nThis will be a crash in FalsePatternLib 0.11, update your code!");
|
||||
try {
|
||||
return (int[]) field.get(null);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
.orElseThrow(() -> noDefault(field, "DefaultIntList"));
|
||||
property.setDefaultValues(defaultValue);
|
||||
property.setMinValue(min);
|
||||
property.setMaxValue(max);
|
||||
|
||||
+1
-12
@@ -48,18 +48,7 @@ public class StringConfigField extends AConfigField<String> {
|
||||
.orElse(null);
|
||||
defaultValue = Optional.ofNullable(field.getAnnotation(Config.DefaultString.class))
|
||||
.map(Config.DefaultString::value)
|
||||
.orElseGet(() -> {
|
||||
Share.LOG.warn("The field "
|
||||
+ field.getName()
|
||||
+ " in class "
|
||||
+ field.getDeclaringClass().getName()
|
||||
+ " has no DefaultString annotation!\nThis will be a crash in FalsePatternLib 0.11, update your code!");
|
||||
try {
|
||||
return (String) field.get(null);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
.orElseThrow(() -> noDefault(field, "DefaultString"));
|
||||
maxLength = Optional.ofNullable(field.getAnnotation(Config.StringMaxLength.class))
|
||||
.map(Config.StringMaxLength::value)
|
||||
.orElse(256);
|
||||
|
||||
+1
-12
@@ -48,18 +48,7 @@ public class StringListConfigField extends AListConfigField<String[]> {
|
||||
.orElse(null);
|
||||
defaultValue = Optional.ofNullable(field.getAnnotation(Config.DefaultStringList.class))
|
||||
.map(Config.DefaultStringList::value)
|
||||
.orElseGet(() -> {
|
||||
Share.LOG.warn("The field "
|
||||
+ field.getName()
|
||||
+ " in class "
|
||||
+ field.getDeclaringClass().getName()
|
||||
+ " has no DefaultStringList annotation!\nThis will be a crash in FalsePatternLib 0.11, update your code!");
|
||||
try {
|
||||
return (String[]) field.get(null);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
.orElseThrow(() -> noDefault(field, "DefaultStringList"));
|
||||
maxStringLength = Optional.ofNullable(field.getAnnotation(Config.StringMaxLength.class))
|
||||
.map(Config.StringMaxLength::value)
|
||||
.orElse(256);
|
||||
|
||||
Reference in new issue
Block a user