Closed dakotahNorth closed 6 months ago
7da6c774b1
)[!TIP] I can email you next time I complete a pull request if you set up your email here!
I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.
src/main/java/com/example/solace/springboot/starter/messaging/MessageHandler.java
✓ https://github.com/dakotahNorth/solace-spring-boot-starter/commit/abd2cd2670079ffa2c34e001bcea802cc84e9a44 Edit
Modify src/main/java/com/example/solace/springboot/starter/messaging/MessageHandler.java with contents:
• Change the `messageType` attribute in the `@MessageHandler` annotation to have a default value of an empty string. For example, `String messageType() default "";`
• Change the `eventClass` attribute to default to `Void.class`. For example, `Class> eventClass() default Void.class;`
• These changes make both attributes optional, as requested.
--- +++ @@ -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; }
src/main/java/com/example/solace/springboot/starter/messaging/MessageHandler.java
✓ Edit
Check src/main/java/com/example/solace/springboot/starter/messaging/MessageHandler.java with contents:
Ran GitHub Actions for abd2cd2670079ffa2c34e001bcea802cc84e9a44:
src/main/java/com/example/solace/springboot/starter/messaging/SolaceMessageListener.java
✓ https://github.com/dakotahNorth/solace-spring-boot-starter/commit/00a027fbbbd7a0a41665390d04d7f228fc6e3456 Edit
Modify src/main/java/com/example/solace/springboot/starter/messaging/SolaceMessageListener.java with contents:
• In the `processBean` method, update the logic to handle cases where `messageType` and/or `eventClass` are not provided. Use reflection to extract the parameter type of the method annotated with `@MessageHandler` when `eventClass` is `Void.class`.
• If `messageType` is an empty string, derive the message type from the class name of the event parameter. This might involve converting the class name to a suitable message type string (e.g., `ExampleEvent` class to `"ExampleEvent"` message type).
• Update the `createHandler` method if necessary to support these changes, ensuring that the handler creation logic works with dynamically determined `eventClass` and `messageType`.
--- +++ @@ -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)); } }
src/main/java/com/example/solace/springboot/starter/messaging/SolaceMessageListener.java
✓ Edit
Check src/main/java/com/example/solace/springboot/starter/messaging/SolaceMessageListener.java with contents:
Ran GitHub Actions for 00a027fbbbd7a0a41665390d04d7f228fc6e3456:
src/test/java/com/example/solace/springboot/starter/messaging/SolaceMessageListenerTest.java
✓ https://github.com/dakotahNorth/solace-spring-boot-starter/commit/3c6bf35c39ced8c484f133ef62bef008ae121e75 Edit
Modify src/test/java/com/example/solace/springboot/starter/messaging/SolaceMessageListenerTest.java with contents:
• Modify the `TestMessageHandler` class to use the `@MessageHandler` annotation without specifying `messageType` and `eventClass`.
• This demonstrates that the updated logic in `SolaceMessageListener.java` can correctly infer these values from the method signature.
• Ensure the test `testReceivingExampleEvent` still passes with these changes, confirming that the functionality works as intended.
--- +++ @@ -19,7 +19,7 @@ @val final ListreceivedEvents = new ArrayList<>(16); - @MessageHandler(messageType = "ExampleEvent", eventClass = ExampleEvent.class) + @MessageHandler public final void handleExampleEvent(ExampleEvent event) { receivedEvents.add(event); }
src/test/java/com/example/solace/springboot/starter/messaging/SolaceMessageListenerTest.java
✓ Edit
Check src/test/java/com/example/solace/springboot/starter/messaging/SolaceMessageListenerTest.java with contents:
Ran GitHub Actions for 3c6bf35c39ced8c484f133ef62bef008ae121e75:
I have finished reviewing the code for completeness. I did not find errors for sweep/remove_messagetype_and_eventclass_from_m
.
💡 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.
Very impressive.
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
Use refection to get the
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)