java - How to get the type of a field in an annotation processor? -
I am trying to write an annotation so that it can detect whether the object is irreversible on runtime or not. To do this, I check that the object's class is final and then if all of its properties are final and then, I want to check the same thing for each field type if it is not a primitive type .
A piece of code here:
for (element sublement: element.get integrated allele ()) {if (sublement.gatekind () .isField ()) {IsFinal = false; (Modifier modifier: subElement.getModifiers ()) {if (modifier.equals (Modifier.FINAL)) {isFinal = true; break; }} If (IsFinal) {processingEnv.getMessager (). PrintMessage (Diagnosis. Kind.ERROR, "Field" + element + "is not immutable because it is not the last"); } Else {// I want to restart my method}}} How can I get my way to start with my area type again? What type of area can I retrieve, which is here?
Edit: I need a category which is declared in the class, which requires the final category to avoid any type of variability. /p>
I do not need to first javax.lang.model if you run the runtime If you want to check things, then instead I want to go through java.lang.Class and java.lang.reflect.Field . You can use the getType to retrieve the type of field you can see on all areas, using getFields Edit: The following idea is no longer relevant. P> Note that such information will return the declaration type, that is it Type as written in the source code. The area may still hold reference to the class derived on the runtime. In potential counter-measures all those sections will be declared as final so that there can be no derivative classes, or all the assignments in those areas can be detected, which means that the major static data flow analysis will be done. Not sure that the effort is worth.
Comments
Post a Comment