@@ -32,11 +32,12 @@ public class RoundContext {
3232 private final ProcessingContext processingContext ;
3333 private final RoundEnvironment roundEnvironment ;
3434 private final Set <? extends TypeElement > annotationElements ;
35- private final Annotations annotations ;
36- private final Declarations declarations ;
37- private final CtTypes ctTypes ;
38- private final Names names ;
3935 private final List <ExternalDomainMeta > externalDomainMetaList = new ArrayList <>();
36+ private boolean initialized ;
37+ private Annotations annotations ;
38+ private Declarations declarations ;
39+ private CtTypes ctTypes ;
40+ private Names names ;
4041
4142 public RoundContext (
4243 ProcessingContext processingContext ,
@@ -45,62 +46,87 @@ public RoundContext(
4546 this .processingContext = Objects .requireNonNull (processingContext );
4647 this .roundEnvironment = Objects .requireNonNull (roundEnvironment );
4748 this .annotationElements = Objects .requireNonNull (annotationElements );
48- this .annotations = new Annotations (this );
49- this .declarations = new Declarations (this );
50- this .ctTypes = new CtTypes (this );
51- this .names = new Names (this );
49+ }
50+
51+ public void init () {
52+ if (initialized ) {
53+ throw new AptIllegalStateException ("already initialized" );
54+ }
55+ annotations = new Annotations (this );
56+ declarations = new Declarations (this );
57+ ctTypes = new CtTypes (this );
58+ names = new Names (this );
59+ initialized = true ;
5260 }
5361
5462 public RoundEnvironment getRoundEnvironment () {
63+ assertInitialized ();
5564 return roundEnvironment ;
5665 }
5766
5867 public MoreElements getMoreElements () {
68+ assertInitialized ();
5969 return processingContext .getMoreElements ();
6070 }
6171
6272 public MoreTypes getMoreTypes () {
73+ assertInitialized ();
6374 return processingContext .getMoreTypes ();
6475 }
6576
6677 public Options getOptions () {
78+ assertInitialized ();
6779 return processingContext .getOptions ();
6880 }
6981
7082 public Reporter getReporter () {
83+ assertInitialized ();
7184 return processingContext .getReporter ();
7285 }
7386
7487 public Resources getResources () {
88+ assertInitialized ();
7589 return processingContext .getResources ();
7690 }
7791
7892 public Annotations getAnnotations () {
93+ assertInitialized ();
7994 return annotations ;
8095 }
8196
8297 public Declarations getDeclarations () {
98+ assertInitialized ();
8399 return declarations ;
84100 }
85101
86102 public CtTypes getCtTypes () {
103+ assertInitialized ();
87104 return ctTypes ;
88105 }
89106
90107 public Names getNames () {
108+ assertInitialized ();
91109 return names ;
92110 }
93111
94112 public List <ExternalDomainMeta > getExternalDomainMetaList () {
113+ assertInitialized ();
95114 return externalDomainMetaList ;
96115 }
97116
98117 public Set <? extends Element > getElementsAnnotatedWith (String annotationName ) {
118+ assertInitialized ();
99119 Objects .requireNonNull (annotationName );
100120 return annotationElements .stream ()
101121 .filter (a -> a .getQualifiedName ().contentEquals (annotationName ))
102122 .findFirst ()
103123 .map (roundEnvironment ::getElementsAnnotatedWith )
104124 .orElse (Set .of ());
105125 }
126+
127+ private void assertInitialized () {
128+ if (!initialized ) {
129+ throw new AptIllegalStateException ("not yet initialized" );
130+ }
131+ }
106132}
0 commit comments