You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Sammy Yu (JIRA)" <ji...@apache.org> on 2009/07/27 23:10:14 UTC

[jira] Created: (THRIFT-551) Enumeration doesn't generate real enum in Java

Enumeration doesn't generate real enum in Java
----------------------------------------------

                 Key: THRIFT-551
                 URL: https://issues.apache.org/jira/browse/THRIFT-551
             Project: Thrift
          Issue Type: Bug
          Components: Compiler (Java)
            Reporter: Sammy Yu


When a enum is specified in the interface file, the code that is generated for Java just creates a empty class with a list of static integer constants, a list of valid values, and a map of values to names.  It would be better if the enum is created instead.


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-551) Enumeration doesn't generate real enum in Java

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-551?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12779732#action_12779732 ] 

Bryan Duxbury commented on THRIFT-551:
--------------------------------------

OK, assuming no one objects, I am going to commit this tonight.

> Enumeration doesn't generate real enum in Java
> ----------------------------------------------
>
>                 Key: THRIFT-551
>                 URL: https://issues.apache.org/jira/browse/THRIFT-551
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Java)
>            Reporter: Sammy Yu
>            Assignee: Bryan Duxbury
>         Attachments: thrift-551.patch
>
>
> When a enum is specified in the interface file, the code that is generated for Java just creates a empty class with a list of static integer constants, a list of valid values, and a map of values to names.  It would be better if the enum is created instead.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-551) Enumeration doesn't generate real enum in Java

Posted by "Mohammad Shahangian (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-551?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12779666#action_12779666 ] 

Mohammad Shahangian commented on THRIFT-551:
--------------------------------------------

Bryan, I reviewed the final patch and it looks good to me.

> Enumeration doesn't generate real enum in Java
> ----------------------------------------------
>
>                 Key: THRIFT-551
>                 URL: https://issues.apache.org/jira/browse/THRIFT-551
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Java)
>            Reporter: Sammy Yu
>            Assignee: Bryan Duxbury
>         Attachments: thrift-551.patch
>
>
> When a enum is specified in the interface file, the code that is generated for Java just creates a empty class with a list of static integer constants, a list of valid values, and a map of values to names.  It would be better if the enum is created instead.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (THRIFT-551) Enumeration doesn't generate real enum in Java

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-551?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bryan Duxbury reassigned THRIFT-551:
------------------------------------

    Assignee: Bryan Duxbury

> Enumeration doesn't generate real enum in Java
> ----------------------------------------------
>
>                 Key: THRIFT-551
>                 URL: https://issues.apache.org/jira/browse/THRIFT-551
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Java)
>            Reporter: Sammy Yu
>            Assignee: Bryan Duxbury
>
> When a enum is specified in the interface file, the code that is generated for Java just creates a empty class with a list of static integer constants, a list of valid values, and a map of values to names.  It would be better if the enum is created instead.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (THRIFT-551) Enumeration doesn't generate real enum in Java

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-551?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bryan Duxbury updated THRIFT-551:
---------------------------------

    Attachment: thrift-551.patch

Here's the first draft of this functionality. I had heavy assistance from Mohammad Shahangian on this one. 

I'd love some review of the changes.

> Enumeration doesn't generate real enum in Java
> ----------------------------------------------
>
>                 Key: THRIFT-551
>                 URL: https://issues.apache.org/jira/browse/THRIFT-551
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Java)
>            Reporter: Sammy Yu
>            Assignee: Bryan Duxbury
>         Attachments: thrift-551.patch
>
>
> When a enum is specified in the interface file, the code that is generated for Java just creates a empty class with a list of static integer constants, a list of valid values, and a map of values to names.  It would be better if the enum is created instead.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-551) Enumeration doesn't generate real enum in Java

Posted by "Mark McBride (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-551?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12741920#action_12741920 ] 

Mark McBride commented on THRIFT-551:
-------------------------------------

I'd like to see this added.  The generated thrift Java interfaces aren't really clear that some ints are actually enums.  Maybe add it is an optional flag?

> Enumeration doesn't generate real enum in Java
> ----------------------------------------------
>
>                 Key: THRIFT-551
>                 URL: https://issues.apache.org/jira/browse/THRIFT-551
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Java)
>            Reporter: Sammy Yu
>
> When a enum is specified in the interface file, the code that is generated for Java just creates a empty class with a list of static integer constants, a list of valid values, and a map of values to names.  It would be better if the enum is created instead.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-551) Enumeration doesn't generate real enum in Java

Posted by "David Reiss (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-551?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12779283#action_12779283 ] 

David Reiss commented on THRIFT-551:
------------------------------------

Eventually, it might make sense to split TType into one enum that is used internally for type tags and another one that is used for the metaDataMap for application code consumption.  Overloading the one enum seems a little dangerous.

> Enumeration doesn't generate real enum in Java
> ----------------------------------------------
>
>                 Key: THRIFT-551
>                 URL: https://issues.apache.org/jira/browse/THRIFT-551
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Java)
>            Reporter: Sammy Yu
>            Assignee: Bryan Duxbury
>         Attachments: thrift-551.patch
>
>
> When a enum is specified in the interface file, the code that is generated for Java just creates a empty class with a list of static integer constants, a list of valid values, and a map of values to names.  It would be better if the enum is created instead.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (THRIFT-551) Enumeration doesn't generate real enum in Java

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-551?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bryan Duxbury resolved THRIFT-551.
----------------------------------

       Resolution: Fixed
    Fix Version/s: 0.2

I committed this patch.

> Enumeration doesn't generate real enum in Java
> ----------------------------------------------
>
>                 Key: THRIFT-551
>                 URL: https://issues.apache.org/jira/browse/THRIFT-551
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Java)
>            Reporter: Sammy Yu
>            Assignee: Bryan Duxbury
>             Fix For: 0.2
>
>         Attachments: thrift-551.patch
>
>
> When a enum is specified in the interface file, the code that is generated for Java just creates a empty class with a list of static integer constants, a list of valid values, and a map of values to names.  It would be better if the enum is created instead.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-551) Enumeration doesn't generate real enum in Java

Posted by "Mathias Herberts (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-551?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12777696#action_12777696 ] 

Mathias Herberts commented on THRIFT-551:
-----------------------------------------

Won't the ENUM=16 in class TType break TCompactProtocol which encodes field id deltas (if field id is less than 16 apart from previous field id) as upper 4 bits (with lower 4 bits being field type)?

> Enumeration doesn't generate real enum in Java
> ----------------------------------------------
>
>                 Key: THRIFT-551
>                 URL: https://issues.apache.org/jira/browse/THRIFT-551
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Java)
>            Reporter: Sammy Yu
>            Assignee: Bryan Duxbury
>         Attachments: thrift-551.patch
>
>
> When a enum is specified in the interface file, the code that is generated for Java just creates a empty class with a list of static integer constants, a list of valid values, and a map of values to names.  It would be better if the enum is created instead.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-551) Enumeration doesn't generate real enum in Java

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-551?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12736846#action_12736846 ] 

Bryan Duxbury commented on THRIFT-551:
--------------------------------------

It looks like this would indeed be a very cool change to make. However it would be a pretty substantial breaking change to existing generated code. What do people think? Should we do this?

> Enumeration doesn't generate real enum in Java
> ----------------------------------------------
>
>                 Key: THRIFT-551
>                 URL: https://issues.apache.org/jira/browse/THRIFT-551
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Java)
>            Reporter: Sammy Yu
>
> When a enum is specified in the interface file, the code that is generated for Java just creates a empty class with a list of static integer constants, a list of valid values, and a map of values to names.  It would be better if the enum is created instead.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-551) Enumeration doesn't generate real enum in Java

Posted by "David Reiss (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-551?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12779316#action_12779316 ] 

David Reiss commented on THRIFT-551:
------------------------------------

Well, given that this appears to be the first case where we are putting a value in there that doesn't correspond to a wire value, it might be the time. :)  I'm okay with delaying it, though, since there isn't much of a cost.  There is some unused junk in the C++ version that has never caused any headaches.

> Enumeration doesn't generate real enum in Java
> ----------------------------------------------
>
>                 Key: THRIFT-551
>                 URL: https://issues.apache.org/jira/browse/THRIFT-551
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Java)
>            Reporter: Sammy Yu
>            Assignee: Bryan Duxbury
>         Attachments: thrift-551.patch
>
>
> When a enum is specified in the interface file, the code that is generated for Java just creates a empty class with a list of static integer constants, a list of valid values, and a map of values to names.  It would be better if the enum is created instead.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-551) Enumeration doesn't generate real enum in Java

Posted by "Jarski (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-551?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12738182#action_12738182 ] 

Jarski commented on THRIFT-551:
-------------------------------

This would indeed be very helpful now that java enums are in common use... I've been wanting to experiment with doing this for a while but not got around to it. However, it is a substantial breaking change --  perhaps it could be made user selectable, so that people who want to stick with the old int-based enum values can do so? 

One other consideration: People may now be relying on persisted int enum values, so it'd be necessary to be able to keep the associated int. One way to bridge that is to keep the same int values associated with the enums if people could be made into properties of the enum definitions, e.g. 

public class MyEnum {
  public static final int X = 0;
  public static final int Y = 100;  // skipped a few to show that they don't have to be all there
}

becomes

public enum MyEnum {
  X (0),
  Y (100);
  public final int value;
  private MyEnum(int value) { this.value = value; }
  public static MyEnum fromIntValue(int X) { // iterate through and pick };
}



> Enumeration doesn't generate real enum in Java
> ----------------------------------------------
>
>                 Key: THRIFT-551
>                 URL: https://issues.apache.org/jira/browse/THRIFT-551
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Java)
>            Reporter: Sammy Yu
>
> When a enum is specified in the interface file, the code that is generated for Java just creates a empty class with a list of static integer constants, a list of valid values, and a map of values to names.  It would be better if the enum is created instead.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-551) Enumeration doesn't generate real enum in Java

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-551?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12779298#action_12779298 ] 

Bryan Duxbury commented on THRIFT-551:
--------------------------------------

I agree with David. I don't know if now is that time, though. I suggest we open another ticket for that purpose.

> Enumeration doesn't generate real enum in Java
> ----------------------------------------------
>
>                 Key: THRIFT-551
>                 URL: https://issues.apache.org/jira/browse/THRIFT-551
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Java)
>            Reporter: Sammy Yu
>            Assignee: Bryan Duxbury
>         Attachments: thrift-551.patch
>
>
> When a enum is specified in the interface file, the code that is generated for Java just creates a empty class with a list of static integer constants, a list of valid values, and a map of values to names.  It would be better if the enum is created instead.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-551) Enumeration doesn't generate real enum in Java

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-551?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12777701#action_12777701 ] 

Bryan Duxbury commented on THRIFT-551:
--------------------------------------

Compact Protocol uses its own internal enumeration for encoding types on the wire. The ENUM addition to TType is essentially just for the metaDataMap changes.

> Enumeration doesn't generate real enum in Java
> ----------------------------------------------
>
>                 Key: THRIFT-551
>                 URL: https://issues.apache.org/jira/browse/THRIFT-551
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Java)
>            Reporter: Sammy Yu
>            Assignee: Bryan Duxbury
>         Attachments: thrift-551.patch
>
>
> When a enum is specified in the interface file, the code that is generated for Java just creates a empty class with a list of static integer constants, a list of valid values, and a map of values to names.  It would be better if the enum is created instead.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-551) Enumeration doesn't generate real enum in Java

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-551?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12778660#action_12778660 ] 

Bryan Duxbury commented on THRIFT-551:
--------------------------------------

Anyone else had any thoughts on this patch? I'd love to get it committed, and I'm guessing there's *something* in there that could bear improvement.

> Enumeration doesn't generate real enum in Java
> ----------------------------------------------
>
>                 Key: THRIFT-551
>                 URL: https://issues.apache.org/jira/browse/THRIFT-551
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Java)
>            Reporter: Sammy Yu
>            Assignee: Bryan Duxbury
>         Attachments: thrift-551.patch
>
>
> When a enum is specified in the interface file, the code that is generated for Java just creates a empty class with a list of static integer constants, a list of valid values, and a map of values to names.  It would be better if the enum is created instead.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.