dimanche 14 août 2016

How to get the annotation to take the default name of the class or field?

I've defined a Book class like so

@DatabaseTable(tableName = "books")
public class Book {

    @DatabaseField(generatedId = true)
    private int mId;

    @DatabaseField(columnName = "book_name", canBeNull = false)
    private String mBookName;

    public Book() {

    }

    public Book(String bookName) {
        mBookName = bookName;
    }

    public int getId() {
        return mId;
    }

    public void setId(int id) {
        mId = id;
    }

    public String getBookName() {
        return mBookName;
    }

    public void setBookName(String bookName) {
        mBookName = bookName;
    }

}

And a few annotation interfaces

public @interface DatabaseTable {
    String tableName() default "";
}

also

public @interface DatabaseField {
    String columnName() default "";
    boolean generatedId() default false;
    boolean canBeNull() default true;
}

However as you can see the names are default to empty strings right now. Let's say I declared the @DatabaseTable annotation but did not give a tableName. Then it would default to "". How can I change it to instead take the name of a class? For example in this case Book? Or in the case of a @DatabaseField, the member name?





Aucun commentaire:

Enregistrer un commentaire