1 /* 2 * Copyright (C) 2016 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 17 package androidx.room.processor 18 19 import androidx.room.vo.QueryParameter 20 import com.google.auto.common.MoreTypes 21 import javax.lang.model.element.VariableElement 22 import javax.lang.model.type.DeclaredType 23 24 class QueryParameterProcessor( 25 baseContext: Context, 26 val containing: DeclaredType, 27 val element: VariableElement, 28 private val sqlName: String? = null) { 29 val context = baseContext.fork(element) 30 fun process(): QueryParameter { 31 val asMember = MoreTypes.asMemberOf(context.processingEnv.typeUtils, containing, element) 32 val parameterAdapter = context.typeAdapterStore.findQueryParameterAdapter(asMember) 33 context.checker.check(parameterAdapter != null, element, 34 ProcessorErrors.CANNOT_BIND_QUERY_PARAMETER_INTO_STMT) 35 36 val name = element.simpleName.toString() 37 context.checker.check(!name.startsWith("_"), element, 38 ProcessorErrors.QUERY_PARAMETERS_CANNOT_START_WITH_UNDERSCORE) 39 return QueryParameter( 40 name = name, 41 sqlName = sqlName ?: name, 42 type = asMember, 43 queryParamAdapter = parameterAdapter) 44 } 45 } 46