1*f585d8a3SJacky Wang /* 2*f585d8a3SJacky Wang * Copyright (C) 2021 The Dagger Authors. 3*f585d8a3SJacky Wang * 4*f585d8a3SJacky Wang * Licensed under the Apache License, Version 2.0 (the "License"); 5*f585d8a3SJacky Wang * you may not use this file except in compliance with the License. 6*f585d8a3SJacky Wang * You may obtain a copy of the License at 7*f585d8a3SJacky Wang * 8*f585d8a3SJacky Wang * http://www.apache.org/licenses/LICENSE-2.0 9*f585d8a3SJacky Wang * 10*f585d8a3SJacky Wang * Unless required by applicable law or agreed to in writing, software 11*f585d8a3SJacky Wang * distributed under the License is distributed on an "AS IS" BASIS, 12*f585d8a3SJacky Wang * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*f585d8a3SJacky Wang * See the License for the specific language governing permissions and 14*f585d8a3SJacky Wang * limitations under the License. 15*f585d8a3SJacky Wang */ 16*f585d8a3SJacky Wang 17*f585d8a3SJacky Wang package dagger.spi.model; 18*f585d8a3SJacky Wang 19*f585d8a3SJacky Wang import java.util.Collections; 20*f585d8a3SJacky Wang import java.util.Map; 21*f585d8a3SJacky Wang import java.util.Set; 22*f585d8a3SJacky Wang 23*f585d8a3SJacky Wang // TODO(bcorso): Move this into dagger/spi? 24*f585d8a3SJacky Wang /** 25*f585d8a3SJacky Wang * A pluggable visitor for {@link BindingGraph}. 26*f585d8a3SJacky Wang * 27*f585d8a3SJacky Wang * <p>Note: This is still experimental and will change. 28*f585d8a3SJacky Wang */ 29*f585d8a3SJacky Wang public interface BindingGraphPlugin { 30*f585d8a3SJacky Wang /** 31*f585d8a3SJacky Wang * Called once for each valid root binding graph encountered by the Dagger processor. May report 32*f585d8a3SJacky Wang * diagnostics using {@code diagnosticReporter}. 33*f585d8a3SJacky Wang */ visitGraph(BindingGraph bindingGraph, DiagnosticReporter diagnosticReporter)34*f585d8a3SJacky Wang void visitGraph(BindingGraph bindingGraph, DiagnosticReporter diagnosticReporter); 35*f585d8a3SJacky Wang 36*f585d8a3SJacky Wang /** 37*f585d8a3SJacky Wang * Initializes this plugin with a {@link DaggerProcessingEnv}. 38*f585d8a3SJacky Wang * 39*f585d8a3SJacky Wang * <p>This will be called once per instance of this plugin, before any graph is 40*f585d8a3SJacky Wang * {@linkplain #visitGraph(BindingGraph, DiagnosticReporter) visited}. 41*f585d8a3SJacky Wang */ init(DaggerProcessingEnv processingEnv, Map<String, String> options)42*f585d8a3SJacky Wang default void init(DaggerProcessingEnv processingEnv, Map<String, String> options) {} 43*f585d8a3SJacky Wang 44*f585d8a3SJacky Wang /** 45*f585d8a3SJacky Wang * Returns the annotation-processing options that this plugin uses to configure behavior. 46*f585d8a3SJacky Wang * 47*f585d8a3SJacky Wang * @see javax.annotation.processing.Processor#getSupportedOptions() 48*f585d8a3SJacky Wang */ supportedOptions()49*f585d8a3SJacky Wang default Set<String> supportedOptions() { 50*f585d8a3SJacky Wang return Collections.emptySet(); 51*f585d8a3SJacky Wang } 52*f585d8a3SJacky Wang 53*f585d8a3SJacky Wang /** 54*f585d8a3SJacky Wang * A distinguishing name of the plugin that will be used in diagnostics printed to the messager. 55*f585d8a3SJacky Wang * By default, the {@linkplain Class#getCanonicalName() fully qualified name} of the plugin is 56*f585d8a3SJacky Wang * used. 57*f585d8a3SJacky Wang */ pluginName()58*f585d8a3SJacky Wang default String pluginName() { 59*f585d8a3SJacky Wang return getClass().getCanonicalName(); 60*f585d8a3SJacky Wang } 61*f585d8a3SJacky Wang 62*f585d8a3SJacky Wang /** 63*f585d8a3SJacky Wang * Perform any extra work after the plugin finished all its visiting. This will be called once per 64*f585d8a3SJacky Wang * instance of this plugin, after all graphs were {@linkplain #visitGraph(BindingGraph, 65*f585d8a3SJacky Wang * DiagnosticReporter) visited} 66*f585d8a3SJacky Wang */ onPluginEnd()67*f585d8a3SJacky Wang default void onPluginEnd() {} 68*f585d8a3SJacky Wang } 69