• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 The Dagger Authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package dagger.hilt.codegen;
18 
19 /**
20  * An annotation used to specify the originating element that triggered the code generation of a
21  * type. This annotation should only be used on generated code and is meant to be used by code
22  * generators that generate Hilt modules, entry points, etc. Failure to use this annotation may mean
23  * improper test isolation for generated classes.
24  *
25  * <p>This annotation should be used on any generated top-level class that either contains generated
26  * modules (or entry points) or contains annotations that will generate modules (or entry points).
27  *
28  * <p>Example: Suppose we have the following use of an annotation, {@code MyAnnotation}.
29  *
30  * <pre><code>
31  *   class Outer {
32  *     static class Inner {
33  *       {@literal @}MyAnnotation Foo foo;
34  *     }
35  *   }
36  * </code></pre>
37  *
38  * <p>If {@code MyAnnotation} generates an entry point, it should be annotated as follows:
39  *
40  * <pre><code>
41  *   {@literal @}OriginatingElement(topLevelClass = Outer.class)
42  *   {@literal @}EntryPoint
43  *   {@literal @}InstallIn(SingletonComponent.class) {
44  *       ...
45  *   }
46  * </code></pre>
47  */
48 // TODO(bcorso): Consider just advising/enforcing that all top-level classes use this annotation.
49 public @interface OriginatingElement {
50   /** Returns the top-level class enclosing the originating element. */
topLevelClass()51   Class<?> topLevelClass();
52 }
53