xref: /aosp_15_r20/external/dagger2/java/dagger/spi/model/BindingGraphPlugin.java (revision f585d8a307d0621d6060bd7e80091fdcbf94fe27)
1 /*
2  * Copyright (C) 2021 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.model;
18 
19 import java.util.Collections;
20 import java.util.Map;
21 import java.util.Set;
22 
23 // TODO(bcorso): Move this into dagger/spi?
24 /**
25  * A pluggable visitor for {@link BindingGraph}.
26  *
27  * <p>Note: This is still experimental and will change.
28  */
29 public interface BindingGraphPlugin {
30   /**
31    * Called once for each valid root binding graph encountered by the Dagger processor. May report
32    * diagnostics using {@code diagnosticReporter}.
33    */
visitGraph(BindingGraph bindingGraph, DiagnosticReporter diagnosticReporter)34   void visitGraph(BindingGraph bindingGraph, DiagnosticReporter diagnosticReporter);
35 
36   /**
37    * Initializes this plugin with a {@link DaggerProcessingEnv}.
38    *
39    * <p>This will be called once per instance of this plugin, before any graph is
40    * {@linkplain #visitGraph(BindingGraph, DiagnosticReporter) visited}.
41    */
init(DaggerProcessingEnv processingEnv, Map<String, String> options)42   default void init(DaggerProcessingEnv processingEnv, Map<String, String> options) {}
43 
44   /**
45    * Returns the annotation-processing options that this plugin uses to configure behavior.
46    *
47    * @see javax.annotation.processing.Processor#getSupportedOptions()
48    */
supportedOptions()49   default Set<String> supportedOptions() {
50     return Collections.emptySet();
51   }
52 
53   /**
54    * A distinguishing name of the plugin that will be used in diagnostics printed to the messager.
55    * By default, the {@linkplain Class#getCanonicalName() fully qualified name} of the plugin is
56    * used.
57    */
pluginName()58   default String pluginName() {
59     return getClass().getCanonicalName();
60   }
61 
62   /**
63    * Perform any extra work after the plugin finished all its visiting. This will be called once per
64    * instance of this plugin, after all graphs were {@linkplain #visitGraph(BindingGraph,
65    * DiagnosticReporter) visited}
66    */
onPluginEnd()67   default void onPluginEnd() {}
68 }
69