public void process()
{
Messager messager = _env.getMessager();
File sourceFile = null;
ArrayList<ConditionStatement> csList = new ArrayList<ConditionStatement>();

// obtain the declaration of the annotation we want to process
AnnotationTypeDeclaration annoDecl = (AnnotationTypeDeclaration)_env.getTypeDeclaration(ConditionAnnotation.class.getName());

// get the annotated types
Collection<Declaration> annotatedTypes = _env.getDeclarationsAnnotatedWith(annoDecl);

for (Declaration decl : annotatedTypes) {
ConditionStatement cs = new ConditionStatement();
cs.setLineNumber(decl.getPosition().line());
Collection<AnnotationMirror> mirrors = decl.getAnnotationMirrors();

// for each annotation found, get a map of element name/value pairs
for (AnnotationMirror mirror : mirrors) {
Map<AnnotationTypeElementDeclaration, AnnotationValue> valueMap = mirror.getElementValues();
Set<Map.Entry<AnnotationTypeElementDeclaration, AnnotationValue>> valueSet = valueMap.entrySet();

// the annotation processor understands two elements: "Pre" and "Post"
for (Map.Entry<AnnotationTypeElementDeclaration, AnnotationValue> annoKeyValue : valueSet) {
AnnotationValue annoValue = annoKeyValue.getValue(); // get the name
sourceFile = annoValue.getPosition().file();

if (annoKeyValue.getKey().getSimpleName().equals("Pre")) {
Object PreValue = annoValue.getValue(); // get the value
if (!(PreValue instanceof String)) {// controllo che sia una stringa
messager.printError(annoValue.getPosition(), "Insert a string condition: Condition(Pre=String)");
}
else {
cs.setPreCondition(annoValue.getValue());
}
}
else if (annoKeyValue.getKey().getSimpleName().equals("Post")) {
Object PostValue = annoValue.getValue(); // get the value
if (!(PostValue instanceof String)) {// controllo che sia una stringa
messager.printError(annoValue.getPosition(), "Insert a string condition: Condition(Post=String)");
}
else {
cs.setPostCondition(annoValue.getValue());
}
}
else {// errore nell'inserimento del campo
messager.printError(annoValue.getPosition(), "@Condition accepts only Pre() and Post() parameters");
}
}
}
csList.add(cs);
}
}