Java Annotation building .class at compile time

1.4k views Asked by At

in my project i have to implements some annotations specifying a set of data type and the operation i can do on them.

After this i have to annotate some classes of my models package, specifying in that way what type of operation i can to on this class.

Eventually, at compile time, i have to parse the class with annotated field and build a new model representing the class and each operation i can do on its properties.

I was wondering what if the way i listed below could be a correct way to do this:

For example:

public @interface MySearchableType1 {         

    enum operations{
         EQUAL,
         NOT_EQUAL,
         LIKE,
         NOT_LIKE,
         IN,
         NOT_IN     
    }        
 }

public @interface MySearchableType2 {

    enum operations{
        EQUAL,
        NOT_EQUAL               
    }        
}

public class MyClass {

    public String name;

    @MySearchableType1
    public String property1;

    @MySearchableType2
    public String property2;
}

the final product should be something like this:

public class MyModelClass{
     public Map<String, String[]> property1 = new HasMap<String,String[]>();
    property1.put("property1", ["EQUAL", "NOT_EQUAL", "LIKE", "NOT_LIKE", "IN", "NOT_IN"]); 

    public Map<String, String[]> property2 = new HasMap<String,String[]>();
    property2.put("property21", ["EQUAL", "NOT_EQUAL"]);
}

What can i use to reach my target? Is it possible to obtain instanced .class file like the one i wrote maybe using spring? Can you give me an example?

1

There are 1 answers