2525import static org .seasar .doma .internal .apt .AnnotationTypes .EXTERNAL_DOMAIN ;
2626import static org .seasar .doma .internal .apt .AnnotationTypes .SCOPE ;
2727
28- import java .util .List ;
29- import java .util .Objects ;
28+ import java .util .HashSet ;
29+ import java .util .Map ;
3030import java .util .Set ;
3131import java .util .function .Function ;
3232import javax .annotation .processing .AbstractProcessor ;
8181})
8282public class DomaProcessor extends AbstractProcessor {
8383
84- private static final List < Operator > operators =
85- List .of (
86- new Operator ( EXTERNAL_DOMAIN , ExternalDomainProcessor ::new ) ,
87- new Operator ( DATA_TYPE , DataTypeProcessor ::new ) ,
88- new Operator ( DOMAIN , DomainProcessor ::new ) ,
89- new Operator ( DOMAIN_CONVERTERS , DomainConvertersProcessor ::new ) ,
90- new Operator ( EMBEDDABLE , EmbeddableProcessor ::new ) ,
91- new Operator ( ENTITY , EntityProcessor ::new ) ,
92- new Operator ( AGGREGATE_STRATEGY , AggregateStrategyProcessor ::new ) ,
93- new Operator ( DAO , DaoProcessor ::new ) ,
94- new Operator ( SCOPE , ScopeProcessor ::new ) );
84+ private static final Map < String , Function < RoundContext , ElementProcessor >> functionMap =
85+ Map .of (
86+ EXTERNAL_DOMAIN , ExternalDomainProcessor ::new ,
87+ DATA_TYPE , DataTypeProcessor ::new ,
88+ DOMAIN , DomainProcessor ::new ,
89+ DOMAIN_CONVERTERS , DomainConvertersProcessor ::new ,
90+ EMBEDDABLE , EmbeddableProcessor ::new ,
91+ ENTITY , EntityProcessor ::new ,
92+ AGGREGATE_STRATEGY , AggregateStrategyProcessor ::new ,
93+ DAO , DaoProcessor ::new ,
94+ SCOPE , ScopeProcessor ::new );
9595
9696 private ProcessingContext processingContext ;
9797
@@ -113,24 +113,39 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
113113 return true ;
114114 }
115115
116- var roundContext = processingContext .createRoundContext (annotations , roundEnv );
116+ var roundContext = processingContext .createRoundContext (roundEnv );
117117
118- for (var operator : operators ) {
119- var elements = roundContext .getElementsAnnotatedWith (operator .annotationName );
120- if (!elements .isEmpty ()) {
121- var processor = operator .function .apply (roundContext );
122- processor .process (elements );
118+ var externalDomainAnnotation = new HashSet <TypeElement >(1 );
119+ var otherAnnotations = new HashSet <TypeElement >(functionMap .size () - 1 );
120+
121+ for (var annotation : annotations ) {
122+ if (annotation .getQualifiedName ().contentEquals (EXTERNAL_DOMAIN )) {
123+ externalDomainAnnotation .add (annotation );
124+ } else {
125+ otherAnnotations .add (annotation );
123126 }
124127 }
125128
129+ // process ExternalDomain annotation first
130+ processWithRoundContext (externalDomainAnnotation , roundContext );
131+
132+ // process other annotations
133+ processWithRoundContext (otherAnnotations , roundContext );
134+
126135 return true ;
127136 }
128137
129- private record Operator (
130- String annotationName , Function <RoundContext , ElementProcessor > function ) {
131- Operator {
132- Objects .requireNonNull (annotationName );
133- Objects .requireNonNull (function );
138+ private void processWithRoundContext (Set <TypeElement > annotations , RoundContext roundContext ) {
139+ for (var annotation : annotations ) {
140+ String annotationName = annotation .getQualifiedName ().toString ();
141+ var function = functionMap .get (annotationName );
142+ if (function != null ) {
143+ var elements = roundContext .getElementsAnnotatedWith (annotation );
144+ if (!elements .isEmpty ()) {
145+ var processor = function .apply (roundContext );
146+ processor .process (elements );
147+ }
148+ }
134149 }
135150 }
136151}
0 commit comments