InstanceOfExpr.java revision 2611838bffef5a009ca71e3e9e59a93f29b098ed
1/* 2 * Copyright (C) 2015 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 android.databinding.tool.expr; 18 19import android.databinding.tool.reflection.ModelAnalyzer; 20import android.databinding.tool.reflection.ModelClass; 21 22import java.util.List; 23 24public class InstanceOfExpr extends Expr { 25 final String mTypeStr; 26 ModelClass mType; 27 28 InstanceOfExpr(Expr left, String type) { 29 super(left); 30 mTypeStr = type; 31 } 32 33 @Override 34 protected String computeUniqueKey() { 35 return join("instanceof", super.computeUniqueKey(), mTypeStr); 36 } 37 38 @Override 39 protected ModelClass resolveType(ModelAnalyzer modelAnalyzer) { 40 mType = modelAnalyzer.findClass(mTypeStr, getModel().getImports()); 41 return modelAnalyzer.loadPrimitive("boolean"); 42 } 43 44 @Override 45 protected List<Dependency> constructDependencies() { 46 return constructDynamicChildrenDependencies(); 47 } 48 49 public Expr getExpr() { 50 return getChildren().get(0); 51 } 52 53 public ModelClass getType() { 54 return mType; 55 } 56} 57