You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2023/01/03 08:22:24 UTC

[GitHub] [cloudstack] weizhouapache commented on a diff in pull request #7022: Cleanup APIs getCommandName

weizhouapache commented on code in PR #7022:
URL: https://github.com/apache/cloudstack/pull/7022#discussion_r1060355453


##########
api/src/main/java/org/apache/cloudstack/api/BaseCmd.java:
##########
@@ -247,30 +247,36 @@ public void setResponseType(final String responseType) {
         this.responseType = responseType;
     }
 
-    /**
-     * For some reason this method does not return the actual command name, but more a name that
-     * is used to create the response. So you can expect for a XCmd a value like xcmdresponse. Anyways
-     * this methods is used in too many places so for now instead of changing it we just create another
-     * method {@link BaseCmd#getActualCommandName()} that returns the value from {@link APICommand#name()}
-     *
-     * @return
-     */
-    public abstract String getCommandName();
-
-
     /**
      * Gets the CommandName based on the class annotations: the value from {@link APICommand#name()}
      *
      * @return the value from {@link APICommand#name()}
      */
-    public String getActualCommandName() {
+    public static String getCommandNameByClass(Class<?> clazz) {
         String cmdName = null;
-        if (this.getClass().getAnnotation(APICommand.class) != null) {
-            cmdName = this.getClass().getAnnotation(APICommand.class).name();
+        APICommand apiClassAnnotation = clazz.getAnnotation(APICommand.class);
+
+        if (apiClassAnnotation != null && apiClassAnnotation.name() != null) {
+            cmdName = apiClassAnnotation.name();
         } else {
-            cmdName = this.getClass().getName();
+            cmdName = clazz.getName();

Review Comment:
   @ezntt thanks for checking. it looks good to me.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org