Tests if the specified package, program element or constructor/method's parameter has an annotation of the specified type.

Parameters:

element

The PackageDoc, ProgramElementDoc or Parameter element whose annotation is requested.

It may be also a Type element, which is automatically converted to the ClassDoc by calling the Doclet API method: Type.asClassDoc()

If the element is not an instance of one of those types, the function returns false.

If this parameter is not specified, the generator context element is assumed, i.e. the same as the call: contextElement.hasAnnotation(qualifiedName)

qualifiedName
The fully qualified name of the annotation type to search for.
qualifiedNames
Instead of a single name, you may specify several fully qualified names in the form of an array (e.g. created with Array() function). For example:
hasAnnotation (
  Array (
    "project.util.Annotation1", 
    "project.util.Annotation2"
  )
)
In that case, the function will search for an annotation with the first type name specified in the array, then, if not found, for an annotation with the second type name and so on.
Returns:
true, if the specified element has an annotation of the specified type; false, otherwise.

Example:

Let's suppose we have a method in our Java sources specified like this:


@Deprecated
void myMethod() { ... }
Then, the following call will tests if the methos has the @Deprecated annotation:
findAnnotation("java.lang.Deprecated")
(provided that the method is currently the generator context element).

Note that the same result can be achieved with the following expression:


hasChild("AnnotationDesc", BooleanQuery(
  checkValueByLPath(
    "annotationType^::AnnotationTypeDoc/@qualifiedName", 
    "java.lang.Deprecated"
  )
))
That expression uses a much more universal approach based on Location Path (which is a variation of XML XPath). However, specifying it is more cumbersome and this will work slower.

Since checking Java annotations may be a rather frequent operation in templates, it was implemented a separate function.

See Also:

findAnnotation(), getAnnotation()