josealdo
josealdo

Reputation: 1

LLVM vmkit java annotation

I am a novice in Java. I want to annotate (with a string) different Java variables that can be translated into LLVM IR (and get them by using llvm.var.annotation or llvm.global.annotations). In the case of C/C++, I use:

__attribute__((annotate("RED"))) static int a;

So a is annotated with the value "RED". My question is, how do I make this in Java (using vmkit for LLVM) ? I think I have to use @, but I do not know what libs do I have to add to vmkit and also how annotations in Java work?

Thank you for your answer !

Upvotes: 0

Views: 264

Answers (1)

Mohammed Falha
Mohammed Falha

Reputation: 967

Look for annotation tutorial in this link http://docs.oracle.com/javase/tutorial/java/annotations/

what you need to do is to define your annotation than make some sort of reflection. this is the @Red annotation

package test;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;


@Retention(RetentionPolicy.RUNTIME)
public @interface Red {

}

and this how to use it

public class AnyClass {

    @Red
    public int a = 5;

}

here is a simple test to get the annotated field

package test;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

public class TestClass {

    /**
     * @param args
     */
    public static void main(String[] args) {
        AnyClass anyClass = new AnyClass();
        Class clasz = anyClass.getClass();
        Field [] fArray = clasz.getFields();
        Annotation[] anArray = clasz.getAnnotations();
        for(Field f : fArray) {
            System.out.println("wink" + f.getAnnotations()[0].annotationType());
        }

    }

}

Upvotes: 1

Related Questions