Skip to content

Rename isAddBeanFor to isBeanAbsent #727

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 20, 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 @@ -294,8 +294,8 @@ void buildConditional(Append writer) {
new ConditionalWriter(writer, conditions).write();
}

void buildAddFor(Append writer) {
writer.append(" if (builder.isAddBeanFor(");
void buildBeanAbsent(Append writer) {
writer.append(" if (builder.isBeanAbsent(");
if (name != null && !name.isEmpty()) {
writer.append("\"%s\", ", name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ final class MethodReader {
String destroyMethod = (bean == null) ? null : bean.destroyMethod();
this.destroyPriority = (bean == null) ? null : bean.destroyPriority();
this.beanCloseable = (bean != null) && bean.autoCloseable();
// for multiRegister we desire a qualifier name such that builder.isAddBeanFor() uses it and allows
// for multiRegister we desire a qualifier name such that builder.isBeanAbsent() uses it and allows
// other beans of the same type to also register, otherwise it defaults to slightly confusing behaviour
this.name = multiRegister && qualifierName == null ? "multi" : qualifierName;
TypeElement returnElement = multiRegister ? APContext.typeElement(uType.mainType()) : asElement(returnMirror);
Expand Down Expand Up @@ -352,7 +352,7 @@ void buildConditional(Append writer) {
}

void buildAddFor(Append writer) {
writer.append(" if (builder.isAddBeanFor(");
writer.append(" if (builder.isBeanAbsent(");
if (isVoid) {
writer.append("Void.class");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private void writeStaticFactoryMethod() {

private void writeAddFor(MethodReader constructor) {
beanReader.buildConditional(writer);
beanReader.buildAddFor(writer);
beanReader.buildBeanAbsent(writer);
if (beanReader.registerProvider()) {
indent += " ";

Expand Down
26 changes: 22 additions & 4 deletions inject/src/main/java/io/avaje/inject/spi/Builder.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,42 @@ static Builder newBuilder(Set<String> profiles, ConfigPropertyPlugin plugin, Lis

/**
* Return true if the bean should be created and registered with the context.
* <p/>
* <p>
* Returning false means there has been a supplied bean already registered and
* that we should skip the creation and registration for this bean.
*
* @param name The qualifier name
* @param types The types that the bean implements and provides
*/
boolean isAddBeanFor(String name, Type... types);
boolean isBeanAbsent(String name, Type... types);

/**
* Return true if the bean should be created and registered with the context.
* <p/>
* <p>
* Returning false means there has been a supplied bean already registered and
* that we should skip the creation and registration for this bean.
*
* @param types The types that the bean implements and provides
*/
boolean isAddBeanFor(Type... types);
default boolean isBeanAbsent(Type... types) {
return isBeanAbsent(null, types);
}

/**
* @deprecated use {@link #isBeanAbsent(String, Type...)}
*/
@Deprecated(forRemoval = true)
default boolean isAddBeanFor(String name, Type... types) {
return isBeanAbsent(name, types);
}

/**
* @deprecated use {@link #isBeanAbsent(Type...)} instead
*/
@Deprecated(forRemoval = true)
default boolean isAddBeanFor(Type... types) {
return isBeanAbsent(types);
}

/**
* Register the next bean as having Primary priority.
Expand Down
7 changes: 1 addition & 6 deletions inject/src/main/java/io/avaje/inject/spi/DBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,7 @@ public void currentModule(Class<? extends AvajeModule> currentModule) {
}

@Override
public final boolean isAddBeanFor(Type... types) {
return isAddBeanFor(null, types);
}

@Override
public boolean isAddBeanFor(String name, Type... types) {
public boolean isBeanAbsent(String name, Type... types) {
parentMatch = null;
next(name, types);
if (parentOverride || parent == null) {
Expand Down
4 changes: 2 additions & 2 deletions inject/src/main/java/io/avaje/inject/spi/DBuilderExtn.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ final class DBuilderExtn extends DBuilder {
}

@Override
public boolean isAddBeanFor(String qualifierName, Type... types) {
if (!super.isAddBeanFor(qualifierName, types)) {
public boolean isBeanAbsent(String qualifierName, Type... types) {
if (!super.isBeanAbsent(qualifierName, types)) {
enrichParentMatch();
return false;
}
Expand Down