1 /* 2 * Copyright (C) 2016 The Dagger Authors. 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 17 package dagger.internal.codegen.base; 18 19 import com.google.auto.common.AnnotationMirrors; 20 import com.google.common.base.Equivalence; 21 import java.util.Optional; 22 import javax.lang.model.element.AnnotationMirror; 23 24 /** 25 * A utility class for working with {@link AnnotationMirror} instances, similar to {@link 26 * AnnotationMirrors}. 27 */ 28 public final class MoreAnnotationMirrors { MoreAnnotationMirrors()29 private MoreAnnotationMirrors() {} 30 31 /** 32 * Wraps an {@link Optional} of a type in an {@code Optional} of a {@link Equivalence.Wrapper} for 33 * that type. 34 */ wrapOptionalInEquivalence( Optional<AnnotationMirror> optional)35 public static Optional<Equivalence.Wrapper<AnnotationMirror>> wrapOptionalInEquivalence( 36 Optional<AnnotationMirror> optional) { 37 return optional.map(AnnotationMirrors.equivalence()::wrap); 38 } 39 40 /** 41 * Unwraps an {@link Optional} of a {@link Equivalence.Wrapper} into an {@code Optional} of the 42 * underlying type. 43 */ unwrapOptionalEquivalence( Optional<Equivalence.Wrapper<AnnotationMirror>> wrappedOptional)44 public static Optional<AnnotationMirror> unwrapOptionalEquivalence( 45 Optional<Equivalence.Wrapper<AnnotationMirror>> wrappedOptional) { 46 return wrappedOptional.map(Equivalence.Wrapper::get); 47 } 48 } 49