1 /* 2 * Copyright (C) 2016 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.internal.codegen.processingstep; 18 19 import static com.google.common.base.Preconditions.checkArgument; 20 21 import androidx.room.compiler.processing.XMessager; 22 import androidx.room.compiler.processing.XMethodElement; 23 import com.google.common.collect.ImmutableSet; 24 import com.squareup.javapoet.ClassName; 25 import dagger.internal.codegen.validation.AnyBindingMethodValidator; 26 import javax.inject.Inject; 27 28 /** A step that validates all binding methods that were not validated while processing modules. */ 29 final class BindingMethodProcessingStep extends TypeCheckingProcessingStep<XMethodElement> { 30 31 private final XMessager messager; 32 private final AnyBindingMethodValidator anyBindingMethodValidator; 33 34 @Inject BindingMethodProcessingStep( XMessager messager, AnyBindingMethodValidator anyBindingMethodValidator)35 BindingMethodProcessingStep( 36 XMessager messager, AnyBindingMethodValidator anyBindingMethodValidator) { 37 this.messager = messager; 38 this.anyBindingMethodValidator = anyBindingMethodValidator; 39 } 40 41 @Override annotationClassNames()42 public ImmutableSet<ClassName> annotationClassNames() { 43 return anyBindingMethodValidator.methodAnnotations(); 44 } 45 46 @Override process(XMethodElement method, ImmutableSet<ClassName> annotations)47 protected void process(XMethodElement method, ImmutableSet<ClassName> annotations) { 48 checkArgument( 49 anyBindingMethodValidator.isBindingMethod(method), 50 "%s is not annotated with any of %s", 51 method, 52 annotations()); 53 if (!anyBindingMethodValidator.wasAlreadyValidated(method)) { 54 anyBindingMethodValidator.validate(method).printMessagesTo(messager); 55 } 56 } 57 } 58