@@ -88,39 +88,39 @@ private static void processConfig(Class<?> configClass) throws IllegalAccessExce
8888 val comment = Optional .ofNullable (field .getAnnotation (Config .Comment .class )).map (Config .Comment ::value ).map ((lines ) -> String .join ("\n " , lines )).orElse ("" );
8989 val name = Optional .ofNullable (field .getAnnotation (Config .Name .class )).map (Config .Name ::value ).orElse (field .getName ());
9090 val langKey = Optional .ofNullable (field .getAnnotation (Config .LangKey .class )).map (Config .LangKey ::value ).orElse (name );
91+ val fieldClass = field .getType ();
9192 var boxed = false ;
92- if ((boxed = field . getType (). equals (Boolean .class )) || field . getType () .equals (boolean .class )) {
93+ if ((boxed = fieldClass . equals (Boolean .class )) || fieldClass .equals (boolean .class )) {
9394 val defaultValue = Optional .ofNullable (field .getAnnotation (Config .DefaultBoolean .class )).map (Config .DefaultBoolean ::value ).orElse (boxed ? (Boolean ) field .get (null ) : field .getBoolean (null ));
9495 field .setBoolean (null , rawConfig .getBoolean (name , category , defaultValue , comment , langKey ));
95- } else if ((boxed = field . getType (). equals (Integer .class )) || field . getType () .equals (int .class )) {
96+ } else if ((boxed = fieldClass . equals (Integer .class )) || fieldClass .equals (int .class )) {
9697 val range = Optional .ofNullable (field .getAnnotation (Config .RangeInt .class ));
9798 val min = range .map (Config .RangeInt ::min ).orElse (Integer .MIN_VALUE );
9899 val max = range .map (Config .RangeInt ::max ).orElse (Integer .MAX_VALUE );
99100 val defaultValue = Optional .ofNullable (field .getAnnotation (Config .DefaultInt .class )).map (Config .DefaultInt ::value ).orElse (boxed ? (Integer )field .get (null ) : field .getInt (null ));
100101 field .setInt (null , rawConfig .getInt (name , category , defaultValue , min , max , comment , langKey ));
101- } else if ((boxed = field . getType (). equals (Float .class )) || field . getType () .equals (float .class )) {
102+ } else if ((boxed = fieldClass . equals (Float .class )) || fieldClass .equals (float .class )) {
102103 val range = Optional .ofNullable (field .getAnnotation (Config .RangeFloat .class ));
103104 val min = range .map (Config .RangeFloat ::min ).orElse (Float .MIN_VALUE );
104105 val max = range .map (Config .RangeFloat ::max ).orElse (Float .MAX_VALUE );
105106 val defaultValue = Optional .ofNullable (field .getAnnotation (Config .DefaultFloat .class )).map (Config .DefaultFloat ::value ).orElse (boxed ? (Float ) field .get (null ) : field .getFloat (null ));
106107 field .setDouble (null , rawConfig .getFloat (name , category , defaultValue , min , max , comment , langKey ));
107- } else if (field . getType () .equals (String .class )) {
108+ } else if (fieldClass .equals (String .class )) {
108109 val defaultValue = Optional .ofNullable (field .getAnnotation (Config .DefaultString .class )).map (Config .DefaultString ::value ).orElse ((String )field .get (null ));
109110 val pattern = Optional .ofNullable (field .getAnnotation (Config .Pattern .class )).map (Config .Pattern ::value ).map (Pattern ::compile ).orElse (null );
110111 field .set (null , rawConfig .getString (name , category , defaultValue , comment , langKey , pattern ));
111- } else if (field .isEnumConstant ()) {
112- val enumClass = field .getType ();
113- val enumValues = Arrays .stream ((Object [])enumClass .getDeclaredMethod ("values" ).invoke (null )).map ((obj ) -> (Enum <?>)obj ).collect (Collectors .toList ());
112+ } else if (fieldClass .isEnum ()) {
113+ val enumValues = Arrays .stream ((Object [])fieldClass .getDeclaredMethod ("values" ).invoke (null )).map ((obj ) -> (Enum <?>)obj ).collect (Collectors .toList ());
114114 val defaultValue = (Enum <?>)
115115 Optional .ofNullable (field .getAnnotation (Config .DefaultEnum .class ))
116116 .map (Config .DefaultEnum ::value )
117- .map ((defName ) -> extractField (enumClass , defName ))
117+ .map ((defName ) -> extractField (fieldClass , defName ))
118118 .map (ConfigurationManager ::extractValue )
119119 .orElse (field .get (null ));
120120 val possibleValues = enumValues .stream ().map (Enum ::name ).toArray (String []::new );
121- field .set (null , enumClass .getDeclaredField (rawConfig .getString (name , category , defaultValue .name (), comment , possibleValues , langKey )));
121+ field .set (null , fieldClass .getDeclaredField (rawConfig .getString (name , category , defaultValue .name (), comment , possibleValues , langKey )));
122122 } else {
123- throw new ConfigException ("Illegal config field: " + field .getName () + " in " + configClass .getName () + ": Unsupported type " + field . getType () .getName () + "! Did you forget an @Ignore annotation?" );
123+ throw new ConfigException ("Illegal config field: " + field .getName () + " in " + configClass .getName () + ": Unsupported type " + fieldClass .getName () + "! Did you forget an @Ignore annotation?" );
124124 }
125125 if (field .isAnnotationPresent (Config .RequiresMcRestart .class )) {
126126 cat .setRequiresMcRestart (true );
0 commit comments