1 /* 2 * Copyright (C) 2014 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.binding; 18 19 import static dagger.internal.codegen.extension.DaggerStreams.toImmutableList; 20 import static dagger.internal.codegen.xprocessing.XElements.getSimpleName; 21 22 import androidx.room.compiler.processing.XMethodType; 23 import androidx.room.compiler.processing.XProcessingEnv; 24 import androidx.room.compiler.processing.XType; 25 import com.google.auto.value.AutoValue; 26 import com.google.common.collect.ImmutableList; 27 import com.squareup.javapoet.TypeName; 28 import dagger.internal.codegen.binding.ComponentDescriptor.ComponentMethodDescriptor; 29 30 /** A class that defines proper {@code equals} and {@code hashcode} for a method signature. */ 31 @AutoValue 32 public abstract class MethodSignature { 33 name()34 abstract String name(); 35 parameterTypes()36 abstract ImmutableList<TypeName> parameterTypes(); 37 thrownTypes()38 abstract ImmutableList<TypeName> thrownTypes(); 39 forComponentMethod( ComponentMethodDescriptor componentMethod, XType componentType, XProcessingEnv processingEnv)40 public static MethodSignature forComponentMethod( 41 ComponentMethodDescriptor componentMethod, 42 XType componentType, 43 XProcessingEnv processingEnv) { 44 XMethodType methodType = componentMethod.methodElement().asMemberOf(componentType); 45 return new AutoValue_MethodSignature( 46 getSimpleName(componentMethod.methodElement()), 47 methodType.getParameterTypes().stream().map(XType::getTypeName).collect(toImmutableList()), 48 // Using the thrown types of the method element, which should be the same as the method type 49 // since thrown types can't use type variables. 50 // TODO(bcorso): Support getting thrown types from XExecutableType in XProcessing. 51 componentMethod.methodElement().getThrownTypes().stream() 52 .map(XType::getTypeName) 53 .collect(toImmutableList())); 54 } 55 } 56