1 package annotations; 2 3 /*>>> 4 import org.checkerframework.checker.nullness.qual.*; 5 */ 6 7 import java.util.Map; 8 import java.util.Set; 9 10 import annotations.el.AnnotationDef; 11 12 /** 13 * A very simple {@link annotations.AnnotationFactory AnnotationFactory} that 14 * creates {@link Annotation}s. It is interested in all annotations and 15 * determines their definitions automatically from the fields supplied. Use the 16 * singleton {@link #saf}. 17 */ 18 public final class AnnotationFactory { AnnotationFactory()19 private AnnotationFactory() { 20 } 21 22 /** 23 * The singleton {@link AnnotationFactory}. 24 */ 25 public static final AnnotationFactory saf = new AnnotationFactory(); 26 27 /** 28 * Returns an {@link AnnotationBuilder} appropriate for building a 29 * {@link Annotation} of the given type name. 30 */ beginAnnotation(AnnotationDef def)31 public AnnotationBuilder beginAnnotation(AnnotationDef def) { 32 return new AnnotationBuilder(def); 33 } 34 35 /** 36 * Returns an {@link AnnotationBuilder}. 37 * Tries to look up the AnnotationDef in adefs; if not found, inserts in adefs. 38 */ beginAnnotation(java.lang.annotation.Annotation a, Map<String, AnnotationDef> adefs)39 public AnnotationBuilder beginAnnotation(java.lang.annotation.Annotation a, Map<String, AnnotationDef> adefs) { 40 AnnotationDef def = AnnotationDef.fromClass(a.getClass(), adefs); 41 return new AnnotationBuilder(def); 42 } 43 44 /** 45 * Returns an {@link AnnotationBuilder} appropriate for building a 46 * {@link Annotation} of the given type name. 47 */ beginAnnotation(String typeName, Set<Annotation> tlAnnotationsHere)48 public AnnotationBuilder beginAnnotation(String typeName, Set<Annotation> tlAnnotationsHere) { 49 assert typeName != null; 50 return new AnnotationBuilder(typeName, tlAnnotationsHere); 51 } 52 } 53