Annotation Interface OriginatingElement


public @interface OriginatingElement
An annotation used to specify the originating element that triggered the code generation of a type. This annotation should only be used on generated code and is meant to be used by code generators that generate Hilt modules, entry points, etc. Failure to use this annotation may mean improper test isolation for generated classes.

This annotation should be used on any generated top-level class that either contains generated modules (or entry points) or contains annotations that will generate modules (or entry points).

Example: Suppose we have the following use of an annotation, MyAnnotation.


   class Outer {
     static class Inner {
       @MyAnnotation Foo foo;
     }
   }
 

If MyAnnotation generates an entry point, it should be annotated as follows:


   @OriginatingElement(topLevelClass = Outer.class)
   @EntryPoint
   @InstallIn(SingletonComponent.class) {
       ...
   }
 
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Returns the top-level class enclosing the originating element.
  • Element Details

    • topLevelClass

      Class<?> topLevelClass
      Returns the top-level class enclosing the originating element.