1515
1616public class GLConstants extends Constants {
1717
18- private static final JSONObject json = getJson () ;
18+ private final JSONObject json ;
1919
20- private static final List _PACKAGES = json . getJSONArray ( "PACKAGES" ). toList () ;
21- private static final Pattern _CALL_REGEX = Pattern . compile ( "(" + String . join ( "|" , _PACKAGES ) + ") \\ .([ \\ w]+) \\ (.+? \\ )" ) ;
22- private static final Pattern _CONSTANT_REGEX = Pattern . compile ( "(?<![-. \\ w]) \\ d+(?![. \\ w])" ) ;
23- private static final Pattern _INPUT_REGEX = Pattern . compile ( "((Keyboard) \\ .((getKeyName|isKeyDown) \\ (.+? \\ )|getEventKey \\ ( \\ ) == .+?(?=[ \\ );]))|new KeyBinding \\ ([ \\ w \\ \" ]+, .+? \\ ))" ) ;
24- private static final Pattern _IMPORT = Pattern . compile ( "import [.* \\ w]+;" ) ;
25- private static final Map _CONSTANTS_KEYBOARD = Util . jsonToMap ( json . getJSONObject ( "CONSTANTS_KEYBOARD" )) ;
26- private static final List _CONSTANTS = Util . jsonToList ( json . getJSONArray ( "CONSTANTS" )) ;
20+ private final List _PACKAGES ;
21+ private final Pattern _CALL_REGEX ;
22+ private final Pattern _CONSTANT_REGEX ;
23+ private final Pattern _INPUT_REGEX ;
24+ private final Pattern _IMPORT ;
25+ private final Map _CONSTANTS_KEYBOARD ;
26+ private final List _CONSTANTS ;
2727
28- private static String updateImport (String code , String imp ) {
28+ public GLConstants () throws JSONException , IOException {
29+ json = getJson ();
30+
31+ _PACKAGES = json .getJSONArray ("PACKAGES" ).toList ();
32+ _CALL_REGEX = Pattern .compile ("(" + String .join ("|" , _PACKAGES ) + ")\\ .([\\ w]+)\\ (.+?\\ )" );
33+ _CONSTANT_REGEX = Pattern .compile ("(?<![-.\\ w])\\ d+(?![.\\ w])" );
34+ _INPUT_REGEX = Pattern .compile ("((Keyboard)\\ .((getKeyName|isKeyDown)\\ (.+?\\ )|getEventKey\\ (\\ ) == .+?(?=[\\ );]))|new KeyBinding\\ ([ \\ w\\ \" ]+, .+?\\ ))" );
35+ _IMPORT = Pattern .compile ("import [.*\\ w]+;" );
36+ _CONSTANTS_KEYBOARD = Util .jsonToMap (json .getJSONObject ("CONSTANTS_KEYBOARD" ));
37+ _CONSTANTS = Util .jsonToList (json .getJSONArray ("CONSTANTS" ));
38+ }
39+
40+ private String updateImport (String code , String imp ) {
2941 Matcher matcher = _IMPORT .matcher (code );
3042 int lastIndex = -1 ;
3143 while (matcher .find ()) {
@@ -38,7 +50,7 @@ private static String updateImport(String code, String imp) {
3850 return code ;
3951 }
4052
41- protected static String replace_constants (String code ) {
53+ protected String replace_constants (String code ) {
4254 Set <String > imports = new HashSet <String >();
4355 code = replaceTextOfMatchGroup (code , _INPUT_REGEX , match1 -> {
4456 String full_call = match1 .group (0 );
@@ -77,12 +89,7 @@ protected static String replace_constants(String code) {
7789 return code ;
7890 }
7991
80- private static JSONObject getJson () {
81- try {
82- return Util .parseJSONFile (GLConstants .class .getClassLoader ().getResourceAsStream ("gl_constants.json" ));
83- } catch (JSONException | IOException e ) {
84- e .printStackTrace ();
85- return null ;
86- }
92+ private static JSONObject getJson () throws JSONException , IOException {
93+ return Util .parseJSONFile (GLConstants .class .getClassLoader ().getResourceAsStream ("gl_constants.json" ));
8794 }
8895}
0 commit comments