This discussion is archived
2 Replies Latest reply: Aug 6, 2009 7:59 AM by 843793 RSS

build-time access to declarations and annotations

843793 Newbie
Currently Being Moderated
This is a couple of yes/no questions to confirm that I got it right. I'm in the context of build-time annotation processing where the AnnotationProcessor analyses each specified annotated class as well as their ancestors.

Let's assume barClassType is a com.sun.mirror.type.ClassType instance representing the type named foo.Bar.
Would barClassType.getDeclaration() return a non-null ClassDeclaration instance,
even though: foo.Bar was not specified when the annotation processing tool was invoked,
provided that: foo.Bar can be found somewhere in the class path?

If so, let's assume barDeclaration was assigned to the said return value and Qux is an annotation type.
Would barDeclaration.getAnnotation(Qux.class) return a non-null Annotation instance,
provided that: the Qux retention policy was set to either Retention.CLASS or Retention.RUNTIME?
  • 1. Re: build-time access to declarations and annotations
    843793 Newbie
    Currently Being Moderated
    Robert.Bossy wrote:
    This is a couple of yes/no questions to confirm that I got it right. I'm in the context of build-time annotation processing where the AnnotationProcessor analyses each specified annotated class as well as their ancestors.

    Let's assume barClassType is a com.sun.mirror.type.ClassType instance representing the type named foo.Bar.
    Would barClassType.getDeclaration() return a non-null ClassDeclaration instance,
    even though: foo.Bar was not specified when the annotation processing tool was invoked,
    provided that: foo.Bar can be found somewhere in the class path?
    Yes.
    If so, let's assume barDeclaration was assigned to the said return value and Qux is an annotation type.
    Would barDeclaration.getAnnotation(Qux.class) return a non-null Annotation instance,
    provided that: the Qux retention policy was set to either Retention.CLASS or Retention.RUNTIME?
    If the Bar type declaration included the Qux annotation (either directly or by annotation inheritance), yes.
  • 2. Re: build-time access to declarations and annotations
    843793 Newbie
    Currently Being Moderated
    j.d.darcy wrote:
    Robert.Bossy wrote:
    This is a couple of yes/no questions to confirm that I got it right. I'm in the context of build-time annotation processing where the AnnotationProcessor analyses each specified annotated class as well as their ancestors.

    Let's assume barClassType is a com.sun.mirror.type.ClassType instance representing the type named foo.Bar.
    Would barClassType.getDeclaration() return a non-null ClassDeclaration instance,
    even though: foo.Bar was not specified when the annotation processing tool was invoked,
    provided that: foo.Bar can be found somewhere in the class path?
    Yes.
    If so, let's assume barDeclaration was assigned to the said return value and Qux is an annotation type.
    Would barDeclaration.getAnnotation(Qux.class) return a non-null Annotation instance,
    provided that: the Qux retention policy was set to either Retention.CLASS or Retention.RUNTIME?
    If the Bar type declaration included the Qux annotation (either directly or by annotation inheritance), yes.
    Yeah, that was implicit. Thanks a lot.