Skip to content

Commit 22134d8

Browse files
authored
validate only a single InjectModule annotation (#776)
Saw some cases where users had multiple for whatever reason and it wasn't working right. (strict wiring was being overridden)
1 parent c2317ad commit 22134d8

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

inject-generator/src/main/java/io/avaje/inject/generator/InjectProcessor.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import javax.lang.model.util.Elements;
1616

1717
import static java.util.stream.Collectors.joining;
18+
import static java.util.stream.Collectors.toList;
19+
1820
import java.io.IOException;
1921
import java.nio.file.Files;
2022
import java.nio.file.StandardOpenOption;
@@ -243,7 +245,7 @@ private static Map<String, AspectImportPrism> importedAspects(RoundEnvironment r
243245

244246
private void readScopes(Set<? extends Element> scopes) {
245247
for (final Element element : scopes) {
246-
if ((element.getKind() == ElementKind.ANNOTATION_TYPE) && (element instanceof TypeElement)) {
248+
if (element.getKind() == ElementKind.ANNOTATION_TYPE && element instanceof TypeElement) {
247249
final var type = (TypeElement) element;
248250
allScopes.addScopeAnnotation(type);
249251
}
@@ -323,6 +325,19 @@ private ScopeInfo findScope(Element element) {
323325
* Read the existing meta-data from InjectModule (if found) and the factory bean (if exists).
324326
*/
325327
private void readModule(RoundEnvironment roundEnv) {
328+
var moduleList =
329+
maybeElements(roundEnv, InjectModulePrism.PRISM_TYPE).stream()
330+
.flatMap(Set::stream)
331+
.filter(e -> !ScopePrism.isPresent(e))
332+
.filter(e -> !GeneratedPrism.isPresent(e))
333+
.collect(toList());
334+
335+
if (moduleList.size() > 1) {
336+
for (var element : moduleList) {
337+
logError(element, "There should only be one default scope @InjectModule annotation in a module");
338+
}
339+
}
340+
326341
if (readModuleInfo) {
327342
// only read the module meta data once
328343
return;

0 commit comments

Comments
 (0)