|
6 | 6 | import static io.avaje.inject.generator.ProcessingContext.delayedElements; |
7 | 7 | import static io.avaje.inject.generator.ProcessingContext.loadMetaInfCustom; |
8 | 8 | import static io.avaje.inject.generator.ProcessingContext.loadMetaInfServices; |
| 9 | +import static io.avaje.inject.generator.ProcessingContext.processingOver; |
9 | 10 | import static java.util.stream.Collectors.joining; |
10 | 11 | import static java.util.stream.Collectors.toList; |
11 | 12 |
|
@@ -71,6 +72,8 @@ public final class InjectProcessor extends AbstractProcessor { |
71 | 72 | private final Set<String> pluginFileProvided = new HashSet<>(); |
72 | 73 | private final Set<String> moduleFileProvided = new HashSet<>(); |
73 | 74 | private final List<ModuleData> moduleData = new ArrayList<>(); |
| 75 | + private int rounds; |
| 76 | + |
74 | 77 |
|
75 | 78 | @Override |
76 | 79 | public SourceVersion getSupportedSourceVersion() { |
@@ -143,16 +146,14 @@ private List<String> lines(String relativeName) { |
143 | 146 |
|
144 | 147 | @Override |
145 | 148 | public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
146 | | - if (roundEnv.errorRaised()) { |
| 149 | + if (processingOver() || roundEnv.errorRaised()) { |
147 | 150 | return false; |
148 | 151 | } |
| 152 | + processingOver(rounds++ > 0); |
149 | 153 |
|
150 | 154 | APContext.setProjectModuleElement(annotations, roundEnv); |
151 | 155 | readModule(roundEnv); |
152 | 156 |
|
153 | | - final var processingOver = roundEnv.processingOver(); |
154 | | - ProcessingContext.processingOver(processingOver); |
155 | | - |
156 | 157 | readBeans(delayedElements()); |
157 | 158 | addImportedAspects(importedAspects(roundEnv)); |
158 | 159 | maybeElements(roundEnv, QualifierPrism.PRISM_TYPE).stream() |
@@ -192,11 +193,12 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment |
192 | 193 | maybeElements(roundEnv, ServiceProviderPrism.PRISM_TYPE).ifPresent(this::registerSPI); |
193 | 194 | maybeElements(roundEnv, PluginProvidesPrism.PRISM_TYPE).ifPresent(this::registerSPI); |
194 | 195 | allScopes.readBeans(roundEnv); |
195 | | - defaultScope.write(processingOver); |
196 | | - allScopes.write(processingOver); |
| 196 | + final var over = processingOver(); |
| 197 | + defaultScope.write(over); |
| 198 | + allScopes.write(over); |
197 | 199 |
|
198 | | - if (processingOver) { |
199 | | - var order = |
| 200 | + if (processingOver()) { |
| 201 | + final var order = |
200 | 202 | new FactoryOrder(ProcessingContext.modules(), defaultScope.pluginProvided()) |
201 | 203 | .orderModules(); |
202 | 204 |
|
@@ -234,8 +236,13 @@ private void validateQualifier(ExecutableElement method) { |
234 | 236 | } |
235 | 237 |
|
236 | 238 | // Optional because these annotations are not guaranteed to exist |
237 | | - private static Optional<? extends Set<? extends Element>> maybeElements(RoundEnvironment round, String name) { |
238 | | - return Optional.ofNullable(typeElement(name)).map(round::getElementsAnnotatedWith); |
| 239 | + private Optional<? extends Set<? extends Element>> maybeElements(RoundEnvironment round, String name) { |
| 240 | + final var op = Optional.ofNullable(typeElement(name)) |
| 241 | + .map(round::getElementsAnnotatedWith); |
| 242 | + |
| 243 | + // reset processingOver flag if anything needs processing in this round |
| 244 | + processingOver(processingOver() && op.filter(n -> !n.isEmpty()).isEmpty()); |
| 245 | + return op; |
239 | 246 | } |
240 | 247 |
|
241 | 248 | private Set<TypeElement> importedElements(RoundEnvironment roundEnv) { |
@@ -264,7 +271,7 @@ private boolean notAlreadyProvided(TypeElement e) { |
264 | 271 | return !moduleFileProvided.contains(type) && !pluginFileProvided.contains(type); |
265 | 272 | } |
266 | 273 |
|
267 | | - private static Map<String, AspectImportPrism> importedAspects(RoundEnvironment roundEnv) { |
| 274 | + private Map<String, AspectImportPrism> importedAspects(RoundEnvironment roundEnv) { |
268 | 275 | return maybeElements(roundEnv, AspectImportPrism.PRISM_TYPE).stream() |
269 | 276 | .flatMap(Set::stream) |
270 | 277 | .map(AspectImportPrism::getAllInstancesOn) |
|
0 commit comments