yahoo / squidb

SquiDB is a SQLite database library for Android and iOS
https://github.com/yahoo/squidb/wiki
Apache License 2.0
1.31k stars 132 forks source link

Inherit static fields and enums #214

Closed MFlisar closed 8 years ago

MFlisar commented 8 years ago

For the sake of code beauty, I want to define some table relevant classes, fields, enums in the Entry spec. But in code, I want to call the classes from the created table classes. Can I do that?

@TableModelSpec(className="GroupedFolder", tableName="groupedFolder")
@Implements(interfaceClasses = {Serializable.class})
public class GroupedFolderEntrySpec
{
    // generate this enum in GroupedFolder as well
    public enum Type
    {
    }
    // generate this static constant in GroupedFolder as well
    public static final int TYPE1 = 1; 
}

Is that somehow possible?

sbosley commented 8 years ago

Any static final field is treated as a constant and copied to the generated model class -- so for the int field in your example, I believe it already does what you want. We don't copy inner class or enum definitions (I'd be very wary of doing so as it would be easy to confuse the two separate but identical definitions), but if you really wanted to you could easily write a code generation plugin to do so -- see this wiki page.

MFlisar commented 8 years ago

You're right about the copying of enums, did not think about that... I'll check out the code generation plugin