@@ -133,6 +133,7 @@ public final class WhitelistLoader {
133133 */
134134 public static Whitelist loadFromResourceFiles (Class <?> resource , String ... filepaths ) {
135135 List <WhitelistClass > whitelistClasses = new ArrayList <>();
136+ List <WhitelistMethod > whitelistStatics = new ArrayList <>();
136137 List <WhitelistBinding > whitelistBindings = new ArrayList <>();
137138
138139 // Execute a single pass through the whitelist text files. This will gather all the
@@ -192,18 +193,18 @@ public static Whitelist loadFromResourceFiles(Class<?> resource, String... filep
192193 whitelistConstructors = new ArrayList <>();
193194 whitelistMethods = new ArrayList <>();
194195 whitelistFields = new ArrayList <>();
195- } else if (line .startsWith ("static " )) {
196+ } else if (line .startsWith ("static_import " )) {
196197 // Ensure the final token of the line is '{'.
197198 if (line .endsWith ("{" ) == false ) {
198199 throw new IllegalArgumentException (
199- "invalid static definition: failed to parse static opening bracket [" + line + "]" );
200+ "invalid static import definition: failed to parse static import opening bracket [" + line + "]" );
200201 }
201202
202203 if (parseType != null ) {
203- throw new IllegalArgumentException ("invalid definition: cannot embed static definition [" + line + "]" );
204+ throw new IllegalArgumentException ("invalid definition: cannot embed static import definition [" + line + "]" );
204205 }
205206
206- parseType = "static " ;
207+ parseType = "static_import " ;
207208
208209 // Handle the end of a definition and reset all previously gathered values.
209210 // Expects the following format: '}' '\n'
@@ -229,9 +230,9 @@ public static Whitelist loadFromResourceFiles(Class<?> resource, String... filep
229230 // Reset the parseType.
230231 parseType = null ;
231232
232- // Handle static definition types.
233- // Expects the following format: ID ID '(' ( ID ( ',' ID )* )? ')' ' bound_to' ID '\n'
234- } else if ("static " .equals (parseType )) {
233+ // Handle static import definition types.
234+ // Expects the following format: ID ID '(' ( ID ( ',' ID )* )? ')' ( 'from_class' | ' bound_to' ) ID '\n'
235+ } else if ("static_import " .equals (parseType )) {
235236 // Mark the origin of this parsable object.
236237 String origin = "[" + filepath + "]:[" + number + "]" ;
237238
@@ -240,7 +241,7 @@ public static Whitelist loadFromResourceFiles(Class<?> resource, String... filep
240241
241242 if (parameterStartIndex == -1 ) {
242243 throw new IllegalArgumentException (
243- "illegal static definition: start of method parameters not found [" + line + "]" );
244+ "illegal static import definition: start of method parameters not found [" + line + "]" );
244245 }
245246
246247 String [] tokens = line .substring (0 , parameterStartIndex ).trim ().split ("\\ s+" );
@@ -261,7 +262,7 @@ public static Whitelist loadFromResourceFiles(Class<?> resource, String... filep
261262
262263 if (parameterEndIndex == -1 ) {
263264 throw new IllegalArgumentException (
264- "illegal static definition: end of method parameters not found [" + line + "]" );
265+ "illegal static import definition: end of method parameters not found [" + line + "]" );
265266 }
266267
267268 String [] canonicalTypeNameParameters =
@@ -272,39 +273,37 @@ public static Whitelist loadFromResourceFiles(Class<?> resource, String... filep
272273 canonicalTypeNameParameters = new String [0 ];
273274 }
274275
275- // Parse the static type and class.
276+ // Parse the static import type and class.
276277 tokens = line .substring (parameterEndIndex + 1 ).trim ().split ("\\ s+" );
277278
278- String staticType ;
279+ String staticImportType ;
279280 String targetJavaClassName ;
280281
281282 // Based on the number of tokens, look up the type and class.
282283 if (tokens .length == 2 ) {
283- staticType = tokens [0 ];
284+ staticImportType = tokens [0 ];
284285 targetJavaClassName = tokens [1 ];
285286 } else {
286- throw new IllegalArgumentException ("invalid static definition: unexpected format [" + line + "]" );
287+ throw new IllegalArgumentException ("invalid static import definition: unexpected format [" + line + "]" );
287288 }
288289
289- // Check the static type is valid.
290- if ("bound_to" .equals (staticType ) == false ) {
291- throw new IllegalArgumentException (
292- "invalid static definition: unexpected static type [" + staticType + "] [" + line + "]" );
290+ // Add a static import method or binding depending on the static import type.
291+ if ("from_class" .equals (staticImportType )) {
292+ whitelistStatics .add (new WhitelistMethod (origin , targetJavaClassName ,
293+ methodName , returnCanonicalTypeName , Arrays .asList (canonicalTypeNameParameters )));
294+ } else if ("bound_to" .equals (staticImportType )) {
295+ whitelistBindings .add (new WhitelistBinding (origin , targetJavaClassName ,
296+ methodName , returnCanonicalTypeName , Arrays .asList (canonicalTypeNameParameters )));
297+ } else {
298+ throw new IllegalArgumentException ("invalid static import definition: " +
299+ "unexpected static import type [" + staticImportType + "] [" + line + "]" );
293300 }
294301
295- whitelistBindings .add (new WhitelistBinding (origin , targetJavaClassName ,
296- methodName , returnCanonicalTypeName , Arrays .asList (canonicalTypeNameParameters )));
297-
298302 // Handle class definition types.
299303 } else if ("class" .equals (parseType )) {
300304 // Mark the origin of this parsable object.
301305 String origin = "[" + filepath + "]:[" + number + "]" ;
302306
303- // Ensure we have a defined class before adding any constructors, methods, augmented methods, or fields.
304- if (parseType == null ) {
305- throw new IllegalArgumentException ("invalid definition: expected one of ['class', 'static'] [" + line + "]" );
306- }
307-
308307 // Handle the case for a constructor definition.
309308 // Expects the following format: '(' ( ID ( ',' ID )* )? ')' '\n'
310309 if (line .startsWith ("(" )) {
@@ -393,7 +392,7 @@ public static Whitelist loadFromResourceFiles(Class<?> resource, String... filep
393392
394393 ClassLoader loader = AccessController .doPrivileged ((PrivilegedAction <ClassLoader >)resource ::getClassLoader );
395394
396- return new Whitelist (loader , whitelistClasses , whitelistBindings );
395+ return new Whitelist (loader , whitelistClasses , whitelistStatics , whitelistBindings );
397396 }
398397
399398 private WhitelistLoader () {}
0 commit comments