1 /*
2  * Copyright (C) 2018 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.spi;
18 
19 import com.google.errorprone.annotations.FormatMethod;
20 import dagger.model.BindingGraph;
21 import dagger.model.BindingGraph.ChildFactoryMethodEdge;
22 import dagger.model.BindingGraph.ComponentNode;
23 import dagger.model.BindingGraph.DependencyEdge;
24 import dagger.model.BindingGraph.MaybeBinding;
25 import javax.tools.Diagnostic;
26 
27 /**
28  * An object that {@link BindingGraphPlugin}s can use to report diagnostics while visiting a {@link
29  * BindingGraph}.
30  *
31  * <p>Note: This API is still experimental and will change.
32  */
33 public interface DiagnosticReporter {
34   /**
35    * Reports a diagnostic for a component. For non-root components, includes information about the
36    * path from the root component.
37    */
reportComponent(Diagnostic.Kind diagnosticKind, ComponentNode componentNode, String message)38   void reportComponent(Diagnostic.Kind diagnosticKind, ComponentNode componentNode, String message);
39 
40   /**
41    * Reports a diagnostic for a component. For non-root components, includes information about the
42    * path from the root component.
43    */
44   @FormatMethod
reportComponent( Diagnostic.Kind diagnosticKind, ComponentNode componentNode, String messageFormat, Object firstArg, Object... moreArgs)45   void reportComponent(
46       Diagnostic.Kind diagnosticKind,
47       ComponentNode componentNode,
48       String messageFormat,
49       Object firstArg,
50       Object... moreArgs);
51 
52   /**
53    * Reports a diagnostic for a binding or missing binding. Includes information about how the
54    * binding is reachable from entry points.
55    */
reportBinding(Diagnostic.Kind diagnosticKind, MaybeBinding binding, String message)56   void reportBinding(Diagnostic.Kind diagnosticKind, MaybeBinding binding, String message);
57 
58   /**
59    * Reports a diagnostic for a binding or missing binding. Includes information about how the
60    * binding is reachable from entry points.
61    */
62   @FormatMethod
reportBinding( Diagnostic.Kind diagnosticKind, MaybeBinding binding, String messageFormat, Object firstArg, Object... moreArgs)63   void reportBinding(
64       Diagnostic.Kind diagnosticKind,
65       MaybeBinding binding,
66       String messageFormat,
67       Object firstArg,
68       Object... moreArgs);
69 
70   /**
71    * Reports a diagnostic for a dependency. Includes information about how the dependency is
72    * reachable from entry points.
73    */
reportDependency( Diagnostic.Kind diagnosticKind, DependencyEdge dependencyEdge, String message)74   void reportDependency(
75       Diagnostic.Kind diagnosticKind, DependencyEdge dependencyEdge, String message);
76 
77   /**
78    * Reports a diagnostic for a dependency. Includes information about how the dependency is
79    * reachable from entry points.
80    */
81   @FormatMethod
reportDependency( Diagnostic.Kind diagnosticKind, DependencyEdge dependencyEdge, String messageFormat, Object firstArg, Object... moreArgs)82   void reportDependency(
83       Diagnostic.Kind diagnosticKind,
84       DependencyEdge dependencyEdge,
85       String messageFormat,
86       Object firstArg,
87       Object... moreArgs);
88 
89   /** Reports a diagnostic for a subcomponent factory method. */
reportSubcomponentFactoryMethod( Diagnostic.Kind diagnosticKind, ChildFactoryMethodEdge childFactoryMethodEdge, String message)90   void reportSubcomponentFactoryMethod(
91       Diagnostic.Kind diagnosticKind,
92       ChildFactoryMethodEdge childFactoryMethodEdge,
93       String message);
94 
95   /** Reports a diagnostic for a subcomponent factory method. */
96   @FormatMethod
reportSubcomponentFactoryMethod( Diagnostic.Kind diagnosticKind, ChildFactoryMethodEdge childFactoryMethodEdge, String messageFormat, Object firstArg, Object... moreArgs)97   void reportSubcomponentFactoryMethod(
98       Diagnostic.Kind diagnosticKind,
99       ChildFactoryMethodEdge childFactoryMethodEdge,
100       String messageFormat,
101       Object firstArg,
102       Object... moreArgs);
103 }
104