@@ -283,40 +283,20 @@ private static String wrapText(String text, int maxColumns, String prefix) {
283283class TypeRef extends Element {
284284 String customType ;
285285
286- private static final Map <String , String > customTypeNames = new HashMap <>();
287- static {
288- customTypeNames .put ("APIRequest.newContext.options.clientCertificates" , "ClientCertificate" );
289- customTypeNames .put ("Browser.newContext.options.clientCertificates" , "ClientCertificate" );
290- customTypeNames .put ("Browser.newPage.options.clientCertificates" , "ClientCertificate" );
291- customTypeNames .put ("BrowserType.launchPersistentContext.options.clientCertificates" , "ClientCertificate" );
292-
293- customTypeNames .put ("BrowserContext.addCookies.cookies" , "Cookie" );
294- customTypeNames .put ("BrowserContext.cookies" , "Cookie" );
295-
296- customTypeNames .put ("Request.headersArray" , "HttpHeader" );
297- customTypeNames .put ("Response.headersArray" , "HttpHeader" );
298- customTypeNames .put ("APIResponse.headersArray" , "HttpHeader" );
299-
300- customTypeNames .put ("Locator.selectOption.values" , "SelectOption" );
301- customTypeNames .put ("ElementHandle.selectOption.values" , "SelectOption" );
302- customTypeNames .put ("Frame.selectOption.values" , "SelectOption" );
303- customTypeNames .put ("Page.selectOption.values" , "SelectOption" );
304-
305- customTypeNames .put ("Locator.setInputFiles.files" , "FilePayload" );
306- customTypeNames .put ("ElementHandle.setInputFiles.files" , "FilePayload" );
307- customTypeNames .put ("FileChooser.setFiles.files" , "FilePayload" );
308- customTypeNames .put ("Frame.setInputFiles.files" , "FilePayload" );
309- customTypeNames .put ("Page.setInputFiles.files" , "FilePayload" );
310- customTypeNames .put ("Page.setInputFiles.files" , "FilePayload" );
311- customTypeNames .put ("FormData.append.value" , "FilePayload" );
312- customTypeNames .put ("FormData.set.value" , "FilePayload" );
313-
314- customTypeNames .put ("Locator.dragTo.options.sourcePosition" , "Position" );
315- customTypeNames .put ("Page.dragAndDrop.options.sourcePosition" , "Position" );
316- customTypeNames .put ("Frame.dragAndDrop.options.sourcePosition" , "Position" );
317- customTypeNames .put ("Locator.dragTo.options.targetPosition" , "Position" );
318- customTypeNames .put ("Page.dragAndDrop.options.targetPosition" , "Position" );
319- customTypeNames .put ("Frame.dragAndDrop.options.targetPosition" , "Position" );
286+ // Returns the Java-specific type alias declared in the api docs (e.g. `alias-java: Cookie`),
287+ // falling back to the language-agnostic `alias` if no Java-specific override is provided.
288+ private static String javaAlias (JsonObject jsonType ) {
289+ if (!jsonType .has ("langAliases" )) {
290+ return null ;
291+ }
292+ JsonObject langAliases = jsonType .getAsJsonObject ("langAliases" );
293+ if (langAliases .has ("java" )) {
294+ return langAliases .get ("java" ).getAsString ();
295+ }
296+ if (langAliases .has ("default" )) {
297+ return langAliases .get ("default" ).getAsString ();
298+ }
299+ return null ;
320300 }
321301
322302 TypeRef (Element parent , JsonElement jsonElement ) {
@@ -355,8 +335,9 @@ private void createClassesAndEnums(JsonObject jsonObject) {
355335 customType = toTitle (parent .parent .jsonName ) + toTitle (parent .jsonName );
356336 typeScope ().createNestedClass (customType , this , jsonObject );
357337 } else {
358- if (customTypeNames .containsKey (jsonPath )) {
359- customType = customTypeNames .get (jsonPath );
338+ String alias = javaAlias (jsonObject );
339+ if (alias != null ) {
340+ customType = alias ;
360341 } else {
361342 customType = toTitle (parent .jsonName );
362343 }
@@ -534,15 +515,12 @@ private String convertBuiltinType(JsonObject jsonType) {
534515 return convertTemplateParams (jsonType );
535516 }
536517 if ("function" .equals (name )) {
518+ String alias = javaAlias (jsonType );
519+ if (alias != null ) {
520+ return alias ;
521+ }
537522 if (!jsonType .has ("args" )) {
538- switch (jsonPath ) {
539- case "BrowserContext.exposeBinding.callback" : return "BindingCallback" ;
540- case "BrowserContext.exposeFunction.callback" : return "FunctionCallback" ;
541- case "Page.exposeBinding.callback" : return "BindingCallback" ;
542- case "Page.exposeFunction.callback" : return "FunctionCallback" ;
543- default :
544- throw new RuntimeException ("Missing mapping for " + jsonPath );
545- }
523+ throw new RuntimeException ("Missing mapping for " + jsonPath );
546524 }
547525 if ("WebSocketRoute.onClose.handler" .equals (jsonPath )) {
548526 return "BiConsumer<Integer, String>" ;
0 commit comments