Skip to content

Tidy Internals #697

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@
*/
final class SimpleBeanWriter {

private static final String CODE_COMMENT = "/**\n * Generated source - dependency injection builder for %s.\n */";
private static final String CODE_COMMENT_FACTORY = "/**\n * Generated source - dependency injection factory for request scoped %s.\n */";
private static final String CODE_COMMENT_BUILD = " /**\n * Create and register %s.\n */";
private static final String CODE_COMMENT_BUILD_PROVIDER = " /**\n * Register %s provider.\n */";

private final BeanReader beanReader;
private final String originName;
private final String shortName;
Expand Down Expand Up @@ -200,11 +195,6 @@ private void writeAddFor(MethodReader constructor) {
}

private void writeBuildMethodStart() {
if (beanReader.registerProvider()) {
writer.append(CODE_COMMENT_BUILD_PROVIDER, shortName).eol();
} else {
writer.append(CODE_COMMENT_BUILD, shortName).eol();
}
writer.append(" public static void build(%s builder) {", beanReader.builderType()).eol();
}

Expand Down Expand Up @@ -334,11 +324,6 @@ private void writeClassEnd() {

private void writeClassStart() {
final var requestScopedController = beanReader.isRequestScopedController();
if (requestScopedController) {
writer.append(CODE_COMMENT_FACTORY, shortName).eol();
} else {
writer.append(CODE_COMMENT, shortName).eol();
}
writer.append(beanReader.generatedType()).append(Constants.AT_GENERATED_COMMENT).eol();
if (requestScopedController) {
writer.append(Constants.AT_SINGLETON).eol();
Expand Down
5 changes: 2 additions & 3 deletions inject/src/main/java/io/avaje/inject/spi/DBeanMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -134,7 +133,7 @@ <T> Provider<T> provider(Type type, String name) {
*/
List<Object> all(Type type) {
DContextEntry entry = beans.get(type.getTypeName());
return entry != null ? entry.all() : Collections.emptyList();
return entry != null ? entry.all() : List.of();
}

/**
Expand All @@ -158,7 +157,7 @@ Map<String, Object> map(Type type, BeanScope parent) {

private Map<String, Object> map(Type type) {
DContextEntry entry = beans.get(type.getTypeName());
return entry != null ? entry.map() : Collections.emptyMap();
return entry != null ? entry.map() : Map.of();
}

/**
Expand Down
18 changes: 9 additions & 9 deletions inject/src/main/java/io/avaje/inject/spi/DBeanScopeProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ public List<Object> listByAnnotation(Class<? extends Annotation> annotation) {
if (delegate != null) {
return delegate.listByAnnotation(annotation);
} else {
throw new IllegalStateException(
"Proxy BeanScope can't use listByAnnotation while scope is being built");
throw illegal("listByAnnotation");
}
}

Expand Down Expand Up @@ -111,8 +110,7 @@ public <T> List<T> listByPriority(Class<T> type) {
if (delegate != null) {
return delegate.listByPriority(type);
} else {
throw new IllegalStateException(
"Proxy BeanScope can't use listByPriority while scope is being built");
throw illegal("listByPriority");
}
}

Expand All @@ -121,8 +119,7 @@ public <T> List<T> listByPriority(Class<T> type, Class<? extends Annotation> pri
if (delegate != null) {
return delegate.listByPriority(type, priority);
} else {
throw new IllegalStateException(
"Proxy BeanScope can't use listByPriority while scope is being built");
throw illegal("listByPriority");
}
}

Expand All @@ -141,7 +138,7 @@ public List<BeanEntry> all() {
if (delegate != null) {
return delegate.all();
} else {
throw new IllegalStateException("Proxy BeanScope can't use all() while scope is being built");
throw illegal("all");
}
}

Expand All @@ -168,9 +165,12 @@ public void close() {
if (delegate != null) {
delegate.close();
} else {
throw new IllegalStateException(
"Proxy BeanScope can't use close() while scope is being built");
throw illegal("close");
}
}

IllegalStateException illegal(String name) {
return new IllegalStateException(
String.format("Proxy BeanScope can't use %s() while scope is being built", name));
}
}