AnnotationField.java revision fead9ca09b117136b35bc5bf137340a754f9eddd
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 */
16package android.databinding.tool.reflection.annotation;
17
18import android.databinding.Bindable;
19import android.databinding.tool.reflection.ModelClass;
20import android.databinding.tool.reflection.ModelField;
21
22import javax.lang.model.element.Modifier;
23import javax.lang.model.element.TypeElement;
24import javax.lang.model.element.VariableElement;
25
26class AnnotationField extends ModelField {
27
28    final VariableElement mField;
29
30    final TypeElement mDeclaredClass;
31
32    public AnnotationField(TypeElement declaredClass, VariableElement field) {
33        mDeclaredClass = declaredClass;
34        mField = field;
35    }
36
37    @Override
38    public String toString() {
39        return mField.toString();
40    }
41
42    @Override
43    public boolean isBindable() {
44        return mField.getAnnotation(Bindable.class) != null;
45    }
46
47    @Override
48    public String getName() {
49        return mField.getSimpleName().toString();
50    }
51
52    @Override
53    public boolean isPublic() {
54        return mField.getModifiers().contains(Modifier.PUBLIC);
55    }
56
57    @Override
58    public boolean isStatic() {
59        return mField.getModifiers().contains(Modifier.STATIC);
60    }
61
62    @Override
63    public boolean isFinal() {
64        return mField.getModifiers().contains(Modifier.FINAL);
65    }
66
67    @Override
68    public ModelClass getFieldType() {
69        return new AnnotationClass(mField.asType());
70    }
71
72    @Override
73    public boolean equals(Object obj) {
74        if (obj instanceof AnnotationField) {
75            AnnotationField that = (AnnotationField) obj;
76            return mDeclaredClass.equals(that.mDeclaredClass) && AnnotationAnalyzer.get()
77                    .getTypeUtils().isSameType(mField.asType(), that.mField.asType());
78        } else {
79            return false;
80        }
81    }
82}
83