javaxdoclet

XDoclet - check annotation from other class


I'm using XDoclet to generate code:

/**
 * @diff.special
 */
public String myString;

Now I'd like to generate code depending on this annotation AND an annotation in an other class, i.e.

if annotation in class 1 = diff.special ===> decide what to do according to annotation in class 2 if annotation in class 1 = diff.normal ===> decide what to do according to annotation in class 3

How can I achieve that in my handler? When my ant task runs and is working on annotation in class 1, how can I get the annotations of class 2 or 3?

Thanks a LOT,

Haemi


Solution

  • Don't know if it's the best way to do, but I solved it the following way:

      final XJavaDoc xJavaDoc = XDocletTagSupport.getXJavaDoc();
      final XClass xClass = xJavaDoc.getXClass(clazz.getCanonicalName());
    
      // iterate over all fields in the angebot class and...
      for (Object field : xClass.getFields(true)) {
        final XField xfield = (XField) field;
        // ... check if it contains the corresponding field, ...
        if (xfield.getName().contains(fieldNameToLookFor)) {
          return xfield;
        }
      }