1 /* 2 * Copyright 2014 Google LLC 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 com.google.auto.value.processor; 17 18 import java.util.List; 19 import java.util.Optional; 20 import javax.lang.model.element.AnnotationMirror; 21 import javax.lang.model.element.Name; 22 import javax.lang.model.element.TypeElement; 23 24 class GwtCompatibility { 25 private final Optional<AnnotationMirror> gwtCompatibleAnnotation; 26 GwtCompatibility(TypeElement type)27 GwtCompatibility(TypeElement type) { 28 Optional<AnnotationMirror> gwtCompatibleAnnotation = Optional.empty(); 29 List<? extends AnnotationMirror> annotations = type.getAnnotationMirrors(); 30 for (AnnotationMirror annotation : annotations) { 31 Name name = annotation.getAnnotationType().asElement().getSimpleName(); 32 if (name.contentEquals("GwtCompatible")) { 33 gwtCompatibleAnnotation = Optional.of(annotation); 34 } 35 } 36 this.gwtCompatibleAnnotation = gwtCompatibleAnnotation; 37 } 38 gwtCompatibleAnnotation()39 Optional<AnnotationMirror> gwtCompatibleAnnotation() { 40 return gwtCompatibleAnnotation; 41 } 42 gwtCompatibleAnnotationString()43 String gwtCompatibleAnnotationString() { 44 return gwtCompatibleAnnotation.map(AnnotationOutput::sourceFormForAnnotation).orElse(""); 45 } 46 } 47