@@ -608,6 +608,9 @@ private static void generateDispatcher(ClassOutput beanClassOutput,
608608
609609 ResultHandle gitHubEventRh = dispatchMethodCreator .getMethodParam (0 );
610610
611+ ResultHandle supportsInstallationRh = dispatchMethodCreator .invokeInterfaceMethod (
612+ MethodDescriptor .ofMethod (GitHubEvent .class , "supportsInstallation" , boolean .class ),
613+ gitHubEventRh );
611614 ResultHandle installationIdRh = dispatchMethodCreator .invokeInterfaceMethod (
612615 MethodDescriptor .ofMethod (GitHubEvent .class , "getInstallationId" , Long .class ),
613616 gitHubEventRh );
@@ -623,45 +626,55 @@ private static void generateDispatcher(ClassOutput beanClassOutput,
623626
624627 TryBlock tryBlock = dispatchMethodCreator .tryBlock ();
625628
626- // if the installation id is defined , we can push the installation client
629+ // if the event supports installation , we can push the installation client
627630 // if not, we have to use the very limited application client
628631 AssignableResultHandle gitHubRh = tryBlock .createVariable (GitHub .class );
629632 AssignableResultHandle gitHubGraphQLClientRh = tryBlock .createVariable (DynamicGraphQLClient .class );
630- BranchResult testInstallationId = tryBlock .ifNotNull (installationIdRh );
631- BytecodeCreator installationIdSet = testInstallationId .trueBranch ();
632- installationIdSet .assign (gitHubRh , installationIdSet .invokeVirtualMethod (
633- MethodDescriptor .ofMethod (GitHubService .class , "getInstallationClient" , GitHub .class , long .class ),
634- installationIdSet .readInstanceField (
635- FieldDescriptor .of (dispatcherClassCreator .getClassName (), GITHUB_SERVICE_FIELD , GitHubService .class ),
636- installationIdSet .getThis ()),
637- installationIdRh ));
633+ BranchResult testSupportsInstallation = tryBlock .ifTrue (supportsInstallationRh );
634+ BytecodeCreator supportsInstallationTrue = testSupportsInstallation .trueBranch ();
635+ if (dispatchingConfiguration .requiresGitHubClient ()) {
636+ supportsInstallationTrue .assign (gitHubRh , supportsInstallationTrue .invokeVirtualMethod (
637+ MethodDescriptor .ofMethod (GitHubService .class , "getInstallationClient" , GitHub .class , long .class ),
638+ supportsInstallationTrue .readInstanceField (
639+ FieldDescriptor .of (dispatcherClassCreator .getClassName (), GITHUB_SERVICE_FIELD ,
640+ GitHubService .class ),
641+ supportsInstallationTrue .getThis ()),
642+ installationIdRh ));
643+ } else {
644+ supportsInstallationTrue .assign (gitHubRh , supportsInstallationTrue .loadNull ());
645+ }
638646 if (dispatchingConfiguration .requiresGraphQLClient ()) {
639- installationIdSet .assign (gitHubGraphQLClientRh , installationIdSet .invokeVirtualMethod (
647+ supportsInstallationTrue .assign (gitHubGraphQLClientRh , supportsInstallationTrue .invokeVirtualMethod (
640648 MethodDescriptor .ofMethod (GitHubService .class , "getInstallationGraphQLClient" , DynamicGraphQLClient .class ,
641649 long .class ),
642- installationIdSet .readInstanceField (
650+ supportsInstallationTrue .readInstanceField (
643651 FieldDescriptor .of (dispatcherClassCreator .getClassName (), GITHUB_SERVICE_FIELD ,
644652 GitHubService .class ),
645- installationIdSet .getThis ()),
653+ supportsInstallationTrue .getThis ()),
646654 installationIdRh ));
647655 } else {
648- installationIdSet .assign (gitHubGraphQLClientRh , installationIdSet .loadNull ());
656+ supportsInstallationTrue .assign (gitHubGraphQLClientRh , supportsInstallationTrue .loadNull ());
657+ }
658+ BytecodeCreator supportsInstallationFalse = testSupportsInstallation .falseBranch ();
659+ if (dispatchingConfiguration .requiresGitHubClient ()) {
660+ supportsInstallationFalse .assign (gitHubRh , supportsInstallationFalse .invokeVirtualMethod (
661+ MethodDescriptor .ofMethod (GitHubService .class , "getTokenOrApplicationClient" , GitHub .class ),
662+ supportsInstallationFalse .readInstanceField (
663+ FieldDescriptor .of (dispatcherClassCreator .getClassName (), GITHUB_SERVICE_FIELD ,
664+ GitHubService .class ),
665+ supportsInstallationFalse .getThis ())));
666+ } else {
667+ supportsInstallationFalse .assign (gitHubRh , supportsInstallationFalse .loadNull ());
649668 }
650- BytecodeCreator installationIdNull = testInstallationId .falseBranch ();
651- installationIdNull .assign (gitHubRh , installationIdNull .invokeVirtualMethod (
652- MethodDescriptor .ofMethod (GitHubService .class , "getTokenOrApplicationClient" , GitHub .class ),
653- installationIdNull .readInstanceField (
654- FieldDescriptor .of (dispatcherClassCreator .getClassName (), GITHUB_SERVICE_FIELD , GitHubService .class ),
655- installationIdNull .getThis ())));
656669 if (dispatchingConfiguration .requiresGraphQLClient ()) {
657- installationIdNull .assign (gitHubGraphQLClientRh , installationIdNull .invokeVirtualMethod (
670+ supportsInstallationFalse .assign (gitHubGraphQLClientRh , supportsInstallationFalse .invokeVirtualMethod (
658671 MethodDescriptor .ofMethod (GitHubService .class , "getTokenGraphQLClientOrNull" , DynamicGraphQLClient .class ),
659- installationIdNull .readInstanceField (
672+ supportsInstallationFalse .readInstanceField (
660673 FieldDescriptor .of (dispatcherClassCreator .getClassName (), GITHUB_SERVICE_FIELD ,
661674 GitHubService .class ),
662- installationIdNull .getThis ())));
675+ supportsInstallationFalse .getThis ())));
663676 } else {
664- installationIdNull .assign (gitHubGraphQLClientRh , installationIdNull .loadNull ());
677+ supportsInstallationFalse .assign (gitHubGraphQLClientRh , supportsInstallationFalse .loadNull ());
665678 }
666679
667680 for (EventDispatchingConfiguration eventDispatchingConfiguration : dispatchingConfiguration .getEventConfigurations ()
0 commit comments