@@ -65,9 +65,9 @@ void loadProvidedFiles(Filer filer) {
65
65
.toUri ()
66
66
.toString ()
67
67
.replace ("/target/classes" , "" );
68
- try ( var lines = Files . lines ( Paths . get ( new URI ( resource )))) {
69
- lines .forEach (pluginFileProvided ::add );
70
- }
68
+
69
+ Files . readAllLines ( Paths . get ( new URI ( resource ))) .forEach (pluginFileProvided ::add );
70
+
71
71
} catch (final Exception e ) {
72
72
// could not find avaje-plugin-provides.txt
73
73
}
@@ -79,17 +79,16 @@ void loadProvidedFiles(Filer filer) {
79
79
.toUri ()
80
80
.toString ()
81
81
.replace ("/target/classes" , "" );
82
- try (var lines = Files .lines (Paths .get (new URI (resource )))) {
83
- lines .forEach (pluginFileProvided ::add );
84
- }
82
+ Files .readAllLines (Paths .get (new URI (resource ))).forEach (pluginFileProvided ::add );
83
+
85
84
} catch (final Exception e2 ) {
86
85
// could not find avaje-module-provides.txt
87
86
}
88
87
}
89
88
90
89
/**
91
- * Register types provided by the plugin so no compiler error when we have a dependency
92
- * on these types and the only thing providing them is the plugin.
90
+ * Register types provided by the plugin so no compiler error when we have a dependency on these
91
+ * types and the only thing providing them is the plugin.
93
92
*/
94
93
private void registerPluginProvidedTypes () {
95
94
for (final Plugin plugin : ServiceLoader .load (Plugin .class , Processor .class .getClassLoader ())) {
@@ -102,7 +101,7 @@ private void registerPluginProvidedTypes() {
102
101
103
102
@ Override
104
103
public Set <String > getSupportedAnnotationTypes () {
105
- Set <String > annotations = new LinkedHashSet <>();
104
+ final Set <String > annotations = new LinkedHashSet <>();
106
105
annotations .add (InjectModule .class .getCanonicalName ());
107
106
annotations .add (Factory .class .getCanonicalName ());
108
107
annotations .add (Singleton .class .getCanonicalName ());
@@ -123,7 +122,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
123
122
}
124
123
readChangedBeans (roundEnv .getElementsAnnotatedWith (Component .class ), false );
125
124
readChangedBeans (roundEnv .getElementsAnnotatedWith (Prototype .class ), false );
126
- TypeElement typeElement = elementUtils .getTypeElement (Constants .CONTROLLER );
125
+ final var typeElement = elementUtils .getTypeElement (Constants .CONTROLLER );
127
126
if (typeElement != null ) {
128
127
readChangedBeans (roundEnv .getElementsAnnotatedWith (typeElement ), false );
129
128
}
@@ -135,78 +134,66 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
135
134
}
136
135
137
136
private void readScopes (Set <? extends Element > scopes ) {
138
- for (Element element : scopes ) {
139
- if (element .getKind () == ElementKind .ANNOTATION_TYPE ) {
140
- if (element instanceof TypeElement ) {
141
- TypeElement type = (TypeElement ) element ;
142
- allScopes .addScopeAnnotation (type );
143
- }
137
+ for (final Element element : scopes ) {
138
+ if ((element .getKind () == ElementKind .ANNOTATION_TYPE ) && (element instanceof TypeElement )) {
139
+ final var type = (TypeElement ) element ;
140
+ allScopes .addScopeAnnotation (type );
144
141
}
145
142
}
146
143
addTestScope ();
147
144
}
148
145
149
- /**
150
- * Add built-in test scope for <code>@TestScope</code> if available.
151
- */
146
+ /** Add built-in test scope for <code>@TestScope</code> if available. */
152
147
private void addTestScope () {
153
- TypeElement testScopeType = elementUtils .getTypeElement (Constants .TESTSCOPE );
148
+ final var testScopeType = elementUtils .getTypeElement (Constants .TESTSCOPE );
154
149
if (testScopeType != null ) {
155
150
allScopes .addScopeAnnotation (testScopeType );
156
151
}
157
152
}
158
153
159
- /**
160
- * Read the beans that have changed.
161
- */
154
+ /** Read the beans that have changed. */
162
155
private void readChangedBeans (Set <? extends Element > beans , boolean factory ) {
163
- for (Element element : beans ) {
156
+ for (final Element element : beans ) {
164
157
// ignore methods (e.g. factory methods with @Prototype on them)
165
158
if (element instanceof TypeElement ) {
166
- TypeElement typeElement = (TypeElement ) element ;
167
- final ScopeInfo scope = findScope (typeElement );
159
+ final var typeElement = (TypeElement ) element ;
160
+ final var scope = findScope (typeElement );
168
161
if (!factory ) {
169
162
// will be found via custom scope so effectively ignore additional @Singleton
170
163
if (scope == null ) {
171
164
defaultScope .read (typeElement , false );
172
165
}
166
+ } else if (scope != null ) {
167
+ // context.logWarn("Adding factory to custom scope "+element+" scope: "+scope);
168
+ scope .read (typeElement , true );
173
169
} else {
174
- if (scope != null ) {
175
- // context.logWarn("Adding factory to custom scope "+element+" scope: "+scope);
176
- scope .read (typeElement , true );
177
- } else {
178
- defaultScope .read (typeElement , true );
179
- }
170
+ defaultScope .read (typeElement , true );
180
171
}
181
172
}
182
173
}
183
174
}
184
175
185
- /**
186
- * Find the scope if the Factory has a scope annotation.
187
- */
176
+ /** Find the scope if the Factory has a scope annotation. */
188
177
private ScopeInfo findScope (Element element ) {
189
- for (AnnotationMirror annotationMirror : element .getAnnotationMirrors ()) {
190
- final ScopeInfo scopeInfo = allScopes .get (annotationMirror .getAnnotationType ().toString ());
178
+ for (final AnnotationMirror annotationMirror : element .getAnnotationMirrors ()) {
179
+ final var scopeInfo = allScopes .get (annotationMirror .getAnnotationType ().toString ());
191
180
if (scopeInfo != null ) {
192
181
return scopeInfo ;
193
182
}
194
183
}
195
184
return null ;
196
185
}
197
186
198
- /**
199
- * Read the existing meta data from InjectModule (if found) and the factory bean (if exists).
200
- */
187
+ /** Read the existing meta data from InjectModule (if found) and the factory bean (if exists). */
201
188
private void readModule (RoundEnvironment roundEnv ) {
202
189
if (readModuleInfo ) {
203
190
// only read the module meta data once
204
191
return ;
205
192
}
206
193
readModuleInfo = true ;
207
- String factory = context .loadMetaInfServices ();
194
+ final var factory = context .loadMetaInfServices ();
208
195
if (factory != null ) {
209
- TypeElement moduleType = elementUtils .getTypeElement (factory );
196
+ final var moduleType = elementUtils .getTypeElement (factory );
210
197
if (moduleType != null ) {
211
198
defaultScope .readModuleMetaData (moduleType );
212
199
}
@@ -215,21 +202,18 @@ private void readModule(RoundEnvironment roundEnv) {
215
202
readInjectModule (roundEnv );
216
203
}
217
204
218
- /**
219
- * Read InjectModule for things like package-info etc (not for custom scopes)
220
- */
205
+ /** Read InjectModule for things like package-info etc (not for custom scopes) */
221
206
private void readInjectModule (RoundEnvironment roundEnv ) {
222
207
// read other that are annotated with InjectModule
223
- for (Element element : roundEnv .getElementsAnnotatedWith (InjectModule .class )) {
224
- Scope scope = element .getAnnotation (Scope .class );
208
+ for (final Element element : roundEnv .getElementsAnnotatedWith (InjectModule .class )) {
209
+ final var scope = element .getAnnotation (Scope .class );
225
210
if (scope == null ) {
226
211
// it it not a custom scope annotation
227
- InjectModule annotation = element .getAnnotation (InjectModule .class );
212
+ final var annotation = element .getAnnotation (InjectModule .class );
228
213
if (annotation != null ) {
229
214
defaultScope .details (annotation .name (), element );
230
215
}
231
216
}
232
217
}
233
218
}
234
-
235
219
}
0 commit comments