dakotahNorth / solace-spring-boot-starter

0 stars 0 forks source link

Sweep: Remove messageType and eventClass from MessageHandler #4

Closed dakotahNorth closed 6 months ago

dakotahNorth commented 6 months ago

Details

Make messageType and eventClass arguments optional in MessageHandler and when those values are not provided, extract those values from method annotated with MessageHandler parameter.

For example instead of doing this

@Component
public static class TestMessageHandler {

    @val final List<ExampleEvent> receivedEvents = new ArrayList<>(16);

    @MessageHandler(messageType = "ExampleEvent", eventClass = ExampleEvent.class)
    public final void handleExampleEvent(ExampleEvent event) {
        receivedEvents.add(event);
    }
}

Use refection to get the

@Component
public static class TestMessageHandler {

    @val final List<ExampleEvent> receivedEvents = new ArrayList<>(16);

    @MessageHandler
    public final void handleExampleEvent(ExampleEvent event) {
        receivedEvents.add(event);
    }
}

Make the necessary changes to MessageHandler.java, SolaceMessageListener.java and SolaceMessageListenerTest.java.

Ensure the test in SolaceMessageHandlerTest still passes.

Branch

No response

Checklist - [X] Modify `src/main/java/com/example/solace/springboot/starter/messaging/MessageHandler.java` ✓ https://github.com/dakotahNorth/solace-spring-boot-starter/commit/abd2cd2670079ffa2c34e001bcea802cc84e9a44 [Edit](https://github.com/dakotahNorth/solace-spring-boot-starter/edit/sweep/remove_messagetype_and_eventclass_from_m/src/main/java/com/example/solace/springboot/starter/messaging/MessageHandler.java) - [X] Running GitHub Actions for `src/main/java/com/example/solace/springboot/starter/messaging/MessageHandler.java` ✓ [Edit](https://github.com/dakotahNorth/solace-spring-boot-starter/edit/sweep/remove_messagetype_and_eventclass_from_m/src/main/java/com/example/solace/springboot/starter/messaging/MessageHandler.java) - [X] Modify `src/main/java/com/example/solace/springboot/starter/messaging/SolaceMessageListener.java` ✓ https://github.com/dakotahNorth/solace-spring-boot-starter/commit/00a027fbbbd7a0a41665390d04d7f228fc6e3456 [Edit](https://github.com/dakotahNorth/solace-spring-boot-starter/edit/sweep/remove_messagetype_and_eventclass_from_m/src/main/java/com/example/solace/springboot/starter/messaging/SolaceMessageListener.java) - [X] Running GitHub Actions for `src/main/java/com/example/solace/springboot/starter/messaging/SolaceMessageListener.java` ✓ [Edit](https://github.com/dakotahNorth/solace-spring-boot-starter/edit/sweep/remove_messagetype_and_eventclass_from_m/src/main/java/com/example/solace/springboot/starter/messaging/SolaceMessageListener.java) - [X] Modify `src/test/java/com/example/solace/springboot/starter/messaging/SolaceMessageListenerTest.java` ✓ https://github.com/dakotahNorth/solace-spring-boot-starter/commit/3c6bf35c39ced8c484f133ef62bef008ae121e75 [Edit](https://github.com/dakotahNorth/solace-spring-boot-starter/edit/sweep/remove_messagetype_and_eventclass_from_m/src/test/java/com/example/solace/springboot/starter/messaging/SolaceMessageListenerTest.java) - [X] Running GitHub Actions for `src/test/java/com/example/solace/springboot/starter/messaging/SolaceMessageListenerTest.java` ✓ [Edit](https://github.com/dakotahNorth/solace-spring-boot-starter/edit/sweep/remove_messagetype_and_eventclass_from_m/src/test/java/com/example/solace/springboot/starter/messaging/SolaceMessageListenerTest.java)
sweep-ai[bot] commented 6 months ago

🚀 Here's the PR! #5

See Sweep's progress at the progress dashboard!
💎 Sweep Pro: I'm using GPT-4. You have unlimited GPT-4 tickets. (tracking ID: 7da6c774b1)

[!TIP] I can email you next time I complete a pull request if you set up your email here!


Actions (click)


Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/dakotahNorth/solace-spring-boot-starter/blob/0eac27ea2f01e9a631d99bd2fbfbd14f72f66bf4/src/main/java/com/example/solace/springboot/starter/messaging/SolaceMessageListener.java#L26-L145 https://github.com/dakotahNorth/solace-spring-boot-starter/blob/0eac27ea2f01e9a631d99bd2fbfbd14f72f66bf4/src/main/java/com/example/solace/springboot/starter/messaging/MessageHandler.java#L1-L22 https://github.com/dakotahNorth/solace-spring-boot-starter/blob/0eac27ea2f01e9a631d99bd2fbfbd14f72f66bf4/src/test/java/com/example/solace/springboot/starter/messaging/SolaceMessageListenerTest.java#L1-L47

Step 2: ⌨️ Coding

--- 
+++ 
@@ -18,6 +18,6 @@
 @Target(ElementType.METHOD)
 @Retention(RetentionPolicy.RUNTIME)
 public @interface MessageHandler {
-    String messageType();
-    Class eventClass();
+    String messageType() default "";
+    Class eventClass() default Void.class;
 }

Ran GitHub Actions for abd2cd2670079ffa2c34e001bcea802cc84e9a44:

--- 
+++ 
@@ -45,7 +45,10 @@
             if (method.isAnnotationPresent(MessageHandler.class)) {
                 MessageHandler annotation = method.getAnnotation(MessageHandler.class);
                 String messageType = annotation.messageType();
-                Class eventClass = annotation.eventClass();
+                Class eventClass = annotation.eventClass().equals(Void.class) ? method.getParameterTypes()[0] : annotation.eventClass();
+                if (messageType.isEmpty()) {
+                    messageType = eventClass.getSimpleName();
+                }
                 messageTypeHandlers.put(messageType, createHandler(method, eventClass, bean));
             }
         }

Ran GitHub Actions for 00a027fbbbd7a0a41665390d04d7f228fc6e3456:

--- 
+++ 
@@ -19,7 +19,7 @@

         @val final List receivedEvents = new ArrayList<>(16);

-        @MessageHandler(messageType = "ExampleEvent", eventClass = ExampleEvent.class)
+        @MessageHandler
         public final void handleExampleEvent(ExampleEvent event) {
             receivedEvents.add(event);
         }

Ran GitHub Actions for 3c6bf35c39ced8c484f133ef62bef008ae121e75:


Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/remove_messagetype_and_eventclass_from_m.


🎉 Latest improvements to Sweep:
  • New dashboard launched for real-time tracking of Sweep issues, covering all stages from search to coding.
  • Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
  • Use the GitHub issues extension for creating Sweep issues directly from your editor.

💡 To recreate the pull request edit the issue title or description. Something wrong? Let us know.

This is an automated message generated by Sweep AI.

dakotahNorth commented 6 months ago

Very impressive.