Debian Codegraph @

compiler/src/main/java/android/databinding/annotationprocessor/AnnotationUtil.java

raw
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 package android.databinding.annotationprocessor;
17
18 import java.lang.annotation.Annotation;
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import javax.annotation.processing.RoundEnvironment;
23 import javax.lang.model.element.Element;
24
25 class AnnotationUtil {
26
27 /**
28 * Returns only the elements that are annotated with the given class. For some reason
29 * RoundEnvironment is returning elements annotated by other annotations.
30 */
31 static List<Element> getElementsAnnotatedWith(RoundEnvironment roundEnv,
32 Class<? extends Annotation> annotationClass) {
33 ArrayList<Element> elements = new ArrayList<Element>();
34 for (Element element : roundEnv.getElementsAnnotatedWith(annotationClass)) {
35 if (element.getAnnotation(annotationClass) != null) {
36 elements.add(element);
37 }
38 }
39 return elements;
40 }
41 }