1/* 2 * Copyright (C) 2017 The Android Open Source Project 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 17package androidx.lifecycle.model 18 19import androidx.lifecycle.name 20import androidx.lifecycle.syntheticName 21import javax.lang.model.element.ExecutableElement 22import javax.lang.model.element.TypeElement 23 24data class InputModel( 25 // all java files with lifecycle annotations excluding classes from classpath 26 private val rootTypes: Set<TypeElement>, 27 // info about all lifecycle observers including classes from classpath 28 val observersInfo: Map<TypeElement, LifecycleObserverInfo>, 29 // info about generated adapters from class path 30 val generatedAdapters: Map<TypeElement, List<ExecutableElement>>) { 31 32 /** 33 * Root class is class defined in currently processed module, not in classpath 34 */ 35 fun isRootType(type: TypeElement) = type in rootTypes 36 37 fun hasSyntheticAccessorFor(eventMethod: EventMethod): Boolean { 38 val syntheticMethods = generatedAdapters[eventMethod.type] ?: return false 39 return syntheticMethods.any { executable -> 40 executable.name() == syntheticName(eventMethod.method) 41 // same number + receiver object 42 && (eventMethod.method.parameters.size + 1) == executable.parameters.size 43 } 44 } 45}