Skip to content

Commit 0a6c657

Browse files
committed
Adds Compiler Warning to useless @Inject
Now will warn when the `@inject` annotation is not needed
1 parent 963296b commit 0a6c657

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ private void writeFields() {
5555
}
5656

5757
private void writeConstructor() {
58-
writer.append(" @Inject\n");
5958
writer.append(" public %s%s(", shortName, suffix);
6059
int count = 0;
6160
for (final String aspectName : aspects.aspectNames()) {
@@ -96,7 +95,6 @@ private void writeImports() {
9695
writer.append("import %s;", Constants.INVOCATION_EXCEPTION).eol();
9796
writer.append("import %s;", Constants.METHOD_INTERCEPTOR).eol();
9897
writer.append("import %s;", Constants.COMPONENT).eol();
99-
writer.append("import %s;", Constants.INJECT).eol();
10098
writer.append("import %s;", Constants.PROXY).eol();
10199
beanReader.writeImports(writer, packageName);
102100
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ void read(TypeElement type) {
5959
break;
6060
}
6161
}
62+
if (injectConstructor != null
63+
&& otherConstructors.isEmpty()
64+
&& InjectPrism.isPresent(injectConstructor.element())) {
65+
logWarn(injectConstructor.element(), "Remove Unused @Inject Annotation");
66+
}
6267
}
6368

6469
/** Read the annotations on the type. */

0 commit comments

Comments
 (0)