1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * http://www.apache.org/licenses/LICENSE-2.0 7 * Unless required by applicable law or agreed to in writing, software 8 * distributed under the License is distributed on an "AS IS" BASIS, 9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 * See the License for the specific language governing permissions and 11 * limitations under the License. 12 */ 13 14 package android.databinding.tool.reflection.java; 15 16 17 import android.databinding.Bindable; 18 import android.databinding.tool.reflection.ModelClass; 19 import android.databinding.tool.reflection.ModelMethod; 20 import android.databinding.tool.reflection.SdkUtil; 21 import android.databinding.tool.reflection.TypeUtil; 22 23 import java.lang.reflect.Method; 24 import java.lang.reflect.Modifier; 25 import java.util.List; 26 27 public class JavaMethod extends ModelMethod { 28 public final Method mMethod; 29 30 public JavaMethod(Method method) { 31 mMethod = method; 32 } 33 34 35 @Override 36 public ModelClass getDeclaringClass() { 37 return new JavaClass(mMethod.getDeclaringClass()); 38 } 39 40 @Override 41 public ModelClass[] getParameterTypes() { 42 Class[] parameterTypes = mMethod.getParameterTypes(); 43 ModelClass[] parameterClasses = new ModelClass[parameterTypes.length]; 44 for (int i = 0; i < parameterTypes.length; i++) { 45 parameterClasses[i] = new JavaClass(parameterTypes[i]); 46 } 47 return parameterClasses; 48 } 49 50 @Override 51 public String getName() { 52 return mMethod.getName(); 53 } 54 55 @Override 56 public ModelClass getReturnType(List<ModelClass> args) { 57 return new JavaClass(mMethod.getReturnType()); 58 } 59 60 @Override 61 public boolean isVoid() { 62 return void.class.equals(mMethod.getReturnType()); 63 } 64 65 @Override 66 public boolean isPublic() { 67 return Modifier.isPublic(mMethod.getModifiers()); 68 } 69 70 @Override 71 public boolean isStatic() { 72 return Modifier.isStatic(mMethod.getModifiers()); 73 } 74 75 @Override 76 public boolean isAbstract() { 77 return Modifier.isAbstract(mMethod.getModifiers()); 78 } 79 80 @Override 81 public boolean isBindable() { 82 return mMethod.getAnnotation(Bindable.class) != null; 83 } 84 85 @Override 86 public int getMinApi() { 87 return SdkUtil.getMinApi(this); 88 } 89 90 @Override 91 public String getJniDescription() { 92 return TypeUtil.getInstance().getDescription(this); 93 } 94 95 @Override 96 public boolean isVarArgs() { 97 return false; 98 } 99 } 100