Skip to content

Commit 0c88583

Browse files
committed
I guess Files.lines doesn't work
1 parent 95d1b99 commit 0c88583

File tree

1 file changed

+33
-49
lines changed
  • inject-generator/src/main/java/io/avaje/inject/generator

1 file changed

+33
-49
lines changed

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

Lines changed: 33 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ void loadProvidedFiles(Filer filer) {
6565
.toUri()
6666
.toString()
6767
.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+
7171
} catch (final Exception e) {
7272
// could not find avaje-plugin-provides.txt
7373
}
@@ -79,17 +79,16 @@ void loadProvidedFiles(Filer filer) {
7979
.toUri()
8080
.toString()
8181
.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+
8584
} catch (final Exception e2) {
8685
// could not find avaje-module-provides.txt
8786
}
8887
}
8988

9089
/**
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.
9392
*/
9493
private void registerPluginProvidedTypes() {
9594
for (final Plugin plugin : ServiceLoader.load(Plugin.class, Processor.class.getClassLoader())) {
@@ -102,7 +101,7 @@ private void registerPluginProvidedTypes() {
102101

103102
@Override
104103
public Set<String> getSupportedAnnotationTypes() {
105-
Set<String> annotations = new LinkedHashSet<>();
104+
final Set<String> annotations = new LinkedHashSet<>();
106105
annotations.add(InjectModule.class.getCanonicalName());
107106
annotations.add(Factory.class.getCanonicalName());
108107
annotations.add(Singleton.class.getCanonicalName());
@@ -123,7 +122,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
123122
}
124123
readChangedBeans(roundEnv.getElementsAnnotatedWith(Component.class), false);
125124
readChangedBeans(roundEnv.getElementsAnnotatedWith(Prototype.class), false);
126-
TypeElement typeElement = elementUtils.getTypeElement(Constants.CONTROLLER);
125+
final var typeElement = elementUtils.getTypeElement(Constants.CONTROLLER);
127126
if (typeElement != null) {
128127
readChangedBeans(roundEnv.getElementsAnnotatedWith(typeElement), false);
129128
}
@@ -135,78 +134,66 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
135134
}
136135

137136
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);
144141
}
145142
}
146143
addTestScope();
147144
}
148145

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. */
152147
private void addTestScope() {
153-
TypeElement testScopeType = elementUtils.getTypeElement(Constants.TESTSCOPE);
148+
final var testScopeType = elementUtils.getTypeElement(Constants.TESTSCOPE);
154149
if (testScopeType != null) {
155150
allScopes.addScopeAnnotation(testScopeType);
156151
}
157152
}
158153

159-
/**
160-
* Read the beans that have changed.
161-
*/
154+
/** Read the beans that have changed. */
162155
private void readChangedBeans(Set<? extends Element> beans, boolean factory) {
163-
for (Element element : beans) {
156+
for (final Element element : beans) {
164157
// ignore methods (e.g. factory methods with @Prototype on them)
165158
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);
168161
if (!factory) {
169162
// will be found via custom scope so effectively ignore additional @Singleton
170163
if (scope == null) {
171164
defaultScope.read(typeElement, false);
172165
}
166+
} else if (scope != null) {
167+
// context.logWarn("Adding factory to custom scope "+element+" scope: "+scope);
168+
scope.read(typeElement, true);
173169
} 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);
180171
}
181172
}
182173
}
183174
}
184175

185-
/**
186-
* Find the scope if the Factory has a scope annotation.
187-
*/
176+
/** Find the scope if the Factory has a scope annotation. */
188177
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());
191180
if (scopeInfo != null) {
192181
return scopeInfo;
193182
}
194183
}
195184
return null;
196185
}
197186

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). */
201188
private void readModule(RoundEnvironment roundEnv) {
202189
if (readModuleInfo) {
203190
// only read the module meta data once
204191
return;
205192
}
206193
readModuleInfo = true;
207-
String factory = context.loadMetaInfServices();
194+
final var factory = context.loadMetaInfServices();
208195
if (factory != null) {
209-
TypeElement moduleType = elementUtils.getTypeElement(factory);
196+
final var moduleType = elementUtils.getTypeElement(factory);
210197
if (moduleType != null) {
211198
defaultScope.readModuleMetaData(moduleType);
212199
}
@@ -215,21 +202,18 @@ private void readModule(RoundEnvironment roundEnv) {
215202
readInjectModule(roundEnv);
216203
}
217204

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) */
221206
private void readInjectModule(RoundEnvironment roundEnv) {
222207
// 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);
225210
if (scope == null) {
226211
// it it not a custom scope annotation
227-
InjectModule annotation = element.getAnnotation(InjectModule.class);
212+
final var annotation = element.getAnnotation(InjectModule.class);
228213
if (annotation != null) {
229214
defaultScope.details(annotation.name(), element);
230215
}
231216
}
232217
}
233218
}
234-
235219
}

0 commit comments

Comments
 (0)