1 package java.lang.reflect.code.type; 2 3 import java.lang.reflect.code.TypeElement; 4 5 /** 6 * A type element factory for construction a {@link TypeElement} from its 7 * {@link TypeElement.ExternalizedTypeElement external content}. 8 */ 9 @FunctionalInterface 10 public interface TypeElementFactory { 11 12 /** 13 * Constructs a {@link TypeElement} from its 14 * {@link TypeElement.ExternalizedTypeElement external content}. 15 * <p> 16 * If there is no mapping from the external content to a type 17 * element then this method returns {@code null}. 18 * 19 * @param tree the externalized type element. 20 * @return the type element. 21 */ 22 TypeElement constructType(TypeElement.ExternalizedTypeElement tree); 23 24 /** 25 * Compose this type element factory with another type element factory. 26 * <p> 27 * If there is no mapping in this type element factory then the result 28 * of the other type element factory is returned. 29 * 30 * @param after the other type element factory. 31 * @return the composed type element factory. 32 */ 33 default TypeElementFactory andThen(TypeElementFactory after) { 34 return t -> { 35 TypeElement te = constructType(t); 36 return te != null ? te : after.constructType(t); 37 }; 38 } 39 }