1fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount/* 2fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount * Copyright (C) 2015 The Android Open Source Project 3fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount * 4fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount * Licensed under the Apache License, Version 2.0 (the "License"); 5fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount * you may not use this file except in compliance with the License. 6fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount * You may obtain a copy of the License at 7fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount * 8fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount * http://www.apache.org/licenses/LICENSE-2.0 9fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount * 10fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount * Unless required by applicable law or agreed to in writing, software 11fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount * distributed under the License is distributed on an "AS IS" BASIS, 12fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount * See the License for the specific language governing permissions and 14fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount * limitations under the License. 15fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount */ 16fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mountpackage android.databinding.annotationprocessor; 17fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount 18fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mountimport java.lang.annotation.Annotation; 19fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mountimport java.util.ArrayList; 20fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mountimport java.util.List; 21fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount 22fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mountimport javax.annotation.processing.RoundEnvironment; 23fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mountimport javax.lang.model.element.Element; 24fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount 25fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mountclass AnnotationUtil { 26fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount 27fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount /** 28fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount * Returns only the elements that are annotated with the given class. For some reason 29fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount * RoundEnvironment is returning elements annotated by other annotations. 30fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount */ 31fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount static List<Element> getElementsAnnotatedWith(RoundEnvironment roundEnv, 32fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount Class<? extends Annotation> annotationClass) { 33b1356339eaa6c8e967e4fc1dc283b82909a1208dYigit Boyar ArrayList<Element> elements = new ArrayList<Element>(); 34fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount for (Element element : roundEnv.getElementsAnnotatedWith(annotationClass)) { 35fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount if (element.getAnnotation(annotationClass) != null) { 36fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount elements.add(element); 37fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount } 38fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount } 39fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount return elements; 40fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount } 41fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mount} 42