Skip to content

Commit be25f9f

Browse files
committed
Remove dead code - @request scope code from generator
1 parent 27bda6a commit be25f9f

File tree

7 files changed

+10
-91
lines changed

7 files changed

+10
-91
lines changed

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class BeanReader {
2727
private final TypeReader typeReader;
2828
private final boolean primary;
2929
private final boolean secondary;
30-
private final boolean requestScopedBean;
3130

3231
private boolean writtenToFile;
3332

@@ -41,8 +40,7 @@ class BeanReader {
4140
this.typeReader = new TypeReader(beanType, context, importTypes, factory);
4241

4342
typeReader.process();
44-
this.requestScopedBean = typeReader.isRequestScopeBean();
45-
this.requestParams = new BeanRequestParams(context, type, requestScopedBean);
43+
this.requestParams = new BeanRequestParams(type);
4644
this.name = typeReader.getName();
4745
this.injectMethods = typeReader.getInjectMethods();
4846
this.injectFields = typeReader.getInjectFields();
@@ -77,10 +75,6 @@ BeanReader read() {
7775
for (MethodReader factoryMethod : factoryMethods) {
7876
factoryMethod.addImports(importTypes);
7977
}
80-
if (requestScopedBean) {
81-
importTypes.add(Constants.REQUESTSCOPEPROVIDER);
82-
importTypes.add(Constants.REQUESTSCOPE);
83-
}
8478
return this;
8579
}
8680

@@ -123,7 +117,7 @@ String getMetaKey() {
123117
* Return true if lifecycle via annotated methods is required.
124118
*/
125119
boolean hasLifecycleMethods() {
126-
return !requestScopedBean && (postConstructMethod != null || preDestroyMethod != null || typeReader.isClosable());
120+
return (postConstructMethod != null || preDestroyMethod != null || typeReader.isClosable());
127121
}
128122

129123
List<MetaData> createFactoryMethodMeta() {
@@ -217,10 +211,6 @@ boolean isRequestScopedController() {
217211
return requestParams.isRequestScopedController();
218212
}
219213

220-
boolean isRequestScopedBean() {
221-
return requestScopedBean;
222-
}
223-
224214
String suffix() {
225215
return isRequestScopedController() ? Constants.FACTORY : Constants.DI;
226216
}

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,17 @@
88
*/
99
class BeanRequestParams {
1010

11-
private final ProcessingContext context;
1211
private final String parentType;
13-
private final boolean requestScopedBean;
14-
1512
private RequestScope.Handler reqScopeHandler;
1613

17-
BeanRequestParams(ProcessingContext context, String parentType, boolean requestScopedBean) {
18-
this.context = context;
14+
BeanRequestParams(String parentType) {
1915
this.parentType = parentType;
20-
this.requestScopedBean = requestScopedBean;
2116
}
2217

2318
/**
2419
* Return true if this type is a request scoped type (e.g. Javalin Context).
2520
*/
2621
boolean check(String paramType) {
27-
if (requestScopedBean) {
28-
// Beans that are @Request don't get the reqScopeHandler factory generated
29-
return false;
30-
}
3122
if (paramType != null && RequestScope.check(paramType)) {
3223
if (reqScopeHandler == null) {
3324
reqScopeHandler = RequestScope.handler(paramType);

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,15 @@ class Constants {
1212
static final String PROVIDER = "jakarta.inject.Provider";
1313
static final String SINGLETON = "jakarta.inject.Singleton";
1414
static final String INJECT = "jakarta.inject.Inject";
15-
static final String REQUEST = "io.avaje.inject.Request";
1615

1716
static final String PATH = "io.avaje.http.api.Path";
1817
static final String CONTROLLER = "io.avaje.http.api.Controller";
19-
static final String REQUESTSCOPEPROVIDER = "io.avaje.inject.RequestScopeProvider";
2018

2119
static final String AT_SINGLETON = "@Singleton";
2220
static final String AT_GENERATED = "@Generated(\"io.avaje.inject.generator\")";
2321
static final String META_INF_FACTORY = "META-INF/services/io.avaje.inject.spi.Module";
2422
static final String META_INF_CUSTOM = "META-INF/services/io.avaje.inject.spi.Module.Custom";
2523

26-
static final String REQUESTSCOPE = "io.avaje.inject.RequestScope";
2724
static final String BEANCONTEXT = "io.avaje.inject.BeanScope";
2825
static final String INJECTMODULE = "io.avaje.inject.InjectModule";
2926

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class MetaData {
1717
private final String type;
1818
private final String shortType;
1919
private final String name;
20-
private final List<String> externallyProvided = new ArrayList<>();
2120
private String method;
2221
private boolean wired;
2322
private boolean requestScope;
@@ -103,7 +102,6 @@ private List<String> asList(String[] content) {
103102
}
104103

105104
void update(BeanReader beanReader) {
106-
this.requestScope = beanReader.isRequestScopedBean();
107105
this.provides = beanReader.getInterfaces();
108106
this.dependsOn = beanReader.getDependsOn();
109107
}
@@ -229,7 +227,4 @@ void setMethod(String method) {
229227
this.method = method;
230228
}
231229

232-
void externallyProvided(String dependency) {
233-
externallyProvided.add(dependency);
234-
}
235230
}

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

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class SimpleBeanWriter {
1414
private static final String CODE_COMMENT = "/**\n * Generated source - dependency injection builder for %s.\n */";
1515
private static final String CODE_COMMENT_FACTORY = "/**\n * Generated source - dependency injection factory for request scoped %s.\n */";
1616
private static final String CODE_COMMENT_BUILD = " /**\n * Create and register %s.\n */";
17-
private static final String CODE_COMMENT_BUILD_RSB = " /**\n * Register provider for request scoped %s.\n */";
1817

1918
private final BeanReader beanReader;
2019
private final ProcessingContext context;
@@ -23,7 +22,7 @@ class SimpleBeanWriter {
2322
private final String packageName;
2423
private final String suffix;
2524
private Append writer;
26-
private String indent = " ";
25+
private final String indent = " ";
2726

2827
SimpleBeanWriter(BeanReader beanReader, ProcessingContext context) {
2928
this.beanReader = beanReader;
@@ -87,26 +86,10 @@ private void writeStaticFactoryMethod() {
8786
return;
8887
}
8988
writeBuildMethodStart(constructor);
90-
if (beanReader.isRequestScopedBean()) {
91-
writeReqScopeBean(constructor);
92-
} else {
93-
writeAddFor(constructor);
94-
}
89+
writeAddFor(constructor);
9590
writer.append(" }").eol().eol();
9691
}
9792

98-
private void writeReqScopeBean(MethodReader constructor) {
99-
indent = indent + " ";
100-
beanReader.buildReq(writer);
101-
writeCreateBean(constructor, "scope");
102-
if (beanReader.isExtraInjectionRequired()) {
103-
writeExtraInjection();
104-
}
105-
beanReader.writePostConstruct(writer);
106-
beanReader.writePreDestroy(writer);
107-
beanReader.buildReqEnd(writer);
108-
}
109-
11093
private void writeAddFor(MethodReader constructor) {
11194
beanReader.buildAddFor(writer);
11295
writeCreateBean(constructor, "builder");
@@ -120,11 +103,7 @@ private void writeAddFor(MethodReader constructor) {
120103

121104
private void writeBuildMethodStart(MethodReader constructor) {
122105
int providerIndex = 0;
123-
if (beanReader.isRequestScopedBean()) {
124-
writer.append(CODE_COMMENT_BUILD_RSB, shortName).eol();
125-
} else {
126-
writer.append(CODE_COMMENT_BUILD, shortName).eol();
127-
}
106+
writer.append(CODE_COMMENT_BUILD, shortName).eol();
128107
writer.append(" public static void build(Builder builder");
129108
for (MethodReader.MethodParam param : constructor.getParams()) {
130109
if (param.isGenericParam()) {
@@ -150,18 +129,11 @@ private void writeCreateBean(MethodReader constructor, String builderName) {
150129
private void writeExtraInjection() {
151130
String builderRef = "b";
152131
String beanRef = "$bean";
153-
if (beanReader.isRequestScopedBean()) {
154-
builderRef = "scope";
155-
beanRef = "bean";
156-
} else {
157-
writer.append(" builder.addInjector(b -> {").eol();
158-
}
132+
writer.append(" builder.addInjector(b -> {").eol();
159133
writer.append(" // field and method injection").eol();
160134
injectFields(builderRef, beanRef);
161135
injectMethods(builderRef, beanRef);
162-
if (!beanReader.isRequestScopedBean()) {
163-
writer.append(" });").eol();
164-
}
136+
writer.append(" });").eol();
165137
}
166138

167139
private void injectFields(String builderRef, String beanRef) {

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class TypeAnnotationReader {
1717
private final ProcessingContext context;
1818
private final List<String> annotationTypes = new ArrayList<>();
1919
private String qualifierName;
20-
private boolean requestScopeBean;
2120

2221
TypeAnnotationReader(TypeElement beanType, ProcessingContext context) {
2322
this.beanType = beanType;
@@ -36,10 +35,6 @@ String getQualifierName() {
3635
return qualifierName;
3736
}
3837

39-
boolean isRequestScopeBean() {
40-
return requestScopeBean;
41-
}
42-
4338
void process() {
4439
for (AnnotationMirror annotationMirror : beanType.getAnnotationMirrors()) {
4540
DeclaredType annotationType = annotationMirror.getAnnotationType();
@@ -49,12 +44,8 @@ void process() {
4944
qualifierName = Util.shortName(annType).toLowerCase();
5045
} else if (annType.indexOf('.') == -1) {
5146
context.logWarn("skip when no package on annotation " + annType);
52-
} else {
53-
if (Constants.REQUEST.equals(annType)) {
54-
requestScopeBean = true;
55-
} else if (IncludeAnnotations.include(annType)) {
56-
annotationTypes.add(annType);
57-
}
47+
} else if (IncludeAnnotations.include(annType)) {
48+
annotationTypes.add(annType);
5849
}
5950
}
6051
}

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class TypeReader {
1515
private final Set<String> importTypes;
1616
private final TypeExtendsReader extendsReader;
1717
private final TypeAnnotationReader annotationReader;
18-
private final ProcessingContext context;
1918
private String typesRegister;
2019

2120
TypeReader(TypeElement beanType, ProcessingContext context, Set<String> importTypes, boolean factory) {
@@ -29,7 +28,6 @@ class TypeReader {
2928
private TypeReader(boolean forBean, TypeElement beanType, ProcessingContext context, Set<String> importTypes, boolean factory) {
3029
this.forBean = forBean;
3130
this.beanType = beanType;
32-
this.context = context;
3331
this.importTypes = importTypes;
3432
this.extendsReader = new TypeExtendsReader(beanType, context, factory);
3533
this.annotationReader = new TypeAnnotationReader(beanType, context);
@@ -47,10 +45,6 @@ boolean isClosable() {
4745
return extendsReader.isCloseable();
4846
}
4947

50-
boolean isRequestScopeBean() {
51-
return annotationReader.isRequestScopeBean();
52-
}
53-
5448
void addImports(Set<String> importTypes) {
5549
importTypes.addAll(this.importTypes);
5650
}
@@ -104,17 +98,6 @@ String getName() {
10498

10599
private void initRegistrationTypes() {
106100
TypeAppender appender = new TypeAppender(importTypes);
107-
if (isRequestScopeBean()) {
108-
List<String> interfaceTypes = extendsReader.getInterfaceTypes();
109-
interfaceTypes.remove(extendsReader.getBaseType());
110-
if (interfaceTypes.isEmpty()) {
111-
this.typesRegister = null;
112-
} else {
113-
appender.add(interfaceTypes);
114-
this.typesRegister = appender.asString();
115-
}
116-
return;
117-
}
118101
appender.add(extendsReader.getBaseType());
119102
appender.add(extendsReader.getExtendsTypes());
120103
appender.add(extendsReader.getInterfaceTypes());

0 commit comments

Comments
 (0)