JavaMethod.java revision fead9ca09b117136b35bc5bf137340a754f9eddd
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
14package android.databinding.tool.reflection.java;
15
16
17import android.databinding.Bindable;
18import android.databinding.tool.reflection.ModelClass;
19import android.databinding.tool.reflection.ModelMethod;
20import android.databinding.tool.reflection.SdkUtil;
21import android.databinding.tool.reflection.TypeUtil;
22
23import java.lang.reflect.Method;
24import java.lang.reflect.Modifier;
25import java.util.List;
26
27public 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 isBindable() {
77        return mMethod.getAnnotation(Bindable.class) != null;
78    }
79
80    @Override
81    public int getMinApi() {
82        return SdkUtil.getMinApi(this);
83    }
84
85    @Override
86    public String getJniDescription() {
87        return TypeUtil.getInstance().getDescription(this);
88    }
89
90    @Override
91    public boolean isVarArgs() {
92        return false;
93    }
94}
95