Skip to content
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
11 changes: 5 additions & 6 deletions inject/src/main/java/io/avaje/inject/spi/DBeanMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,13 @@ void register(Provider<?> provider) {
}
}

/**
* Get with a strict match on name for the single entry case.
*/
Object getStrict(Type type, String name) {
/** Check if a non secondary entry exists */
Object nonDefaultEntry(Type type, String name) {
DContextEntry entry = beans.get(type.getTypeName());
if (entry == null) {
return null;
}
return entry.getStrict(name);
return entry.nonDefaultEntry(name);
}

boolean contains(String type) {
Expand Down Expand Up @@ -175,7 +173,8 @@ Map<String, Object> map(Type type, BeanScope parent) {
Map<String, Object> localMap = map(type);
if (parentMap.isEmpty()) {
return localMap;
} else if (localMap.isEmpty()) {
}
if (localMap.isEmpty()) {
return parentMap;
}
Map<String, Object> result = new LinkedHashMap<>(parentMap);
Expand Down
21 changes: 9 additions & 12 deletions inject/src/main/java/io/avaje/inject/spi/DBeanScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,18 @@ private <T> T getByType(Type type, @Nullable String name) {
return parent.get(type, name);
}

/**
* Get with a strict match on name for the single entry case.
*/
/** Check if a non secondary entry exists */
@Nullable
Object getStrict(@Nullable String name, Type[] types) {
Object nonDefaultEntry(@Nullable String name, Type[] types) {
for (Type type : types) {
Object match = beans.getStrict(type, name);
var match = beans.nonDefaultEntry(type, name);
if (match != null) {
return match;
}
}
if (parent instanceof DBeanScope) {
DBeanScope dParent = (DBeanScope) parent;
return dParent.getStrict(name, types);
return dParent.nonDefaultEntry(name, types);
}
return null;
}
Expand Down Expand Up @@ -183,12 +181,12 @@ private <T> List<T> listOf(Type type, @Nullable String name) {
static <T> List<T> combine(List<T> values, List<T> parentValues) {
if (values.isEmpty()) {
return parentValues;
} else if (parentValues.isEmpty()) {
return values;
} else {
values.addAll(parentValues);
}
if (parentValues.isEmpty()) {
return values;
}
values.addAll(parentValues);
return values;
}

@Override
Expand Down Expand Up @@ -266,8 +264,7 @@ private void shutdown() {
@Override
public Set<String> customScopeAnnotations() {
if (parent != null) {
final Set<String> scopes = new HashSet<>();
scopes.addAll(beans.scopeAnnotations());
final Set<String> scopes = new HashSet<>(beans.scopeAnnotations());
scopes.addAll(parent.customScopeAnnotations());
return scopes;
}
Expand Down
4 changes: 2 additions & 2 deletions inject/src/main/java/io/avaje/inject/spi/DBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ public boolean isBeanAbsent(@Nullable String name, Type... types) {
return true;
}
if (parent instanceof DBeanScope) {
// effectively looking for a match in the parent scope
// look for a match in the parent scope
final DBeanScope dParent = (DBeanScope) parent;
parentMatch = dParent.getStrict(name, removeAnnotations(types));
parentMatch = dParent.nonDefaultEntry(name, removeAnnotations(types));
return parentMatch == null;
}
return true;
Expand Down
20 changes: 8 additions & 12 deletions inject/src/main/java/io/avaje/inject/spi/DContextEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ Provider<?> provider(String name, Class<? extends AvajeModule> currentModule) {
return new EntryMatcher(name, currentModule).provider(entries);
}

/**
* Get with strict name match for the single entry case.
*/
Object getStrict(String name) {
/** Check if a non secondary entry exists */
Object nonDefaultEntry(String name) {
if (entries.size() == 1) {
return entries.get(0).beanIfNameMatch(name);
return entries.get(0).nonDefaultMatch(name);
}
return new EntryMatcher(name, null).match(entries);
var entry = new EntryMatcher(name, null).findMatch(entries);
return entry != null ? entry.nonDefaultMatch(null) : null;
}

Object get(String name, Class<? extends AvajeModule> currentModule) {
Expand Down Expand Up @@ -156,7 +155,8 @@ private void checkMatch(DContextEntryBean entry) {
if (match.priority() < entry.priority()) {
// existing supplied match always wins
return;
} else if (match.priority() > entry.priority()) {
}
if (match.priority() > entry.priority()) {
// new supplied wins
match = entry;
return;
Expand All @@ -171,13 +171,9 @@ private void checkMatch(DContextEntryBean entry) {
}
// leave as is, current primary wins
return;
} else if (impliedName) {
ignoredSecondaryMatch = entry;
return;
}

// try to resolve match using qualifier name (including null)
if (match.isNameEqual(name) && !entry.isNameEqual(name)) {
if (impliedName || (match.isNameEqual(name) && !entry.isNameEqual(name))) {
ignoredSecondaryMatch = entry;
return;
} else if (!match.isNameEqual(name) && entry.isNameEqual(name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ final boolean isSupplied(String qualifierName) {
return priority == BeanEntry.SUPPLIED && (qualifierName == null || qualifierName.equals(name));
}

final Object nonDefaultMatch(String name) {
return isNameMatch(name) && priority != BeanEntry.SECONDARY ? bean() : null;
}

/**
* Prototype scope Provider based entry.
*/
Expand Down